List of usage examples for javax.servlet DispatcherType REQUEST
DispatcherType REQUEST
To view the source code for javax.servlet DispatcherType REQUEST.
Click Source Link
From source file:io.undertow.servlet.test.dispatcher.DispatcherIncludeTestCase.java
@BeforeClass public static void setup() throws ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo().setClassLoader(SimpleServletTestCase.class.getClassLoader()) .setContextPath("/servletContext").setClassIntrospecter(TestClassIntrospector.INSTANCE) .setDeploymentName("servletContext.war") .setResourceManager(new TestResourceLoader(DispatcherIncludeTestCase.class)) .addServlet(new ServletInfo("include", MessageServlet.class) .addInitParam(MessageServlet.MESSAGE, "included").addMapping("/include")) .addServlet(new ServletInfo("dispatcher", IncludeServlet.class).addMapping("/dispatch")) .addServlet(new ServletInfo("pathTest", PathTestServlet.class).addMapping("/path")) .addFilter(new FilterInfo("notIncluded", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Not Included")) .addFilter(new FilterInfo("inc", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Path!")) .addFilter(new FilterInfo("nameFilter", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "Name!")) .addFilterUrlMapping("notIncluded", "/include", DispatcherType.REQUEST) .addFilterUrlMapping("inc", "/include", DispatcherType.INCLUDE) .addFilterServletNameMapping("nameFilter", "include", DispatcherType.INCLUDE); DeploymentManager manager = container.addDeployment(builder); manager.deploy();//from ww w . j a va 2 s .c o m root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
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:com.iflytek.edu.cloud.frame.web.RestServiceWebApplicationInitializer.java
@Override public void onStartup(ServletContext servletContext) throws ServletException { servletContext.setInitParameter("contextConfigLocation", "classpath*:META-INF/spring/*-context.xml"); servletContext.setInitParameter("contextInitializerClasses", ProfileApplicationContextInitializer.class.getName()); servletContext.addListener(new LogBackLoadConfigureListener()); servletContext.addListener(new ContextLoaderListener()); FilterRegistration.Dynamic characterEncodingFilter = servletContext.addFilter("characterEncodingFilter", new CharacterEncodingFilter()); EnumSet<DispatcherType> characterEncodingFilterDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD);//from w w w . jav a2 s. c om characterEncodingFilter.setInitParameter("encoding", "UTF-8"); characterEncodingFilter.setInitParameter("forceEncoding", "true"); characterEncodingFilter.addMappingForUrlPatterns(characterEncodingFilterDispatcherTypes, true, "/*"); FilterRegistration.Dynamic openServiceFilter = servletContext.addFilter("openServiceFilter", new DelegatingFilterProxy()); EnumSet<DispatcherType> openServiceFilterDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); openServiceFilter.addMappingForUrlPatterns(openServiceFilterDispatcherTypes, true, "/api"); if (EnvUtil.jdbcEnabled()) { FilterRegistration.Dynamic serviceMetricsFilter = servletContext.addFilter("serviceMetricsFilter", new DelegatingFilterProxy()); EnumSet<DispatcherType> serviceMetricsFilterDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); serviceMetricsFilter.addMappingForUrlPatterns(serviceMetricsFilterDispatcherTypes, true, "/api"); } FilterRegistration.Dynamic CORSFilter = servletContext.addFilter("CORSFilter", new DelegatingFilterProxy()); EnumSet<DispatcherType> CORSFilterDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); CORSFilter.addMappingForUrlPatterns(CORSFilterDispatcherTypes, true, "/api"); if (EnvUtil.oauthEnabled()) { FilterRegistration.Dynamic springSecurityFilterChain = servletContext .addFilter("springSecurityFilterChain", new DelegatingFilterProxyExt()); EnumSet<DispatcherType> springSecurityFilterChainDispatcherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); springSecurityFilterChain.addMappingForUrlPatterns(springSecurityFilterChainDispatcherTypes, true, "/api"); } else { logger.info( "?oauth2???META-INF/res/profile.propertiesoauth2 profile"); } ServletRegistration.Dynamic dispatcherServlet = servletContext.addServlet("rest", new DispatcherServlet()); dispatcherServlet.setLoadOnStartup(1); dispatcherServlet.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); dispatcherServlet.setInitParameter("contextConfigLocation", "org.spring.rest"); dispatcherServlet.setMultipartConfig(getMultiPartConfig()); dispatcherServlet.addMapping("/api"); ServletRegistration.Dynamic printProjectVersionServlet = servletContext .addServlet("printProjectVersionServlet", new PrintProjectVersionServlet()); printProjectVersionServlet.setLoadOnStartup(Integer.MAX_VALUE); }
From source file:io.undertow.servlet.test.wrapper.AbstractResponseWrapperTestCase.java
@Before public void setup() throws ServletException { DeploymentInfo builder = new DeploymentInfo(); builder.setExceptionHandler(LoggingExceptionHandler.builder() .add(IllegalArgumentException.class, "io.undertow", Logger.Level.DEBUG).build()); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); builder.addServlet(new ServletInfo("wrapperServlet", WrapperServlet.class).addMapping("/*")); builder.addFilter(new FilterInfo("standard", StandardRequestWrappingFilter.class)); builder.addFilterUrlMapping("standard", "/standard", DispatcherType.REQUEST); builder.addFilter(new FilterInfo("nonstandard", NonStandardRequestWrappingFilter.class)); builder.addFilterUrlMapping("nonstandard", "/nonstandard", DispatcherType.REQUEST); builder.setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(AbstractResponseWrapperTestCase.class.getClassLoader()) .setContextPath("/servletContext").setDeploymentName("servletContext.war") .setAllowNonStandardWrappers(isNonStandardAllowed()); final DeploymentManager manager = container.addDeployment(builder); manager.deploy();//w w w . ja v a2 s .c om root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
From source file:br.eti.danielcamargo.backend.common.config.WebAppInitializer.java
private void configureSpringSecurity(ServletContext servletContext, WebApplicationContext rootContext) { EnumSet<DispatcherType> dispacherTypes = EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD); FilterRegistration.Dynamic springSecurity = servletContext.addFilter("springSecurityFilterChain", new DelegatingFilterProxy("springSecurityFilterChain", rootContext)); springSecurity.addMappingForUrlPatterns(dispacherTypes, true, "/*"); }
From source file:io.jmnarloch.spring.request.correlation.support.RequestCorrelationConfiguration.java
@Bean public FilterRegistrationBean requestCorrelationFilterBean(RequestCorrelationFilter correlationFilter) { final FilterRegistrationBean filterRegistration = new FilterRegistrationBean(); filterRegistration.setFilter(correlationFilter); filterRegistration.setMatchAfter(false); filterRegistration.setDispatcherTypes( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ASYNC)); filterRegistration.setAsyncSupported(true); filterRegistration.setOrder(Ordered.HIGHEST_PRECEDENCE); return filterRegistration; }
From source file:io.undertow.servlet.test.handlers.MarkSecureHandlerTestCase.java
@Test public void testMarkSecureHandler() throws IOException, GeneralSecurityException, ServletException { final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); ServletInfo s = new ServletInfo("servlet", MessageServlet.class) .addInitParam(MessageServlet.MESSAGE, HELLO_WORLD).addMapping("/issecure"); DeploymentInfo builder = new DeploymentInfo() .setClassLoader(MarkSecureHandlerTestCase.class.getClassLoader()).setContextPath("/servletContext") .setClassIntrospecter(TestClassIntrospector.INSTANCE).setDeploymentName("servletContext.war") .addServlet(s);// www . ja v a2s .c om builder.addFilter(new FilterInfo("issecure-filter", IsSecureFilter.class)); builder.addFilterUrlMapping("issecure-filter", "/*", DispatcherType.REQUEST); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(new MarkSecureHandler(root)); TestHttpClient client = new TestHttpClient(); try { HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/issecure"); HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); // When MarkSecureHandler is enabled, req.isSecure() should be true Assert.assertEquals("true", result.getHeaders("issecure")[0].getValue()); // When SecureCookieHandler is not enabled, secure cookie is not automatically enabled. Header header = result.getFirstHeader("set-cookie"); Assert.assertEquals("foo=bar", header.getValue()); final String response = HttpClientUtils.readResponse(result); Assert.assertEquals(HELLO_WORLD, response); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.undertow.servlet.test.defaultservlet.DefaultServletCachingTestCase.java
@BeforeClass public static void setup() throws ServletException, IOException { tmpDir = Files.createTempDirectory(DIR_NAME); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext") .setDeploymentName("servletContext.war").setResourceManager(new CachingResourceManager(100, 10000, dataCache, new PathResourceManager(tmpDir, 10485760), METADATA_MAX_AGE)); builder.addServlet(new ServletInfo("DefaultTestServlet", PathTestServlet.class).addMapping("/path/default")) .addFilter(Servlets.filter("message", MessageFilter.class).addInitParam(MessageFilter.MESSAGE, "FILTER_TEXT ")) .addFilterUrlMapping("message", "*.txt", DispatcherType.REQUEST); DeploymentManager manager = container.addDeployment(builder); manager.deploy();/* ww w.j a va2 s .co m*/ root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); }
From source file:com.mnt.base.console.JettyController.java
protected void init() { log.info("Prepare to startup the Jetty Web Server..."); super.init(); final ServletContextHandler context = new ServletContextHandler( BaseConfiguration.isSessionEnabled() ? ServletContextHandler.SESSIONS : ServletContextHandler.NO_SESSIONS); context.setContextPath("/"); jettyServer.setHandler(context);//w w w .j a v a 2s. co m context.addServlet(new ServletHolder(new AccessRouterServlet()), "/*"); super.setupExternalConf(new ExternalConfSetter() { @Override public void addServlet(Class<HttpServlet> servletClass, String pathSpec) throws Exception { HttpServlet servlet = (HttpServlet) (servletClass.newInstance()); context.addServlet(new ServletHolder(servlet), pathSpec); } @Override public void addFilter(Class<Filter> filterClass, String pathSpec) { context.addFilter(filterClass, pathSpec, EnumSet.of(DispatcherType.REQUEST)); } }); }
From source file:io.undertow.servlet.test.metrics.ServletMetricsHandlerTestCase.java
@Test public void testMetrics() throws Exception { final TestMetricsCollector metricsCollector = new TestMetricsCollector(); CompletionLatchHandler completionLatchHandler; final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); DeploymentInfo builder = new DeploymentInfo().setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(ServletPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext") .setDeploymentName("servletContext.war") .setResourceManager(new TestResourceLoader(DefaultServletTestCase.class)); builder.addServlet(/*from www . j av a 2s. co m*/ new ServletInfo("MetricTestServlet", MetricTestServlet.class).addMapping("/path/default")); builder.addFilter(new FilterInfo("Filter", HelloFilter.class)); builder.addFilterUrlMapping("Filter", "/filterpath/*", DispatcherType.REQUEST); builder.setMetricsCollector(metricsCollector); DeploymentManager manager = container.addDeployment(builder); manager.deploy(); root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(completionLatchHandler = new CompletionLatchHandler(root)); HttpGet get = new HttpGet(DefaultServer.getDefaultServerURL() + "/servletContext/path/default"); TestHttpClient client = new TestHttpClient(); try { HttpResponse result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); Assert.assertTrue(HttpClientUtils.readResponse(result).contains("metric")); completionLatchHandler.await(); completionLatchHandler.reset(); MetricsHandler.MetricResult metrics = metricsCollector.getMetrics("MetricTestServlet"); Assert.assertEquals(1, metrics.getTotalRequests()); Assert.assertTrue(metrics.getMaxRequestTime() > 0); Assert.assertEquals(metrics.getMinRequestTime(), metrics.getMaxRequestTime()); Assert.assertEquals(metrics.getMaxRequestTime(), metrics.getTotalRequestTime()); result = client.execute(get); Assert.assertEquals(StatusCodes.OK, result.getStatusLine().getStatusCode()); Assert.assertTrue(HttpClientUtils.readResponse(result).contains("metric")); completionLatchHandler.await(); completionLatchHandler.reset(); metrics = metricsCollector.getMetrics("MetricTestServlet"); Assert.assertEquals(2, metrics.getTotalRequests()); } finally { client.getConnectionManager().shutdown(); } }