@Override public void onStartup(ServletContext servletContext) throws ServletException { String servletName = getServletName(); Assert.hasLength(servletName, "getServletName() must not return null or empty"); ApplicationContext applicationContext = createApplicationContext(); Assert.notNull(applicationContext, "createApplicationContext() must not return null"); refreshApplicationContext(applicationContext); registerCloseListener(servletContext, applicationContext); HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(applicationContext).build(); ServletHttpHandlerAdapter servlet = new ServletHttpHandlerAdapter(httpHandler); ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, servlet); if (registration == null) { throw new IllegalStateException("Failed to register servlet with name '" + servletName + "'. " + "Check if there is another servlet registered under the same name."); } registration.setLoadOnStartup(1); registration.addMapping(getServletMapping()); registration.setAsyncSupported(true); }
public class FooInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) { WebApplicationContext appContext = ...; ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(appContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); } }
/** * Configure registration settings. Subclasses can override this method to perform * additional configuration if required. * @param registration the registration */ @Override protected void configure(ServletRegistration.Dynamic registration) { super.configure(registration); String[] urlMapping = StringUtils.toStringArray(this.urlMappings); if (urlMapping.length == 0 && this.alwaysMapUrl) { urlMapping = DEFAULT_MAPPINGS; } if (!ObjectUtils.isEmpty(urlMapping)) { registration.addMapping(urlMapping); } registration.setLoadOnStartup(this.loadOnStartup); if (this.multipartConfig != null) { registration.setMultipartConfig(this.multipartConfig); } }
public class AppInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { WebApplicationContext context = new MyWebApplicationContext(); servletContext.addListener(new ContextLoaderListener(context)); addStaticHtmlFilesHandlingServlet(servletContext); addSpringDispatcherServlet(servletContext, context); } // (...) private void addStaticHtmlFilesHandlingServlet(ServletContext servletContext) { ServletRegistration.Dynamic servlet = servletContext.addServlet("HtmlsServlet", new StaticFilesServlet()); servlet.setLoadOnStartup(1); servlet.addMapping("*.html"); } }
public class AppInitializer implements WebApplicationInitializer { @Override public void onStartup(ServletContext servletContext) throws ServletException { WebApplicationContext context = new MyWebApplicationContext(); servletContext.addListener(new ContextLoaderListener(context)); addStaticHtmlFilesHandlingServlet(servletContext); addSpringDispatcherServlet(servletContext, context); } // (...) private void addStaticHtmlFilesHandlingServlet(ServletContext servletContext) { ServletRegistration.Dynamic servlet = servletContext.addServlet("HtmlsServlet", new JspServlet()); // org.apache.jasper.servlet.JspServlet servlet.setLoadOnStartup(1); servlet.addMapping("*.html"); } }
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(2); dispatcher.addMapping("/"); dispatcher.setInitParameter("throwExceptionIfNoHandlerFound", "true");
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", dispatcherServlet); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/*"); dispatcher.setMultipartConfig(new MultipartConfigElement("/tmp", 1024*1024*5, 1024*1024*5*5, 1024*1024));
AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(ApplicationConfig.class); servletContext.addListener(new ContextLoaderListener(context)); ServletRegistration.Dynamic servletRegistration = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); servletRegistration.setLoadOnStartup(1); servletRegistration.addMapping("*.htmlx");
ServletRegistration.Dynamic h2Servlet = servletContext.addServlet("h2Servlet", new org.h2.server.web.WebServlet()); h2Servlet.setLoadOnStartup(1); h2Servlet.addMapping("/h2/*");
ServletRegistration.Dynamic api = servletContext.addServlet("ApiServlet", (ApiServlet) ctx.getBean("apiServlet")); api.setLoadOnStartup(1); api.addMapping("/api/*"); // yay now we have a single URL and a single servlet
//register the thrift API servlet using a spring bean ServletRegistration.Dynamic thrift = servletContext.addServlet("thriftapi", (ThriftServlet) ctx.getBean("thriftServlet")); // get thriftServlet from springbeans! thrift.setLoadOnStartup(2); thrift.addMapping("/api/*");
/** Faces Servlet */ ServletRegistration.Dynamic facesServlet = servletContext.addServlet("Faces Servlet", FacesServlet.class); facesServlet.setLoadOnStartup(1); facesServlet.addMapping("*.xhtml");
ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(applicationContext)); dispatcher.setInitParameter("dispatchOptionsRequest", "true"); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/*");
ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new GenericWebApplicationContext()); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/");
// Create the 'root' Spring application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(SecurityConfiguration.class); // Manage the lifecycle of the root application context container.addListener(new ContextLoaderListener(rootContext)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(WebMvcConfiguration.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); // Register spring security FilterChain FilterRegistration.Dynamic registration = container.addFilter("springSecurityFilterChain", DelegatingFilterProxy.class); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR, DispatcherType.ASYNC); registration.addMappingForUrlPatterns(dispatcherTypes, true, "/*");
dispatcherServlet.setContextInitializers(getServletApplicationContextInitializers()); ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, dispatcherServlet); if (registration == null) { throw new IllegalStateException("Failed to register servlet with name '" + servletName + "'. " + registration.setLoadOnStartup(1); registration.addMapping(getServletMappings()); registration.setAsyncSupported(isAsyncSupported());
/** * Add new servlet according to {@link Application} subclass with {@link ApplicationPath} annotation or existing * {@code servlet-mapping}. */ private static void addServletWithApplication(final ServletContext context, final Class<? extends Application> clazz, final Set<Class<?>> defaultClasses) throws ServletException { final ApplicationPath ap = clazz.getAnnotation(ApplicationPath.class); if (ap != null) { // App is annotated with ApplicationPath final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(clazz, defaultClasses) .addProperties(Utils.getContextParams(context)); final ServletContainer s = new ServletContainer(resourceConfig); final ServletRegistration.Dynamic dsr = context.addServlet(clazz.getName(), s); dsr.setAsyncSupported(true); dsr.setLoadOnStartup(1); final String mapping = createMappingPath(ap); if (!mappingExists(context, mapping)) { dsr.addMapping(mapping); LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_MAPPING(clazz.getName(), mapping)); } else { LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_MAPPING_CONFLICT(clazz.getName(), mapping)); } } }
/** * Add new servlet according to {@link Application} subclass with {@link ApplicationPath} annotation or existing * {@code servlet-mapping}. */ private static void addServletWithApplication(final ServletContext context, final Class<? extends Application> clazz, final Set<Class<?>> defaultClasses) throws ServletException { final ApplicationPath ap = clazz.getAnnotation(ApplicationPath.class); if (ap != null) { // App is annotated with ApplicationPath final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(clazz, defaultClasses) .addProperties(Utils.getContextParams(context)); final ServletContainer s = new ServletContainer(resourceConfig); final ServletRegistration.Dynamic dsr = context.addServlet(clazz.getName(), s); dsr.setAsyncSupported(true); dsr.setLoadOnStartup(1); final String mapping = createMappingPath(ap); if (!mappingExists(context, mapping)) { dsr.addMapping(mapping); LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_MAPPING(clazz.getName(), mapping)); } else { LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_MAPPING_CONFLICT(clazz.getName(), mapping)); } } }
final ServletRegistration.Dynamic dynamicRegistration = context.addServlet(clazz.getName(), servlet); dynamicRegistration.setAsyncSupported(true); dynamicRegistration.setLoadOnStartup(1); registration = dynamicRegistration;
final ServletRegistration.Dynamic dynamicRegistration = context.addServlet(clazz.getName(), servlet); dynamicRegistration.setAsyncSupported(true); dynamicRegistration.setLoadOnStartup(1); registration = dynamicRegistration;