Java Code Examples for javax.servlet.ServletContext#addServlet()
The following examples show how to use
javax.servlet.ServletContext#addServlet() .
These examples are extracted from open source projects.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: sakai File: WebAppConfiguration.java License: Educational Community License v2.0 | 6 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.setServletContext(servletContext); rootContext.register(ThymeleafConfig.class); servletContext.addListener(new SakaiContextLoaderListener(rootContext)); servletContext.addFilter("sakai.request", RequestFilter.class) .addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.INCLUDE), true, "/*"); Dynamic servlet = servletContext.addServlet("sakai.onedrive", new DispatcherServlet(rootContext)); servlet.addMapping("/"); servlet.setLoadOnStartup(1); }
Example 2
Source Project: flowable-engine File: WebConfigurer.java License: Apache License 2.0 | 6 votes |
/** * Initializes Spring and Spring MVC. */ private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) { LOGGER.debug("Configuring Spring Web application context"); AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); dispatcherServletConfiguration.setParent(rootContext); dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); LOGGER.debug("Registering Spring MVC Servlet"); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); dispatcherServlet.addMapping("/service/*"); dispatcherServlet.setMultipartConfig(new MultipartConfigElement((String) null)); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.setAsyncSupported(true); return dispatcherServlet; }
Example 3
Source Project: tracee File: TraceeInterceptorSpringApplicationInitializer.java License: BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void initialize(AnnotationConfigWebApplicationContext applicationContext) { final AnnotationConfigWebApplicationContext rootCtx = new AnnotationConfigWebApplicationContext(); rootCtx.register(TraceeInterceptorSpringConfig.class); final ServletContext servletContext = applicationContext.getServletContext(); // Manage the lifecycle of the root application context servletContext.addListener(new ContextLoaderListener(rootCtx)); // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(TraceeInterceptorSpringConfig.class); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
Example 4
Source Project: Spring File: WebAppInitializer.java License: Apache License 2.0 | 6 votes |
@Override public void onStartup(ServletContext servletContext) { final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(WebConfig.class); servletContext.addListener(new ContextLoaderListener(context)); final ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcherServlet", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); dispatcher.addMapping("*.html"); dispatcher.addMapping("*.pdf"); dispatcher.addMapping("*.json"); // dispatcher.setInitParameter("contextConfigLocation", "com.spring4.application.configuration.ApplicationConfig"); // dispatcher.setInitParameter("contextClass", "org.springframework.web.context.support.AnnotationConfigWebApplicationContext"); }
Example 5
Source Project: servicecomb-java-chassis File: RestServletInjector.java License: Apache License 2.0 | 6 votes |
public Dynamic inject(ServletContext servletContext, String urlPattern) { String[] urlPatterns = splitUrlPattern(urlPattern); if (urlPatterns.length == 0) { LOGGER.warn("urlPattern is empty, ignore register {}.", SERVLET_NAME); return null; } String listenAddress = ServletConfig.getLocalServerAddress(); if (!ServletUtils.canPublishEndpoint(listenAddress)) { LOGGER.warn("ignore register {}.", SERVLET_NAME); return null; } // dynamic deploy a servlet to handle serviceComb RESTful request Dynamic dynamic = servletContext.addServlet(SERVLET_NAME, RestServlet.class); dynamic.setAsyncSupported(true); dynamic.addMapping(urlPatterns); dynamic.setLoadOnStartup(0); LOGGER.info("RESTful servlet url pattern: {}.", Arrays.toString(urlPatterns)); return dynamic; }
Example 6
Source Project: Tomcat7.0.67 File: TestContextConfig.java License: Apache License 2.0 | 5 votes |
@Override public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException { Servlet s = new CustomDefaultServlet(); ServletRegistration.Dynamic r = ctx.addServlet(servletName, s); r.addMapping("/"); }
Example 7
Source Project: Tomcat8-Source-Read File: TesterServletContainerInitializer2.java License: MIT License | 5 votes |
@Override public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException { Servlet s = new TesterServlet(); ServletRegistration.Dynamic r = ctx.addServlet("TesterServlet2", s); r.addMapping("/TesterServlet2"); }
Example 8
Source Project: Tomcat8-Source-Read File: TestContextConfig.java License: MIT License | 5 votes |
@Override public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException { Servlet s = new CustomDefaultServlet(); ServletRegistration.Dynamic r = ctx.addServlet(servletName, s); r.addMapping("/"); }
Example 9
Source Project: Spring-Security-Third-Edition File: WebAppInitializer.java License: MIT License | 5 votes |
@Override public void onStartup(final ServletContext servletContext) throws ServletException { // Register DispatcherServlet super.onStartup(servletContext); // Register H2 Admin console: ServletRegistration.Dynamic h2WebServlet = servletContext.addServlet("h2WebServlet", "org.h2.server.web.WebServlet"); h2WebServlet.addMapping("/admin/h2/*"); h2WebServlet.setInitParameter("webAllowOthers", "true"); }
Example 10
Source Project: junit-servers File: WebApplicationConfiguration.java License: MIT License | 5 votes |
private void initSpringMvc(ServletContext servletContext, AnnotationConfigWebApplicationContext context) { DispatcherServlet dispatcherServlet = new DispatcherServlet(context); dispatcherServlet.setContextConfigLocation(configLocation()); dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("spring", dispatcherServlet); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/*"); dispatcher.addMapping("/"); }
Example 11
Source Project: FRC-2018-Public File: AppInitializer.java License: MIT License | 5 votes |
public void onStartup(ServletContext container) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(AppConfig.class); ctx.setServletContext(container); ServletRegistration.Dynamic servlet = container.addServlet("dispatcher", new DispatcherServlet(ctx)); servlet.setLoadOnStartup(1); servlet.addMapping("/"); }
Example 12
Source Project: Spring-5.0-Cookbook File: SpringWebInitializer.java License: MIT License | 5 votes |
private void addDispatcherContext(ServletContext container) { // Create the dispatcher servlet's Spring application context AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(SpringDispatcherConfig.class); // Declare <servlet> and <servlet-mapping> for the DispatcherServlet ServletRegistration.Dynamic dispatcher = container.addServlet("ch02-servlet", new DispatcherServlet(dispatcherContext)); dispatcher.addMapping("*.html"); dispatcher.setLoadOnStartup(1); }
Example 13
Source Project: tomcatsrc File: TestStandardContext.java License: Apache License 2.0 | 5 votes |
@Override public void onStartup(Set<Class<?>> c, ServletContext ctx) throws ServletException { // Register and map servlet s = new Bug51376Servlet(); ServletRegistration.Dynamic sr = ctx.addServlet("bug51376", s); sr.addMapping("/bug51376"); if (loadOnStartUp) { sr.setLoadOnStartup(1); } }
Example 14
Source Project: chronos File: AppInitializer.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public void onStartup(ServletContext container) { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(TestConfig.class); rootContext.registerShutdownHook(); container.addListener(new ContextLoaderListener(rootContext)); ServletRegistration.Dynamic dispatcher = container.addServlet("chronos-dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/swagger-ui.html"); dispatcher.addMapping("/*"); }
Example 15
Source Project: spring-analysis-note File: AbstractDispatcherServletInitializer.java License: MIT License | 5 votes |
/** * Register a {@link DispatcherServlet} against the given servlet context. * <p>This method will create a {@code DispatcherServlet} with the name returned by * {@link #getServletName()}, initializing it with the application context returned * from {@link #createServletApplicationContext()}, and mapping it to the patterns * returned from {@link #getServletMappings()}. * <p>Further customization can be achieved by overriding {@link * #customizeRegistration(ServletRegistration.Dynamic)} or * {@link #createDispatcherServlet(WebApplicationContext)}. * @param servletContext the context to register the servlet against */ protected void registerDispatcherServlet(ServletContext servletContext) { String servletName = getServletName(); Assert.hasLength(servletName, "getServletName() must not return null or empty"); WebApplicationContext servletAppContext = createServletApplicationContext(); Assert.notNull(servletAppContext, "createServletApplicationContext() must not return null"); FrameworkServlet dispatcherServlet = createDispatcherServlet(servletAppContext); Assert.notNull(dispatcherServlet, "createDispatcherServlet(WebApplicationContext) must not return null"); dispatcherServlet.setContextInitializers(getServletApplicationContextInitializers()); ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, dispatcherServlet); 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(getServletMappings()); registration.setAsyncSupported(isAsyncSupported()); Filter[] filters = getServletFilters(); if (!ObjectUtils.isEmpty(filters)) { for (Filter filter : filters) { registerServletFilter(servletContext, filter); } } customizeRegistration(registration); }
Example 16
Source Project: piranha File: MojarraInitializer.java License: BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Initialize Mojarra. * * @param classes the classes. * @param servletContext the Servlet context. * @throws ServletException when a Servlet error occurs. */ @Override public void onStartup(Set<Class<?>> classes, ServletContext servletContext) throws ServletException { Dynamic dynamic = servletContext.addServlet("Faces Servlet", "javax.faces.webapp.FacesServlet"); dynamic.addMapping("/faces/*", "*.html", "*.xhtml", "*.jsf"); servletContext.setAttribute("com.sun.faces.facesInitializerMappingsAdded", TRUE); servletContext.addListener("com.sun.faces.config.ConfigureListener"); }
Example 17
Source Project: springMvc4.x-project File: WebInitializer.java License: Apache License 2.0 | 5 votes |
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); ctx.register(MyMvcConfig.class); ctx.setServletContext(servletContext); // ② Dynamic servlet = servletContext.addServlet("dispatcher",new DispatcherServlet(ctx)); // 3 servlet.addMapping("/"); servlet.setLoadOnStartup(1); }
Example 18
Source Project: syncope File: SyncopeBuildToolsApplication.java License: Apache License 2.0 | 5 votes |
@Override public void onStartup(final ServletContext sc) throws ServletException { sc.addListener(new ConnectorServerStartStopListener()); sc.addListener(new ApacheDSStartStopListener()); sc.addListener(new H2StartStopListener()); sc.addListener(new GreenMailStartStopListener()); ServletRegistration.Dynamic apacheDS = sc.addServlet("ApacheDSRootDseServlet", ApacheDSRootDseServlet.class); apacheDS.addMapping("/apacheDS"); ServletRegistration.Dynamic sts = sc.addServlet("ServiceTimeoutServlet", ServiceTimeoutServlet.class); sts.addMapping("/services/*"); super.onStartup(sc); }
Example 19
Source Project: Spring File: WebAppInitializer.java License: Apache License 2.0 | 5 votes |
@Override public void onStartup(ServletContext servletContext) { final AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(WebConfig.class); servletContext.addListener(new ContextLoaderListener(context)); final ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcherServlet", new DispatcherServlet(context)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/invoker/*"); }
Example 20
Source Project: activiti6-boot2 File: WebConfigurer.java License: Apache License 2.0 | 5 votes |
/** * Initializes Spring and Spring MVC. */ private ServletRegistration.Dynamic initSpring(ServletContext servletContext, AnnotationConfigWebApplicationContext rootContext) { log.debug("Configuring Spring Web application context"); AnnotationConfigWebApplicationContext dispatcherServletConfiguration = new AnnotationConfigWebApplicationContext(); dispatcherServletConfiguration.setParent(rootContext); dispatcherServletConfiguration.register(DispatcherServletConfiguration.class); log.debug("Registering Spring MVC Servlet"); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServletConfiguration)); dispatcherServlet.addMapping("/service/*"); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.setAsyncSupported(true); return dispatcherServlet; }