@Override public String getServletContextName() { return proxy.getServletContextName(); }
/** * Show class name and some details that are useful in template-not-found errors. * * @since 2.3.21 */ @Override public String toString() { return TemplateLoaderUtils.getClassNameForToString(this) + "(subdirPath=" + StringUtil.jQuote(subdirPath) + ", servletContext={contextPath=" + StringUtil.jQuote(getContextPath()) + ", displayName=" + StringUtil.jQuote(servletContext.getServletContextName()) + "})"; }
@Override public String getServletContextName() { return _servletContext.getServletContextName(); }
public String getServletContextName() { return _servletContext.getServletContextName(); }
serverInfo = servletContext.getServerInfo(); contextPath = Parameters.getContextPath(servletContext); contextDisplayName = servletContext.getServletContextName(); webappVersion = MavenArtifact.getWebappVersion();
public void contextInitialized(ServletContextEvent sce) { servletContext = sce.getServletContext(); servletContextPath = servletContext.getContextPath(); servletContextName = sce.getServletContext().getServletContextName(); processApplicationClassloader = initProcessApplicationClassloader(sce); // perform lifecycle start deploy(); }
/** * Gets the servlet or filter name from the config. * * @return the servlet or filter name */ public final String getName() { switch (type) { case ServletConfig: return servletConfig.getServletName(); case FilterConfig: return filterConfig.getFilterName(); case ServletContext: return servletContext.getServletContextName(); default: throw new IllegalStateException(); } }
public void contextInitialized(ServletContextEvent sce) { servletContext = sce.getServletContext(); servletContextPath = servletContext.getContextPath(); servletContextName = sce.getServletContext().getServletContextName(); processApplicationClassloader = initProcessApplicationClassloader(sce); // perform lifecycle start deploy(); }
public void throwHotDeployException( HotDeployEvent event, String msg, Throwable t) throws HotDeployException { ServletContext servletContext = event.getServletContext(); String servletContextName = servletContext.getServletContextName(); throw new HotDeployException(msg + servletContextName, t); }
@Override public void contextDestroyed(ServletContextEvent servletContextEvent) { portalDestroy(); if (_classLoaderRegistered) { ServletContextClassLoaderPool.unregister( servletContext.getServletContextName()); } }
@Override public void contextInitialized(ServletContextEvent servletContextEvent) { servletContext = servletContextEvent.getServletContext(); Thread currentThread = Thread.currentThread(); pluginClassLoader = currentThread.getContextClassLoader(); String servletContextName = servletContext.getServletContextName(); if (ServletContextClassLoaderPool.getClassLoader(servletContextName) == null) { ServletContextClassLoaderPool.register( servletContextName, pluginClassLoader); _classLoaderRegistered = true; } servletContext.setAttribute(PLUGIN_CLASS_LOADER, pluginClassLoader); ServletContextPool.put(servletContextName, servletContext); registerPortalLifecycle(); }
private void initializeNonJndi(final String location) { if (this.name == null) { this.name = this.servletContext.getServletContextName(); LOGGER.debug("Using the servlet context name \"{}\".", this.name); } if (this.name == null) { this.name = this.servletContext.getContextPath(); LOGGER.debug("Using the servlet context context-path \"{}\".", this.name); } if (this.name == null && location == null) { LOGGER.error("No Log4j context configuration provided. This is very unusual."); this.name = new SimpleDateFormat("yyyyMMdd_HHmmss.SSS").format(new Date()); } if (location != null && location.contains(",")) { final List<URI> uris = getConfigURIs(location); this.loggerContext = Configurator.initialize(this.name, this.getClassLoader(), uris, this.servletContext); return; } final URI uri = getConfigURI(location); this.loggerContext = Configurator.initialize(this.name, this.getClassLoader(), uri, this.servletContext); }
protected ResourceBundleLoader getResourceBundleLoader() { if (_servletContext != null) { return ResourceBundleLoaderUtil. getResourceBundleLoaderByServletContextName( _servletContext.getServletContextName()); } return new AggregateResourceBundleLoader( new ClassResourceBundleLoader("content.Language", getClass()), ResourceBundleLoaderUtil.getPortalResourceBundleLoader()); }
@Test public void testNotFound() throws ServletException, IOException { StaticContentServlet servlet = new StaticContentServlet(); ServletContext context = mock(ServletContext.class); when(context.getServletContextName()).thenReturn("foo"); when(context.getMimeType(anyString())).thenReturn("image/jpeg"); ServletConfig config = mock(ServletConfig.class); when(config.getInitParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("root"))); when(config.getInitParameter("root")).thenReturn(getFileSystemRoot()); when(config.getServletContext()).thenReturn(context); servlet.init(config); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getMethod()).thenReturn("GET"); when(request.getPathInfo()).thenReturn("/missing.jpg"); when(request.getRequestURI()).thenReturn("/foo/missing.jpg"); when(request.getContextPath()).thenReturn("/foo"); HttpServletResponse response = mock(HttpServletResponse.class); servlet.service(request, response); verify(response).sendError(HttpServletResponse.SC_NOT_FOUND, "/foo/missing.jpg"); }
@Test public void testDirectoryListingForbidden() throws ServletException, IOException { StaticContentServlet servlet = new StaticContentServlet(); ServletContext context = mock(ServletContext.class); when(context.getServletContextName()).thenReturn("foo"); when(context.getMimeType(anyString())).thenReturn("image/png"); ServletConfig config = mock(ServletConfig.class); when(config.getInitParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("root"))); when(config.getInitParameter("root")).thenReturn(getFileSystemRoot()); when(config.getServletContext()).thenReturn(context); servlet.init(config); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getMethod()).thenReturn("GET"); when(request.getPathInfo()).thenReturn("/"); // Attempt directory listing when(request.getRequestURI()).thenReturn("/foo/"); // Attempt directory listing when(request.getContextPath()).thenReturn("/foo"); ServletOutputStream stream = mock(ServletOutputStream.class); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(stream); servlet.service(request, response); verify(response).sendError(HttpServletResponse.SC_FORBIDDEN, "/foo/"); }
when(context.getServletContextName()).thenReturn("foo"); when(context.getMimeType(anyString())).thenReturn("image/png");
when(context.getServletContextName()).thenReturn("foo"); when(context.getMimeType(anyString())).thenReturn("image/png");
when(context.getServletContextName()).thenReturn("foo"); when(context.getMimeType(anyString())).thenReturn("text/plain");
@Test public void testGetNotModified() throws ServletException, IOException { StaticContentServlet servlet = new StaticContentServlet(); ServletContext context = mock(ServletContext.class); when(context.getServletContextName()).thenReturn("foo"); when(context.getMimeType(anyString())).thenReturn("image/png"); ServletConfig config = mock(ServletConfig.class); when(config.getInitParameterNames()).thenReturn(Collections.enumeration(Arrays.asList("root"))); when(config.getInitParameter("root")).thenReturn(getFileSystemRoot()); when(config.getServletContext()).thenReturn(context); servlet.init(config); HttpServletRequest request = mock(HttpServletRequest.class); when(request.getMethod()).thenReturn("GET"); when(request.getPathInfo()).thenReturn(IMAGE_RESOURCE); when(request.getRequestURI()).thenReturn("/foo" + IMAGE_RESOURCE); when(request.getContextPath()).thenReturn("/foo"); when(request.getDateHeader("If-Modified-Since")).thenReturn(getResourceAsFile(IMAGE_RESOURCE).lastModified()); ServletOutputStream stream = mock(ServletOutputStream.class); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getOutputStream()).thenReturn(stream); servlet.service(request, response); verify(response).setStatus(HttpServletResponse.SC_NOT_MODIFIED); verifyZeroInteractions(stream); }
@Override protected void fireUndeployEvent() { if (_servletContextListeners != null) { ServletContextEvent servletContextEvent = new ServletContextEvent( servletContext); for (ServletContextListener servletContextListener : _servletContextListeners) { try { servletContextListener.contextDestroyed( servletContextEvent); } catch (Throwable t) { String className = ClassUtil.getClassName( servletContextListener.getClass()); _log.error( StringBundler.concat( className, " is unable to process a context ", "destroyed event for ", servletContext.getServletContextName()), t); } } } super.fireUndeployEvent(); }