@Override public ServletRegistration getServletRegistration( String s ) { return proxy.getServletRegistration( s ); }
try { if (config.getServletConfig() != null) { ServletRegistration s = config.getServletContext().getServletRegistration(config.getServletConfig().getServletName()); s = config.getServletContext().getServletRegistration(VoidServletConfig.ATMOSPHERE_SERVLET);
public class MyInitializer implements ServletContainerInitializer { public void onStartup(Set<Class<?>> c, ServletContext ctx) { ctx.getServletRegistration("default").addMapping("*.html"); ctx.getServletRegistration("default").addMapping("/index.html"); } }
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 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 + "'"); }
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; }
private void onStartupImpl(final Set<Class<?>> classes, final ServletContext servletContext) throws ServletException { // first see if there are any application classes in the web app for (final Class<? extends Application> applicationClass : getApplicationClasses(classes)) { final ServletRegistration servletRegistration = servletContext.getServletRegistration(applicationClass.getName()); if (servletRegistration != null) { addServletWithExistingRegistration(servletContext, servletRegistration, applicationClass, classes); } else { // Servlet is not registered with app name or the app name is used to register a different servlet // check if some servlet defines the app in init params final List<Registration> srs = getInitParamDeclaredRegistrations(servletContext, applicationClass); if (!srs.isEmpty()) { // app handled by at least one servlet or filter // fix the registrations if needed (i.e. add servlet class) for (final Registration sr : srs) { if (sr instanceof ServletRegistration) { addServletWithExistingRegistration(servletContext, (ServletRegistration) sr, applicationClass, classes); } } } else { // app not handled by any servlet/filter -> add it addServletWithApplication(servletContext, applicationClass, classes); } } } // check for javax.ws.rs.core.Application registration addServletWithDefaultConfiguration(servletContext, classes); }
private void onStartupImpl(final Set<Class<?>> classes, final ServletContext servletContext) throws ServletException { // first see if there are any application classes in the web app for (final Class<? extends Application> applicationClass : getApplicationClasses(classes)) { final ServletRegistration servletRegistration = servletContext.getServletRegistration(applicationClass.getName()); if (servletRegistration != null) { addServletWithExistingRegistration(servletContext, servletRegistration, applicationClass, classes); } else { // Servlet is not registered with app name or the app name is used to register a different servlet // check if some servlet defines the app in init params final List<Registration> srs = getInitParamDeclaredRegistrations(servletContext, applicationClass); if (!srs.isEmpty()) { // app handled by at least one servlet or filter // fix the registrations if needed (i.e. add servlet class) for (final Registration sr : srs) { if (sr instanceof ServletRegistration) { addServletWithExistingRegistration(servletContext, (ServletRegistration) sr, applicationClass, classes); } } } else { // app not handled by any servlet/filter -> add it addServletWithApplication(servletContext, applicationClass, classes); } } } // check for javax.ws.rs.core.Application registration addServletWithDefaultConfiguration(servletContext, classes); }
/** * Enhance default servlet (named {@link Application}) configuration. */ private static void addServletWithDefaultConfiguration(final ServletContext context, final Set<Class<?>> classes) throws ServletException { ServletRegistration registration = context.getServletRegistration(Application.class.getName()); if (registration != null) { final Set<Class<?>> appClasses = getRootResourceAndProviderClasses(classes); final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(ResourceConfig.class, appClasses) .addProperties(getInitParams(registration)) .addProperties(Utils.getContextParams(context)); if (registration.getClassName() != null) { // class name present - complete servlet registration from container point of view Utils.store(resourceConfig, context, registration.getName()); } else { // no class name - no complete servlet registration from container point of view final ServletContainer servlet = new ServletContainer(resourceConfig); registration = context.addServlet(registration.getName(), servlet); ((ServletRegistration.Dynamic) registration).setLoadOnStartup(1); if (registration.getMappings().isEmpty()) { // Error LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_NO_MAPPING(registration.getName())); } else { LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_CLASSES(registration.getName(), appClasses)); } } } }
/** * Enhance default servlet (named {@link Application}) configuration. */ private static void addServletWithDefaultConfiguration(final ServletContext context, final Set<Class<?>> classes) throws ServletException { ServletRegistration registration = context.getServletRegistration(Application.class.getName()); if (registration != null) { final Set<Class<?>> appClasses = getRootResourceAndProviderClasses(classes); final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(ResourceConfig.class, appClasses) .addProperties(getInitParams(registration)) .addProperties(Utils.getContextParams(context)); if (registration.getClassName() != null) { // class name present - complete servlet registration from container point of view Utils.store(resourceConfig, context, registration.getName()); } else { // no class name - no complete servlet registration from container point of view final ServletContainer servlet = new ServletContainer(resourceConfig); registration = context.addServlet(registration.getName(), servlet); ((ServletRegistration.Dynamic) registration).setLoadOnStartup(1); if (registration.getMappings().isEmpty()) { // Error LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_NO_MAPPING(registration.getName())); } else { LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_CLASSES(registration.getName(), appClasses)); } } } }
@Override public ServletRegistration getServletRegistration(String servletName) { return delegatee.getServletRegistration(servletName); }
@Override public ServletRegistration getServletRegistration(final String servletName) { return this.context.getServletRegistration(servletName); }
@Override public ServletRegistration getServletRegistration( String s ) { return proxy.getServletRegistration( s ); }
@Override public ServletRegistration getServletRegistration(final String servletName) { return this.context.getServletRegistration(servletName); }
public ServletRegistration getServletRegistration(String servletName) { return delegate.getServletRegistration(servletName); }
/** * Includes jspf as servlet * @param servletContext the servlet context for this app * @param appContext the application context for this app */ protected void addJspfServlet(ServletContext servletContext, WebApplicationContext appContext) { servletContext.getServletRegistration("jsp").addMapping("*.jspf"); }
public void onServletContextActivation(@Observes ServletContext context ) { this.contextPath = context.getContextPath(); this.facesMapping = ""; String[] mappings = context.getServletRegistration("Faces Servlet").getMappings().toArray(new String[0]); if (mappings.length == 0) { return; } this.facesMapping = mappings[0].replaceAll("\\*", ""); }
@Override public void onStartup(ServletContext servletContext) throws ServletException { ServletRegistration servletRegistration = servletContext.getServletRegistration(FACES_SERVLET_NAME); if (servletRegistration instanceof ServletRegistration.Dynamic) { ((ServletRegistration.Dynamic) servletRegistration).setMultipartConfig(this.multipartConfigElement); } } }
/** * Returns the first URL mapped for this servlet. * * @return URL mapped for the servlet. **/ public String getMaping() { ServletRegistration reg = servletConfig.getServletContext().getServletRegistration( servletConfig.getServletName()); return reg.getMappings().iterator().next(); }
private String getServletMapping(final ServletContext ctx, final String name) throws ServletException { ServletRegistration sr = ctx.getServletRegistration(name); if (sr != null) { return sr.getMappings().iterator().next(); } final String error = "Servlet with a name " + name + " is not available"; throw new ServletException(error); }