List of usage examples for javax.servlet ServletContext addServlet
public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass);
From source file:com.econcept.init.MainWebAppplicationInitializer.java
@Override public void onStartup(ServletContext pContainer) throws ServletException { // Create the 'root' Spring application context AnnotationConfigWebApplicationContext lRootContext = new AnnotationConfigWebApplicationContext(); lRootContext.scan("com.econcept.init"); // Manage the lifecycle of the root application context pContainer.addListener(new ContextLoaderListener(lRootContext)); // Register and map the dispatcher servlet ServletRegistration.Dynamic lDispatcher = pContainer.addServlet("CFXServlet", CXFServlet.class); lDispatcher.addMapping("/rest/*"); // Apply Spring OAuthSecurity to both forward and request dispatcher FilterRegistration.Dynamic lFilter = pContainer.addFilter("unicodeFilter", new UnicodeFilter()); lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*"); // Apply Spring OAuthSecurity to both forward and request dispatcher lFilter = pContainer.addFilter("securityFilter", new DelegatingFilterProxy("springSecurityFilterChain")); lFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD), true, "/*"); pContainer.addListener(AppHttpSessionListener.class); }
From source file:org.jboss.arquillian.spring.testsuite.beans.web.EmployeeWebRootInitializer.java
/** * {@inheritDoc}/*from w w w. jav a 2 s . c om*/ */ public void onStartup(ServletContext servletContext) throws ServletException { // creates the web root app context AnnotationConfigWebApplicationContext webRootContext = new AnnotationConfigWebApplicationContext(); webRootContext.register(WebAppConfig.class); // registers context load listener servletContext.addListener(new ContextLoaderListener(webRootContext)); // adds a dispatch servlet, the servlet will be configured from root web app context ServletRegistration.Dynamic servletConfig = servletContext.addServlet("employee", new DispatcherServlet(new AnnotationConfigWebApplicationContext())); servletConfig.setLoadOnStartup(1); servletConfig.addMapping("*.htm"); }
From source file:com.azirar.requester.ws.config.WebAppInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(AppConf.class); dispatcherServlet.setServletContext(servletContext); // //Added filter dynamically javax.servlet.FilterRegistration.Dynamic corsFilter = servletContext.addFilter("corsFilter", CorsFilter.class); corsFilter.addMappingForUrlPatterns(null, true, "/*"); Dynamic dynamic = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherServlet)); dynamic.addMapping("/"); dynamic.setLoadOnStartup(1);// www .ja v a 2s . co m }
From source file:com.nebhale.cyclinglibrary.web.ApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(UtilConfiguration.class, RepositoryConfiguration.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext(); webContext.register(WebConfiguration.class); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("dispatcher", new DispatcherServlet(webContext)); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.addMapping("/"); FilterRegistration.Dynamic gzipFilter = servletContext.addFilter("gzip", new GzipFilter()); gzipFilter.addMappingForServletNames(null, false, "dispatcher"); FilterRegistration.Dynamic eTagFilter = servletContext.addFilter("etag", new ShallowEtagHeaderFilter()); eTagFilter.addMappingForServletNames(null, false, "dispatcher"); }
From source file:org.jboss.arquillian.spring.testsuite.beans.web.EmployeeWebInitializer.java
/** * {@inheritDoc}/*w w w . j a va2 s . c om*/ */ public void onStartup(ServletContext servletContext) throws ServletException { // creates the web app context AnnotationConfigWebApplicationContext webContext = new AnnotationConfigWebApplicationContext(); webContext.register(WebAppConfig.class); // registers context load listener servletContext.addListener(new ContextLoaderListener(new AnnotationConfigWebApplicationContext())); // adds a dispatch servlet, the servlet will be configured from root web app context ServletRegistration.Dynamic servletConfig = servletContext.addServlet("employee", new DispatcherServlet(webContext)); servletConfig.setLoadOnStartup(1); servletConfig.addMapping("*.htm"); }
From source file:com.sonicle.webtop.core.app.ContextLoader.java
private void addRestApiServlet(ServletContext servletContext, ServiceDescriptor desc) { String serviceId = desc.getManifest().getId(); String name = serviceId + "@RestApiServlet"; String path = com.sonicle.webtop.core.app.servlet.RestApi.URL + "/" + serviceId + "/*"; logger.debug("Adding RestApi servlet [{}] -> [{}]", name, path); Dynamic servlet = servletContext.addServlet(name, com.sonicle.webtop.core.app.servlet.RestApi.class); servlet.setInitParameter("javax.ws.rs.Application", "com.sonicle.webtop.core.app.JaxRsServiceApplication"); servlet.setInitParameter("com.sun.jersey.config.feature.DisableWADL", "true"); servlet.setInitParameter(RestApi.INIT_PARAM_WEBTOP_SERVICE_ID, serviceId); servlet.setLoadOnStartup(2);/*from w w w .ja v a 2 s . c om*/ servlet.setAsyncSupported(true); servlet.addMapping(path); }
From source file:org.uoiu.platform.web.DefaultWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); // appContext.register(AppConfig.class); appContext.getEnvironment().setActiveProfiles("webapp"); servletContext.addListener(new ContextLoaderListener(appContext)); AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(MvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(mvcContext)); dispatcher.setLoadOnStartup(1);/*from w w w . ja v a 2 s . co m*/ dispatcher.addMapping("/"); FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", characterEncodingFilter()); encodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); }
From source file:com.pojur.config.AppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // WebApplicationContext context = getContext(); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ServiceConfig.class, JPAConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherServlet = new AnnotationConfigWebApplicationContext(); dispatcherServlet.register(WebMvcConfig.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(dispatcherServlet)); dispatcher.setLoadOnStartup(1);/* www . jav a 2s . c o m*/ dispatcher.addMapping("/"); }
From source file:com.videohub.configuration.VideoHubInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { LOGGER.trace("Starting videohub app"); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebConfiguration.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(DispatcherConfiguration.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_NAME, new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);/* w w w . j ava 2s . c o m*/ dispatcher.addMapping(DISPATCHER_MAPPING); }