List of usage examples for javax.servlet ServletContext addServlet
public ServletRegistration.Dynamic addServlet(String servletName, Class<? extends Servlet> servletClass);
From source file:echec.spring.SpringConfigWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Initialise spring au dmarrage de l'application web. AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(SpringConfig.class); servletContext.addListener(new ContextLoaderListener(appContext)); // Register and map the dispatcher servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(appContext)); dispatcher.setLoadOnStartup(1);// ww w. ja v a 2 s . c o m dispatcher.addMapping("/"); }
From source file:org.osgpfoundation.osgp.webdemoapp.application.config.WebDemoInitializer.java
@Override public void onStartup(final ServletContext servletContext) throws ServletException { try {/*from w w w.ja v a 2 s .c o m*/ TimeZone.setDefault(TimeZone.getTimeZone("UTC")); final Context initialContext = new InitialContext(); final AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(ApplicationContext.class); final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); servletContext.addListener(new ContextLoaderListener(rootContext)); } catch (final NamingException e) { throw new ServletException("naming exception", e); } }
From source file:org.lightadmin.core.config.LightAdminWebApplicationInitializer.java
private void registerLightAdminDispatcherRedirector(final ServletContext servletContext) { final DispatcherRedirectorServlet handlerServlet = new DispatcherRedirectorServlet(); ServletRegistration.Dynamic lightAdminDispatcherRedirectorRegistration = servletContext .addServlet(LIGHT_ADMIN_DISPATCHER_REDIRECTOR_NAME, handlerServlet); lightAdminDispatcherRedirectorRegistration.setLoadOnStartup(4); lightAdminDispatcherRedirectorRegistration.addMapping(lightAdminBaseUrl(servletContext)); }
From source file:com.dm.platform.listener.PlatformServletContextListener.java
@Override public void contextInitialized(ServletContextEvent sce) { System.out.println("contextInitialized"); ServletContext sc = sce.getServletContext(); sc.setInitParameter("contextConfigLocation", "/WEB-INF/applicationContext.xml"); // sc.addListener(ContextLoaderListener.class); FilterRegistration fr = sc.addFilter(DelegatingFilterProxy.class.getSimpleName(), DelegatingFilterProxy.class); fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/spring/*"); ServletRegistration sr = sc.addServlet("spring", DispatcherServlet.class); sr.setInitParameter("contextConfigLocation", "/WEB-INF/dispatcher-servlet.xml /WEB-INF/platform-security.xml"); sr.addMapping("/spring/*"); fr = sc.addFilter(DynamicRegistFilter.class.getSimpleName(), DynamicRegistFilter.class); fr.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/platform/*"); }
From source file:org.openmrs.web.WebComponentRegistrar.java
@Override public void setServletContext(ServletContext servletContext) { try {//from w ww .ja v a 2s . co m ServletRegistration openmrsServletReg = servletContext.getServletRegistration("openmrs"); addMappings(openmrsServletReg, "*.htm", "*.form", "*.list", "*.json", "*.field", "*.portlet", "*.page", "*.action"); addMappings(servletContext.getServletRegistration("jsp"), "*.withjstl"); ServletRegistration servletReg = servletContext.addServlet("logoutServlet", new LogoutServlet()); servletReg.addMapping("/logout"); Dynamic filter = servletContext.addFilter("forcePasswordChangeFilter", new ForcePasswordChangeFilter()); filter.setInitParameter("changePasswordForm", "/admin/users/changePassword.form"); filter.setInitParameter("excludeURL", "changePasswordForm,logout,.js,.css,.gif,.jpg,.jpeg,.png"); filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); filter = servletContext.addFilter("adminPageFilter", new AdminPageFilter()); filter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/admin"); servletContext.addListener(new SessionListener()); /* * EfficientShutdownServletContextAttributeListener is used instead of * EfficientShutdownServletContextListener since the latter implements ServletContextListener, * which is not supported by ServletContext.addListener. */ servletContext.addListener(new EfficientShutdownServletContextAttributeListener()); } catch (Exception ex) { //TODO not yet looked into what caused this to fail. } }
From source file:com.kajj.tools.logviewer.config.LogViewerWebApplicationInitializer.java
/** * Initialization method for the ServletContext. Creates the Spring context and * DispatcherServlet.//from ww w. j a v a 2 s . c o m * * @param servletContext The ServletContext to initialize. * @throws ServletException If the ServletContext fails to initialize. */ @Override public void onStartup(final ServletContext servletContext) throws ServletException { final AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext(); springContext.setConfigLocation("com.kajj.tools.logviewer.config"); servletContext.addListener(new ContextLoaderListener(springContext)); final DispatcherServlet servlet = new DispatcherServlet(springContext); final ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, servlet); dispatcher.setLoadOnStartup(1); dispatcher.addMapping(MAPPING_ANY); }
From source file:br.eti.danielcamargo.backend.common.config.WebAppInitializer.java
private void configureWebServlets(ServletContext servletContext, WebApplicationContext rootContext) { AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(WebConfig.class); mvcContext.setParent(rootContext);/*from www . j av a 2 s . com*/ DispatcherServlet restDispatcherServlet = new DispatcherServlet(mvcContext); String restDispatcherName = "Rest Servlet"; ServletRegistration.Dynamic restServletRegistration = servletContext.addServlet(restDispatcherName, restDispatcherServlet); restServletRegistration.setLoadOnStartup(1); restServletRegistration.addMapping("/rest/*"); }
From source file:org.openwms.client.application.ApplicationInitializer.java
/** * {@inheritDoc}//from ww w . ja v a2 s . c o m * * @see org.springframework.web.WebApplicationInitializer#onStartup(javax.servlet.ServletContext) */ @Override public void onStartup(ServletContext servletContext) throws ServletException { // Load application context AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(WebApplicationContextConfiguration.class); // Context loader listener servletContext.addListener(new ContextLoaderListener(rootContext)); // Dispatcher servlet ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1); dispatcher.addMapping("/"); }
From source file:ru.war.name.application.config.Initializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext ctx = new AnnotationConfigWebApplicationContext(); // ?? Spring ? ctx.register(SpringWebConfig.class); ctx.register(SpringSecurityConfig.class); servletContext.addListener(new ContextLoaderListener(ctx)); ctx.setServletContext(servletContext); Dynamic servlet = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(ctx)); servlet.addMapping("/"); servlet.setLoadOnStartup(1);// w w w . jav a2 s .co m }
From source file:io.github.jhipster.config.metrics.PrometheusRegistry.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { if (jHipsterProperties.getMetrics().getPrometheus().isEnabled()) { String endpoint = jHipsterProperties.getMetrics().getPrometheus().getEndpoint(); log.info("Initializing Metrics Prometheus endpoint at {}", endpoint); CollectorRegistry collectorRegistry = new CollectorRegistry(); collectorRegistry.register(new DropwizardExports(metricRegistry)); servletContext.addServlet("prometheusMetrics", new MetricsServlet(collectorRegistry)) .addMapping(endpoint);/*from w w w.ja v a 2s.c om*/ } }