@Override public String getServletName() { return wrapped.getServletName(); }
public String getServletName() { return sc.getServletName(); }
public String getAppName() { return config.getServletName(); }
/** * Overridden method that simply returns {@code null} when no * ServletConfig set yet. * @see #getServletConfig() */ @Override @Nullable public String getServletName() { return (getServletConfig() != null ? getServletConfig().getServletName() : null); }
private String getServletPath(ServletConfig config) { String name = config.getServletName(); ServletRegistration registration = config.getServletContext().getServletRegistration(name); if (registration == null) { throw new IllegalStateException("ServletRegistration not found for Servlet '" + name + "'"); } Collection<String> mappings = registration.getMappings(); if (mappings.size() == 1) { String mapping = mappings.iterator().next(); if (mapping.equals("/")) { return ""; } if (mapping.endsWith("/*")) { String path = mapping.substring(0, mapping.length() - 2); if (!path.isEmpty() && logger.isDebugEnabled()) { logger.debug("Found servlet mapping prefix '" + path + "' for '" + name + "'"); } return path; } } throw new IllegalArgumentException("Expected a single Servlet mapping: " + "either the default Servlet mapping (i.e. '/'), " + "or a path based mapping (e.g. '/*', '/foo/*'). " + "Actual mappings: " + mappings + " for Servlet '" + name + "'"); }
@Override public String getServletName() { return filterChain.getServletConfig().getServletName(); } }
/** * Returns the name of this servlet instance. * See {@link ServletConfig#getServletName}. * * @return the name of this servlet instance * * * */ public String getServletName() { ServletConfig sc = getServletConfig(); if (sc == null) { throw new IllegalStateException( lStrings.getString("err.servlet_config_not_initialized")); } return sc.getServletName(); } }
private void publishRequestHandledEvent(HttpServletRequest request, HttpServletResponse response, long startTime, @Nullable Throwable failureCause) { if (this.publishEvents && this.webApplicationContext != null) { // Whether or not we succeeded, publish an event. long processingTime = System.currentTimeMillis() - startTime; this.webApplicationContext.publishEvent( new ServletRequestHandledEvent(this, request.getRequestURI(), request.getRemoteAddr(), request.getMethod(), getServletConfig().getServletName(), WebUtils.getSessionId(request), getUsernameForRequest(request), processingTime, failureCause, response.getStatus())); } }
/** * Create new ServletConfigPropertyValues. * @param config the ServletConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } } }
public static String getContextIdFromServletConfig(ServletConfig config) { String ctxId = null; if (isServletConfigAvailable(config)) { ctxId = getInitParam(config, OpenApiContext.OPENAPI_CONTEXT_ID_KEY); if (StringUtils.isBlank(ctxId)) { ctxId = OpenApiContext.OPENAPI_CONTEXT_ID_PREFIX + "servlet." + config.getServletName(); } } if (StringUtils.isBlank(ctxId)) { ctxId = OpenApiContext.OPENAPI_CONTEXT_ID_DEFAULT; } return ctxId; }
/** * Overridden method that simply returns {@code null} when no * ServletConfig set yet. * @see #getServletConfig() */ @Override @Nullable public String getServletName() { return (getServletConfig() != null ? getServletConfig().getServletName() : null); }
private String getServletPath(ServletConfig config) { String name = config.getServletName(); ServletRegistration registration = config.getServletContext().getServletRegistration(name); if (registration == null) { throw new IllegalStateException("ServletRegistration not found for Servlet '" + name + "'"); } Collection<String> mappings = registration.getMappings(); if (mappings.size() == 1) { String mapping = mappings.iterator().next(); if (mapping.equals("/")) { return ""; } if (mapping.endsWith("/*")) { String path = mapping.substring(0, mapping.length() - 2); if (!path.isEmpty() && logger.isDebugEnabled()) { logger.debug("Found servlet mapping prefix '" + path + "' for '" + name + "'"); } return path; } } throw new IllegalArgumentException("Expected a single Servlet mapping: " + "either the default Servlet mapping (i.e. '/'), " + "or a path based mapping (e.g. '/*', '/foo/*'). " + "Actual mappings: " + mappings + " for Servlet '" + name + "'"); }
private void publishRequestHandledEvent(HttpServletRequest request, HttpServletResponse response, long startTime, @Nullable Throwable failureCause) { if (this.publishEvents && this.webApplicationContext != null) { // Whether or not we succeeded, publish an event. long processingTime = System.currentTimeMillis() - startTime; this.webApplicationContext.publishEvent( new ServletRequestHandledEvent(this, request.getRequestURI(), request.getRemoteAddr(), request.getMethod(), getServletConfig().getServletName(), WebUtils.getSessionId(request), getUsernameForRequest(request), processingTime, failureCause, response.getStatus())); } }
/** * Create new ServletConfigPropertyValues. * @param config the ServletConfig we'll use to take PropertyValues from * @param requiredProperties set of property names we need, where * we can't accept default values * @throws ServletException if any required properties are missing */ public ServletConfigPropertyValues(ServletConfig config, Set<String> requiredProperties) throws ServletException { Set<String> missingProps = (!CollectionUtils.isEmpty(requiredProperties) ? new HashSet<>(requiredProperties) : null); Enumeration<String> paramNames = config.getInitParameterNames(); while (paramNames.hasMoreElements()) { String property = paramNames.nextElement(); Object value = config.getInitParameter(property); addPropertyValue(new PropertyValue(property, value)); if (missingProps != null) { missingProps.remove(property); } } // Fail if we are still missing properties. if (!CollectionUtils.isEmpty(missingProps)) { throw new ServletException( "Initialization from ServletConfig for servlet '" + config.getServletName() + "' failed; the following required properties were missing: " + StringUtils.collectionToDelimitedString(missingProps, ", ")); } } }
public AtmosphereFrameworkInitializer configureFramework(ServletConfig sc, boolean init, boolean useNative, Class<? extends AtmosphereFramework> frameworkClass) throws ServletException { if (framework == null) { if (sc.getServletContext().getMajorVersion() > 2) { try { framework = (AtmosphereFramework) sc.getServletContext() .getAttribute(sc.getServletContext().getServletRegistration(sc.getServletName()).getName()); } catch (Exception ex) { // Equinox throw an exception (NPE) // WebLogic Crap => https://github.com/Atmosphere/atmosphere/issues/1569 if (UnsupportedOperationException.class.isAssignableFrom(ex.getClass())) { logger.warn("WebLogic 12c unable to retrieve Servlet. Please make sure your servlet-name is 'AtmosphereServlet' " + "or set org.atmosphere.servlet to the current value"); String name = sc.getInitParameter(ApplicationConfig.SERVLET_NAME); if (name == null) { name = AtmosphereServlet.class.getSimpleName(); } framework = (AtmosphereFramework) sc.getServletContext().getAttribute(name); } else { logger.trace("", ex); } } } if (framework == null) { framework = newAtmosphereFramework(frameworkClass, isFilter, autoDetectHandlers); } } framework.setUseNativeImplementation(useNative); if (init) framework.init(sc); return this; }
try { if (config.getServletConfig() != null) { ServletRegistration s = config.getServletContext().getServletRegistration(config.getServletConfig().getServletName()); + config.getServletConfig().getServletName());
@Override public void init(ServletConfig servletConfig) throws ServletException { sc = servletConfig.getServletContext(); Mvcs.setServletContext(sc); selfName = servletConfig.getServletName(); Mvcs.set(selfName, null, null); NutConfig config = new ServletNutConfig(servletConfig); Mvcs.setNutConfig(config); handler = new ActionHandler(config); sp = config.getSessionProvider(); }
@Test public void servletHandlerAdapter() throws Exception { MockHttpServletRequest request = new MockHttpServletRequest(getServletContext(), "GET", "/servlet.do"); MockHttpServletResponse response = new MockHttpServletResponse(); complexDispatcherServlet.service(request, response); assertEquals("body", response.getContentAsString()); Servlet myServlet = (Servlet) complexDispatcherServlet.getWebApplicationContext().getBean("myServlet"); assertEquals("complex", myServlet.getServletConfig().getServletName()); assertEquals(getServletContext(), myServlet.getServletConfig().getServletContext()); complexDispatcherServlet.destroy(); assertNull(myServlet.getServletConfig()); }
@Test public void servletWrappingController() throws Exception { HttpServletRequest request = new MockHttpServletRequest("GET", "/somePath"); HttpServletResponse response = new MockHttpServletResponse(); ServletWrappingController swc = new ServletWrappingController(); swc.setServletClass(TestServlet.class); swc.setServletName("action"); Properties props = new Properties(); props.setProperty("config", "myValue"); swc.setInitParameters(props); swc.afterPropertiesSet(); assertNotNull(TestServlet.config); assertEquals("action", TestServlet.config.getServletName()); assertEquals("myValue", TestServlet.config.getInitParameter("config")); assertNull(TestServlet.request); assertFalse(TestServlet.destroyed); assertNull(swc.handleRequest(request, response)); assertEquals(request, TestServlet.request); assertEquals(response, TestServlet.response); assertFalse(TestServlet.destroyed); swc.destroy(); assertTrue(TestServlet.destroyed); }
@Test public void servletWrappingControllerWithBeanName() throws Exception { HttpServletRequest request = new MockHttpServletRequest("GET", "/somePath"); HttpServletResponse response = new MockHttpServletResponse(); ServletWrappingController swc = new ServletWrappingController(); swc.setServletClass(TestServlet.class); swc.setBeanName("action"); swc.afterPropertiesSet(); assertNotNull(TestServlet.config); assertEquals("action", TestServlet.config.getServletName()); assertNull(TestServlet.request); assertFalse(TestServlet.destroyed); assertNull(swc.handleRequest(request, response)); assertEquals(request, TestServlet.request); assertEquals(response, TestServlet.response); assertFalse(TestServlet.destroyed); swc.destroy(); assertTrue(TestServlet.destroyed); }