List of usage examples for javax.servlet ServletRegistration.Dynamic addMapping
public Set<String> addMapping(String... urlPatterns);
From source file:com.dm.estore.config.WebAppInitializer.java
private void registerServlets(ServletContext servletContext) { // Enable Spring Data REST in the DispatcherServlet AnnotationConfigWebApplicationContext webCtx = new AnnotationConfigWebApplicationContext(); webCtx.register(RestAPIModule.class); // REST API dispatcher DispatcherServlet dispatcherServlet = new DispatcherServlet(webCtx); ServletRegistration.Dynamic restDispatcher = servletContext.addServlet("restAPI", dispatcherServlet); restDispatcher.setLoadOnStartup(1);//from w ww .ja va 2s. c o m restDispatcher.setAsyncSupported(true); restDispatcher.addMapping(REST_SERVLET_MAPPING); }
From source file:be.wolkmaan.klimtoren.web.config.WebAppInitializer.java
public void logbackServlet(ServletContext servletContext) { ServletRegistration.Dynamic servlet = servletContext.addServlet("logbackStatus", new ch.qos.logback.classic.ViewStatusMessagesServlet()); servlet.setLoadOnStartup(3);//from w ww. j a v a 2 s . com Set<String> mappingConflicts = servlet.addMapping("/admin/logbackStatus/*"); if (!mappingConflicts.isEmpty()) { for (String s : mappingConflicts) { logger.error("Mapping conflict: " + s); } throw new IllegalStateException("servlet cannot be mapped"); } }
From source file:com.zxy.commons.hystrix.web.HystrixInitializer.java
/** * {@inheritDoc}//from w w w .ja v a2 s . c o m */ public void onStartup(ServletContext container) throws ServletException { // WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(container); Properties properties = load(); String enabled = properties.getProperty(HystrixProperties.HYSTRIX_ENABLED); String streamEnabled = properties.getProperty(HystrixProperties.HYSTRIX_STREAM_ENABLED); if ((StringUtils.isBlank(enabled) || "true".equalsIgnoreCase(enabled)) && (StringUtils.isBlank(streamEnabled) || "true".equalsIgnoreCase(streamEnabled))) { // AnnotationConfigWebApplicationContext ctx = new // AnnotationConfigWebApplicationContext(); // ctx.register(AppConfig.class); // ctx.setServletContext(container); // ServletRegistration.Dynamic servlet = // container.addServlet("dispatcher", new DispatcherServlet(ctx)); // WebApplicationContext context = WebApplicationContextUtils.getRequiredWebApplicationContext(container); // servlet.setLoadOnStartup(1); // servlet.addMapping("/"); FilterRegistration.Dynamic hystrixRequestContextServletFilter = container .addFilter("HystrixRequestContextServletFilter", new HystrixRequestContextServletFilter()); hystrixRequestContextServletFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); FilterRegistration.Dynamic hystrixRequestLogViaResponseHeaderServletFilter = container.addFilter( "HystrixRequestLogViaResponseHeaderServletFilter", new HystrixRequestLogViaResponseHeaderServletFilter()); hystrixRequestLogViaResponseHeaderServletFilter .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); ServletRegistration.Dynamic hystrixMetricsStreamServlet = container .addServlet("HystrixMetricsStreamServlet", new HystrixMetricsStreamServlet()); hystrixMetricsStreamServlet.addMapping("/hystrix.stream"); // ServletRegistration.Dynamic proxyStreamServlet = // container.addServlet("ProxyStreamServlet", new // ProxyStreamServlet()); // proxyStreamServlet.addMapping("/proxy.stream"); } }
From source file:cz.muni.fi.editor.webapp.config.init.EditorApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { String bootLogo = " __ __ _ _ _ _ _ _ \n" + " | \\/ | | | | | | | | (_) | \n" + " | \\ / | ___| |_ __ _ __| | __ _| |_ __ _ ___ __| |_| |_ ___ _ __ \n" + " | |\\/| |/ _ \\ __/ _` |/ _` |/ _` | __/ _` | / _ \\/ _` | | __/ _ \\| '__|\n" + " | | | | __/ || (_| | (_| | (_| | || (_| | | __/ (_| | | || (_) | | \n" + " |_| |_|\\___|\\__\\__,_|\\__,_|\\__,_|\\__\\__,_| \\___|\\__,_|_|\\__\\___/|_| \n" + " \n" + " "; System.out.println(ANSI_YELLOW + bootLogo + ANSI_RESET); AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.getEnvironment().setActiveProfiles("production"); rootContext.register(WebAppConfiguration.class, SecurityConfig.class); servletContext.addListener(new ContextLoaderListener(rootContext)); AnnotationConfigWebApplicationContext dispatcherContext = new AnnotationConfigWebApplicationContext(); dispatcherContext.register(MvcConfiguration.class, WebSocketSecurityConfiguration.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(dispatcherContext)); dispatcher.setLoadOnStartup(1);//from w w w. j av a2 s . co m dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); servletContext.addFilter("encodingFilter", new CharacterEncodingFilter("UTF-8", true)) .addMappingForUrlPatterns(null, false, "/*"); servletContext.addFilter("httpMethodFilter", new HiddenHttpMethodFilter()).addMappingForUrlPatterns(null, true, "/*"); }
From source file:com.techtrip.dynbl.context.config.WebAppinitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Setup Context to Accept Annotated Classes on Input (including plain Spring {@code @Component} // Stereotypes in addition to JSR-330 Compliant Classes using {@code javax.inject} AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); //context.setConfigLocation(APP_CONFIG_LOCATION); context.setConfigLocation(APP_CONFIG_LOCATION); /* /* w w w. j a v a 2 s . c o m*/ * Add a Spring Security Filter using the JEE6 Filter Registration Filter Method from {@code FilterRegistration) that allows filters to be registered * and configured with the specified context */ /* FilterRegistration.Dynamic securityFilter = servletContext.addFilter(ProjectKeyValConsts.SECURITY_FILTER.getKey(), new DelegatingFilterProxy(ProjectKeyValConsts.SECURITY_FILTER.getValue())); securityFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ProjectConsts.BASE_URL_MAPPING_PATTERN.getValue()); // where the filter will be applied */ // Add a Character Encoding Filter that specifies an encoding for mapped requests FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); characterEncodingFilter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, ROOT_CONTEXT); // where the filter will be applied characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", Boolean.TRUE.toString()); characterEncodingFilter.setAsyncSupported(true); servletContext.addListener(new ContextLoaderListener(context)); servletContext.setInitParameter("defaultHtmlEscape", Boolean.TRUE.toString()); DispatcherServlet servlet = new DispatcherServlet(); // no explicit configuration reference here: everything is configured in the root container for simplicity servlet.setContextConfigLocation(""); /* TMT From JEE 6 API Docs: * Registers the given servlet instance with this ServletContext under the given servletName. * The registered servlet may be further configured via the returned ServletRegistration object. */ ServletRegistration.Dynamic appServlet = servletContext.addServlet(APP_SERVLET, servlet); appServlet.setLoadOnStartup(1); appServlet.setAsyncSupported(true); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { throw new IllegalStateException(String.format( "The servlet named '%s' cannot be mapped to '/' under Tomcat versions <= 7.0.14", APP_SERVLET)); } // TMT servletContext.addListener(new Log4jConfigListener()); System.out.println("Application inplemented on Spring Version: " + SpringVersion.getVersion()); }
From source file:be.wolkmaan.klimtoren.web.config.WebAppInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { // Create the root appcontext AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootConfig.class); rootContext.register(PersistenceConfig.class); // Manage the lifecycle of the root appcontext servletContext.addListener(new ContextLoaderListener(rootContext)); servletContext.setInitParameter("defaultHtmlEscape", "true"); this.zkLoaderServlet(servletContext); // now the config for the Dispatcher servlet AnnotationConfigWebApplicationContext mvcContext = new AnnotationConfigWebApplicationContext(); mvcContext.register(WebMvcConfig.class); // Filters//from w ww . j a v a 2s.c om // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/package-summary.html // Enables support for DELETE and PUT request methods with web browser // clients // http://static.springsource.org/spring/docs/3.1.x/javadoc-api/org/springframework/web/filter/HiddenHttpMethodFilter.html FilterRegistration.Dynamic fr = servletContext.addFilter("hiddenHttpMethodFilter", new HiddenHttpMethodFilter()); fr.addMappingForUrlPatterns(null, true, "/*"); fr = servletContext.addFilter("encodingFilter", new CharacterEncodingFilter()); fr.setInitParameter("encoding", "UTF-8"); fr.setInitParameter("forceEncoding", "true"); fr.addMappingForUrlPatterns(null, true, "/*"); // The main Spring MVC servlet. ServletRegistration.Dynamic appServlet = servletContext.addServlet("appServlet", new DispatcherServlet(mvcContext)); appServlet.setLoadOnStartup(2); Set<String> mappingConflicts = appServlet.addMapping("/"); if (!mappingConflicts.isEmpty()) { for (String s : mappingConflicts) { logger.error("Mapping conflict: " + s); } throw new IllegalStateException("'appServlet' cannot be mapped to '/' under Tomcat versions <= 7.0.14"); } HttpSessionListener zkCleanUp = new HttpSessionListener(); servletContext.addListener(zkCleanUp); this.logbackServlet(servletContext); this.zkUpdateServlet(servletContext); }
From source file:com.kurento.kmf.content.internal.ContentApiWebApplicationInitializer.java
/** * Recorder initializator: this method search classes in the classpath using * the annotation {@link HttpRecorderService}, and it register a servlet for * each handler found.//from w w w . j ava 2 s .co m * * @param sc * Servlet Context in which registering servlets for each handler * @throws ServletException * Exception raised when a reflection problem occurs, typically * when a class has not been found in the classpath */ private void initializeRecorders(ServletContext sc) throws ServletException { for (String rh : findServices(HttpRecorderHandler.class, HttpRecorderService.class)) { try { HttpRecorderService recorderService = Class.forName(rh).getAnnotation(HttpRecorderService.class); if (recorderService != null) { String name = recorderService.name().isEmpty() ? rh : recorderService.name(); String path = recorderService.path(); log.debug("Registering HttpRecorderHandler with name " + name + " at path " + path); ServletRegistration.Dynamic sr = sc.addServlet(name, RecorderHandlerServlet.class); sr.addMapping(path); sr.setInitParameter(HANDLER_CLASS_PARAM_NAME, rh); sr.setAsyncSupported(true); } } catch (ClassNotFoundException e) { log.error("Error: could not find class " + rh + " in classpath", e); throw new ServletException(e); } } }
From source file:com.kurento.kmf.content.internal.ContentApiWebApplicationInitializer.java
/** * RtpMedia initializator: this method search classes in the classpath using * the annotation {@link RtpContentService}, and it register a servlet for * each handler found./*from w w w. j a va2s. c o m*/ * * @param sc * Servlet Context in which register servlets for each handler * @throws ServletException * Exception raised when a reflection problem occurs, typically * when a class has not been found in the classpath */ private void initializeRtpMediaServices(ServletContext sc) throws ServletException { for (String rh : findServices(RtpContentHandler.class, RtpContentService.class)) { try { RtpContentService mediaService = Class.forName(rh).getAnnotation(RtpContentService.class); if (mediaService != null) { String name = mediaService.name().isEmpty() ? rh : mediaService.name(); String path = mediaService.path(); log.debug("Registering RtpContentHandler with name " + name + " at path " + path); ServletRegistration.Dynamic sr = sc.addServlet(name, RtpMediaHandlerServlet.class); sr.addMapping(path); sr.setInitParameter(HANDLER_CLASS_PARAM_NAME, rh); sr.setAsyncSupported(true); } } catch (ClassNotFoundException e) { log.error("Error: could not find class " + rh + " in classpath", e); throw new ServletException(e); } } }
From source file:com.kurento.kmf.content.internal.ContentApiWebApplicationInitializer.java
/** * WebRtc initializator: this method search classes in the classpath using * the annotation {@link WebRtcContentService}, and it register a servlet * for each handler found.//from w w w . j a va 2s. c om * * @param sc * Servlet Context in which register servlets for each handler * @throws ServletException * Exception raised when a reflection problem occurs, typically * when a class has not been found in the classpath */ private void initializeWebRtcMediaServices(ServletContext sc) throws ServletException { for (String wh : findServices(WebRtcContentHandler.class, WebRtcContentService.class)) { try { WebRtcContentService mediaService = Class.forName(wh).getAnnotation(WebRtcContentService.class); if (mediaService != null) { String name = mediaService.name().isEmpty() ? wh : mediaService.name(); String path = mediaService.path(); log.debug("Registering WebRtcContentHandler with name " + name + " at path " + path); ServletRegistration.Dynamic sr = sc.addServlet(name, WebRtcMediaHandlerServlet.class); sr.addMapping(path); sr.setInitParameter(HANDLER_CLASS_PARAM_NAME, wh); sr.setAsyncSupported(true); } } catch (ClassNotFoundException e) { log.error("Error: could not find class " + wh + " in classpath", e); throw new ServletException(e); } } }
From source file:org.lightadmin.logging.configurer.LightConfigurerWebApplicationInitializer.java
private void registerLightConfigurerDispatcher(final ServletContext servletContext, LoggingConfigurerSettings configuration) { final DispatcherServlet lightConfigurerDispatcher = new DispatcherServlet(createApplicationContext()); ServletRegistration.Dynamic lightConfigurerDispatcherRegistration = servletContext .addServlet("light-configurer-dispatcher", lightConfigurerDispatcher); lightConfigurerDispatcherRegistration.setLoadOnStartup(2); lightConfigurerDispatcherRegistration .addMapping(dispatcherUrlMapping(configuration.getApplicationBaseUrl())); }