List of usage examples for javax.servlet FilterRegistration.Dynamic addMappingForUrlPatterns
public void addMappingForUrlPatterns(EnumSet<DispatcherType> dispatcherTypes, boolean isMatchAfter, String... urlPatterns);
From source file:com.sandeep.prototypes.address.AddressApplication.java
@Override public void run(AddressConfiguration addressConfiguration, Environment environment) throws Exception { FilterRegistration.Dynamic cors = environment.servlets().addFilter("CORS", CrossOriginFilter.class); cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); cors.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*"); cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, "Content-Type,Authorization,X-Requested-With,Content-Length,Accept,Origin"); cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, "POST,GET,DELETE,PUT,OPTIONS"); cors.setInitParameter("allowCredentials", "true"); environment.jersey().register(new ApiListingResourceJSON()); environment.jersey().register(new ApiDeclarationProvider()); environment.jersey().register(new ResourceListingProvider()); environment.jersey().register(new AddressResource()); environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); BeanConfig config = new BeanConfig(); config.setTitle(addressConfiguration.getApplicationTitle()); config.setDescription(addressConfiguration.getApplicationDescription()); config.setTermsOfServiceUrl(addressConfiguration.getApplicationTosUrl()); config.setContact(addressConfiguration.getApplicationContact()); config.setLicense(addressConfiguration.getLicense()); config.setVersion(addressConfiguration.getVersion()); config.setBasePath(addressConfiguration.getDocsPath()); config.setResourcePackage("com.sandeep.prototypes.address.resources"); config.setScan(true);/*w w w. j a v a 2s .c o m*/ }
From source file:rashjz.info.com.az.config.MyWebInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext appContext = new AnnotationConfigWebApplicationContext(); appContext.register(SpringWebConfig.class); DispatcherServlet dispatcherServlet = new DispatcherServlet(appContext); dispatcherServlet.setThrowExceptionIfNoHandlerFound(true); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("SpringDispatcher", dispatcherServlet); dispatcher.setLoadOnStartup(1);/* w w w . ja v a 2 s . c o m*/ dispatcher.addMapping("/"); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); }
From source file:com.consol.citrus.simulator.WebAppInitializer.java
public void onStartup(ServletContext servletContext) throws ServletException { XmlWebApplicationContext appContext = new XmlWebApplicationContext(); appContext.setConfigLocation("/WEB-INF/citrus-servlet-context.xml"); ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("citrus", new MessageDispatcherServlet()); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.addMapping("/simulator"); dispatcherServlet.addMapping("/simulator/*"); dispatcherServlet.setInitParameter("contextConfigLocation", ""); ServletRegistration.Dynamic statusServlet = servletContext.addServlet("status", new SimulatorStatusServlet()); statusServlet.setLoadOnStartup(1000); statusServlet.addMapping("/status"); statusServlet.addMapping("/status/*"); ServletRegistration.Dynamic runServlet = servletContext.addServlet("run", new SimulatorRunServlet()); runServlet.setLoadOnStartup(1000);//w w w.ja v a 2 s . c om runServlet.addMapping("/run"); runServlet.addMapping("/run/*"); ServletRegistration.Dynamic resourceServlet = servletContext.addServlet("resource", new StaticResourceServlet()); resourceServlet.setLoadOnStartup(1000); resourceServlet.addMapping("/info"); resourceServlet.addMapping("/info/*"); servletContext.addListener(new ContextLoaderListener(appContext)); CharacterEncodingFilter encodingFilter = new CharacterEncodingFilter(); encodingFilter.setEncoding(System.getProperty("file.encoding", "UTF-8")); encodingFilter.setForceEncoding(true); FilterRegistration.Dynamic filter = servletContext.addFilter("encoding-filter", encodingFilter); filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); }
From source file:net.rgielen.actionframeworks.struts2.ApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(ApplicationConfig.class); servletContext.addListener(new ContextLoaderListener(context)); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter);//from w w w. j ava 2s . co m characterEncoding.addMappingForUrlPatterns(dispatcherTypes, false, "/*"); final FilterRegistration.Dynamic struts = servletContext.addFilter("struts", new StrutsPrepareAndExecuteFilter()); struts.addMappingForUrlPatterns(dispatcherTypes, false, "/*"); }
From source file:net.rgielen.actionframeworks.springmvc.ApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext context = new AnnotationConfigWebApplicationContext(); context.register(ApplicationConfig.class); servletContext.addListener(new ContextLoaderListener(context)); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter);/*from w w w . j av a 2 s .c o m*/ characterEncoding.addMappingForUrlPatterns(dispatcherTypes, false, "/*"); ServletRegistration.Dynamic registration = servletContext.addServlet("dispatcher", new DispatcherServlet(context)); registration.setLoadOnStartup(1); registration.addMapping("/"); }
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 ww .j av a 2 s . co m dispatcher.addMapping("/"); FilterRegistration.Dynamic encodingFilter = servletContext.addFilter("encodingFilter", characterEncodingFilter()); encodingFilter.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); }
From source file:org.jblogcms.core.config.MainConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(MainContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet(DISPATCHER_SERVLET_NAME, new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);//from w w w . j a va 2s . c o m dispatcher.addMapping(DISPATCHER_SERVLET_MAPPING); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); security.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); servletContext.addListener(new ContextLoaderListener(rootContext)); }
From source file:com.rakesh.rp3599.config.WebAppInitializer.java
public void onStartup(ServletContext container) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(AppContext.class); /** Dispatcher Servlet **/ ServletRegistration.Dynamic dispatcher = container.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);/* ww w .j ava 2 s . co m*/ dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); /** Dispatcher Types Enum **/ EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); /** UTF-8 Filter **/ FilterRegistration.Dynamic characterEncoding = container.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); /** Context Listener **/ container.addListener(new ContextLoaderListener(rootContext)); }
From source file:com.sandeep.prototypes.person.PersonApplication.java
@Override public void run(PersonConfiguration configuration, Environment environment) throws Exception { // We need CORS enabled so that swagger can access the documentation endpoint and we can // retrieve the swagger compliant json FilterRegistration.Dynamic cors = environment.servlets().addFilter(CORS_FILTER, CrossOriginFilter.class); cors.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, "/*"); cors.setInitParameter(CrossOriginFilter.ACCESS_CONTROL_ALLOW_ORIGIN_HEADER, "*"); cors.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, CORS_HEADERS); cors.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, CORS_METHODS); cors.setInitParameter("allowCredentials", "true"); environment.jersey().register(new ApiListingResourceJSON()); environment.jersey().register(new ApiDeclarationProvider()); environment.jersey().register(new ResourceListingProvider()); // environment.jersey().register(new PersonResource(configuration.getMessage())); environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); BeanConfig config = new BeanConfig(); config.setTitle(configuration.getApplicationTitle()); config.setDescription(configuration.getApplicationDescription()); config.setTermsOfServiceUrl(configuration.getApplicationTosUrl()); config.setContact(configuration.getApplicationContact()); config.setLicense(configuration.getLicense()); config.setVersion(configuration.getVersion()); config.setBasePath(configuration.getDocsPath()); config.setResourcePackage("com.sandeep.prototypes.person.resources"); config.setScan(true);//w w w . j av a 2 s . c o m }
From source file:com.github.sshw.config.RootApplicationConfig.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { AnnotationConfigWebApplicationContext rootContext = new AnnotationConfigWebApplicationContext(); rootContext.register(RootApplicationContext.class); ServletRegistration.Dynamic dispatcher = servletContext.addServlet("dispatcher", new DispatcherServlet(rootContext)); dispatcher.setLoadOnStartup(1);/* w w w. j a v a 2 s . c om*/ dispatcher.setAsyncSupported(true); dispatcher.addMapping("/"); EnumSet<DispatcherType> dispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CharacterEncodingFilter characterEncodingFilter = new CharacterEncodingFilter(); characterEncodingFilter.setEncoding("UTF-8"); characterEncodingFilter.setForceEncoding(true); FilterRegistration.Dynamic characterEncoding = servletContext.addFilter("characterEncoding", characterEncodingFilter); characterEncoding.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); FilterRegistration.Dynamic security = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy()); security.addMappingForUrlPatterns(dispatcherTypes, true, "/*"); servletContext.addListener(new ContextLoaderListener(rootContext)); }