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:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerRestApiServlet(ServletContext servletContext) { CubaRestApiServlet cubaRestApiServlet = new SingleAppRestApiServlet(dependencyJars); try {/* w w w . j a v a 2s . c om*/ cubaRestApiServlet.init(new CubaServletConfig("rest_api", servletContext)); } catch (ServletException e) { throw new RuntimeException("An error occurred while initializing dispatcher servlet", e); } ServletRegistration.Dynamic cubaRestApiServletReg = servletContext.addServlet("rest_api", cubaRestApiServlet); cubaRestApiServletReg.setLoadOnStartup(2); cubaRestApiServletReg.addMapping("/rest/*"); DelegatingFilterProxy restSpringSecurityFilterChain = new DelegatingFilterProxy(); restSpringSecurityFilterChain .setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.rest_api"); restSpringSecurityFilterChain.setTargetBeanName("springSecurityFilterChain"); FilterRegistration.Dynamic restSpringSecurityFilterChainReg = servletContext .addFilter("restSpringSecurityFilterChain", restSpringSecurityFilterChain); restSpringSecurityFilterChainReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/rest/*"); }
From source file:org.apache.hadoop.gateway.filter.rewrite.impl.FrontendFunctionProcessorTest.java
public void setUp(String username, Map<String, String> initParams, Attributes attributes) throws Exception { ServiceRegistry mockServiceRegistry = EasyMock.createNiceMock(ServiceRegistry.class); EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "NAMENODE")) .andReturn("test-nn-scheme://test-nn-host:411").anyTimes(); EasyMock.expect(mockServiceRegistry.lookupServiceURL("test-cluster", "JOBTRACKER")) .andReturn("test-jt-scheme://test-jt-host:511").anyTimes(); GatewayServices mockGatewayServices = EasyMock.createNiceMock(GatewayServices.class); EasyMock.expect(mockGatewayServices.getService(GatewayServices.SERVICE_REGISTRY_SERVICE)) .andReturn(mockServiceRegistry).anyTimes(); EasyMock.replay(mockServiceRegistry, mockGatewayServices); String descriptorUrl = TestUtils.getResourceUrl(FrontendFunctionProcessorTest.class, "rewrite.xml") .toExternalForm();/*from w w w . j a v a 2 s. co m*/ Log.setLog(new NoOpLogger()); server = new ServletTester(); server.setContextPath("/"); server.getContext().addEventListener(new UrlRewriteServletContextListener()); server.getContext().setInitParameter(UrlRewriteServletContextListener.DESCRIPTOR_LOCATION_INIT_PARAM_NAME, descriptorUrl); if (attributes != null) { server.getContext().setAttributes(attributes); } server.getContext().setAttribute(GatewayServices.GATEWAY_CLUSTER_ATTRIBUTE, "test-cluster"); server.getContext().setAttribute(GatewayServices.GATEWAY_SERVICES_ATTRIBUTE, mockGatewayServices); FilterHolder setupFilter = server.addFilter(SetupFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); setupFilter.setFilter(new SetupFilter(username)); FilterHolder rewriteFilter = server.addFilter(UrlRewriteServletFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); if (initParams != null) { for (Map.Entry<String, String> entry : initParams.entrySet()) { rewriteFilter.setInitParameter(entry.getKey(), entry.getValue()); } } rewriteFilter.setFilter(new UrlRewriteServletFilter()); interactions = new ArrayQueue<MockInteraction>(); ServletHolder servlet = server.addServlet(MockServlet.class, "/"); servlet.setServlet(new MockServlet("mock-servlet", interactions)); server.start(); interaction = new MockInteraction(); request = HttpTester.newRequest(); response = null; }
From source file:com.jsmartframework.web.manager.ContextControl.java
@Override @SuppressWarnings("unchecked") public void contextInitialized(ServletContextEvent event) { try {/*from w w w. j a v a2 s . com*/ ServletContext servletContext = event.getServletContext(); CONFIG.init(servletContext); if (CONFIG.getContent() == null) { throw new RuntimeException("Configuration file " + Constants.WEB_CONFIG_XML + " was not found in WEB-INF resources folder!"); } String contextConfigLocation = "com.jsmartframework.web.manager"; if (CONFIG.getContent().getPackageScan() != null) { contextConfigLocation += "," + CONFIG.getContent().getPackageScan(); } // Configure necessary parameters in the ServletContext to set Spring configuration without needing an XML file AnnotationConfigWebApplicationContext configWebAppContext = new AnnotationConfigWebApplicationContext(); configWebAppContext.setConfigLocation(contextConfigLocation); CONTEXT_LOADER = new ContextLoader(configWebAppContext); CONTEXT_LOADER.initWebApplicationContext(servletContext); TagEncrypter.init(); TEXTS.init(); IMAGES.init(servletContext); HANDLER.init(servletContext); // ServletControl -> @MultipartConfig @WebServlet(name = "ServletControl", displayName = "ServletControl", loadOnStartup = 1) Servlet servletControl = servletContext.createServlet( (Class<? extends Servlet>) Class.forName("com.jsmartframework.web.manager.ServletControl")); ServletRegistration.Dynamic servletControlReg = (ServletRegistration.Dynamic) servletContext .addServlet("ServletControl", servletControl); servletControlReg.setAsyncSupported(true); servletControlReg.setLoadOnStartup(1); // ServletControl Initial Parameters InitParam[] initParams = CONFIG.getContent().getInitParams(); if (initParams != null) { for (InitParam initParam : initParams) { servletControlReg.setInitParameter(initParam.getName(), initParam.getValue()); } } // MultiPart to allow file upload on ServletControl MultipartConfigElement multipartElement = getServletMultipartElement(); if (multipartElement != null) { servletControlReg.setMultipartConfig(multipartElement); } // Security constraint to ServletControl ServletSecurityElement servletSecurityElement = getServletSecurityElement(servletContext); if (servletSecurityElement != null) { servletControlReg.setServletSecurity(servletSecurityElement); } // TODO: Fix problem related to authentication by container to use SSL dynamically (Maybe create more than one servlet for secure and non-secure patterns) // Check also the use of request.login(user, pswd) // Check the HttpServletRequest.BASIC_AUTH, CLIENT_CERT_AUTH, FORM_AUTH, DIGEST_AUTH // servletReg.setRunAsRole("admin"); // servletContext.declareRoles("admin"); // ServletControl URL mapping String[] servletMapping = getServletMapping(); servletControlReg.addMapping(servletMapping); // ErrorFilter -> @WebFilter(urlPatterns = {"/*"}) Filter errorFilter = servletContext.createFilter( (Class<? extends Filter>) Class.forName("com.jsmartframework.web.filter.ErrorFilter")); FilterRegistration.Dynamic errorFilterReg = (FilterRegistration.Dynamic) servletContext .addFilter("ErrorFilter", errorFilter); errorFilterReg.setAsyncSupported(true); errorFilterReg.addMappingForUrlPatterns( EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ERROR), true, "/*"); // EncodeFilter -> @WebFilter(urlPatterns = {"/*"}) Filter encodeFilter = servletContext.createFilter( (Class<? extends Filter>) Class.forName("com.jsmartframework.web.filter.EncodeFilter")); FilterRegistration.Dynamic encodeFilterReg = (FilterRegistration.Dynamic) servletContext .addFilter("EncodeFilter", encodeFilter); encodeFilterReg.setAsyncSupported(true); encodeFilterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR), true, "/*"); // CacheFilter -> @WebFilter(urlPatterns = {"/*"}) Filter cacheFilter = servletContext.createFilter( (Class<? extends Filter>) Class.forName("com.jsmartframework.web.filter.CacheFilter")); FilterRegistration.Dynamic cacheFilterReg = (FilterRegistration.Dynamic) servletContext .addFilter("CacheFilter", cacheFilter); cacheFilterReg.setAsyncSupported(true); cacheFilterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR), true, "/*"); // Add custom filters defined by client for (String filterName : sortCustomFilters()) { Filter customFilter = servletContext .createFilter((Class<? extends Filter>) HANDLER.webFilters.get(filterName)); HANDLER.executeInjection(customFilter); WebFilter webFilter = customFilter.getClass().getAnnotation(WebFilter.class); FilterRegistration.Dynamic customFilterReg = (FilterRegistration.Dynamic) servletContext .addFilter(filterName, customFilter); if (webFilter.initParams() != null) { for (WebInitParam initParam : webFilter.initParams()) { customFilterReg.setInitParameter(initParam.name(), initParam.value()); } } customFilterReg.setAsyncSupported(webFilter.asyncSupported()); customFilterReg.addMappingForUrlPatterns(EnumSet.copyOf(Arrays.asList(webFilter.dispatcherTypes())), true, webFilter.urlPatterns()); } // FilterControl -> @WebFilter(servletNames = {"ServletControl"}) Filter filterControl = servletContext.createFilter( (Class<? extends Filter>) Class.forName("com.jsmartframework.web.manager.FilterControl")); FilterRegistration.Dynamic filterControlReg = (FilterRegistration.Dynamic) servletContext .addFilter("FilterControl", filterControl); filterControlReg.setAsyncSupported(true); filterControlReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.INCLUDE), true, "ServletControl"); // OutputFilter -> @WebFilter(servletNames = {"ServletControl"}) Filter outputFilter = servletContext.createFilter( (Class<? extends Filter>) Class.forName("com.jsmartframework.web.manager.OutputFilter")); FilterRegistration.Dynamic outputFilterReg = (FilterRegistration.Dynamic) servletContext .addFilter("OutputFilter", outputFilter); outputFilterReg.setAsyncSupported(true); outputFilterReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.INCLUDE), true, "ServletControl"); // AsyncFilter -> @WebFilter(servletNames = {"ServletControl"}) // Filter used case AsyncContext is dispatched internally by AsyncBean implementation Filter asyncFilter = servletContext.createFilter( (Class<? extends Filter>) Class.forName("com.jsmartframework.web.manager.AsyncFilter")); FilterRegistration.Dynamic asyncFilterReg = (FilterRegistration.Dynamic) servletContext .addFilter("AsyncFilter", asyncFilter); asyncFilterReg.setAsyncSupported(true); asyncFilterReg.addMappingForServletNames(EnumSet.of(DispatcherType.ASYNC), true, "ServletControl"); // SessionControl -> @WebListener EventListener sessionListener = servletContext.createListener((Class<? extends EventListener>) Class .forName("com.jsmartframework.web.manager.SessionControl")); servletContext.addListener(sessionListener); // RequestControl -> @WebListener EventListener requestListener = servletContext.createListener((Class<? extends EventListener>) Class .forName("com.jsmartframework.web.manager.RequestControl")); servletContext.addListener(requestListener); // Custom WebServlet -> Custom Servlets created by application for (String servletName : HANDLER.webServlets.keySet()) { Servlet customServlet = servletContext .createServlet((Class<? extends Servlet>) HANDLER.webServlets.get(servletName)); HANDLER.executeInjection(customServlet); WebServlet webServlet = customServlet.getClass().getAnnotation(WebServlet.class); ServletRegistration.Dynamic customReg = (ServletRegistration.Dynamic) servletContext .addServlet(servletName, customServlet); customReg.setLoadOnStartup(webServlet.loadOnStartup()); customReg.setAsyncSupported(webServlet.asyncSupported()); WebInitParam[] customInitParams = webServlet.initParams(); if (customInitParams != null) { for (WebInitParam customInitParam : customInitParams) { customReg.setInitParameter(customInitParam.name(), customInitParam.value()); } } // Add mapping url for custom servlet customReg.addMapping(webServlet.urlPatterns()); if (customServlet.getClass().isAnnotationPresent(MultipartConfig.class)) { customReg.setMultipartConfig(new MultipartConfigElement( customServlet.getClass().getAnnotation(MultipartConfig.class))); } } // Controller Dispatcher for Spring MVC Set<String> requestPaths = HANDLER.requestPaths.keySet(); if (!requestPaths.isEmpty()) { ServletRegistration.Dynamic mvcDispatcherReg = servletContext.addServlet("DispatcherServlet", new DispatcherServlet(configWebAppContext)); mvcDispatcherReg.setLoadOnStartup(1); mvcDispatcherReg.addMapping(requestPaths.toArray(new String[requestPaths.size()])); // RequestPathFilter -> @WebFilter(servletNames = {"DispatcherServlet"}) Filter requestPathFilter = servletContext.createFilter((Class<? extends Filter>) Class .forName("com.jsmartframework.web.manager.RequestPathFilter")); FilterRegistration.Dynamic reqPathFilterReg = (FilterRegistration.Dynamic) servletContext .addFilter("RequestPathFilter", requestPathFilter); reqPathFilterReg.addMappingForServletNames(EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD, DispatcherType.ERROR, DispatcherType.INCLUDE, DispatcherType.ASYNC), true, "DispatcherServlet"); } } catch (Exception ex) { throw new RuntimeException(ex); } }
From source file:com.jivesoftware.os.routing.bird.server.JerseyEndpoints.java
@Override public Handler getHandler(final Server server, String context, String applicationName) { ResourceConfig rc = new ResourceConfig(); if (enableSwagger) { BeanConfig beanConfig = new BeanConfig(); beanConfig.setVersion("1.0.0"); beanConfig.setResourcePackage(resourcePackage); beanConfig.setScan(true);// w w w .j av a 2 s.c o m beanConfig.setBasePath("/"); beanConfig.setTitle(applicationName); Set<String> packages = new HashSet<>(); packages.add(ApiListingResource.class.getPackage().getName()); for (Class<?> clazz : allClasses) { packages.add(clazz.getPackage().getName()); } rc.packages(packages.toArray(new String[0])); } rc.registerClasses(allClasses); rc.register(HttpMethodOverrideFilter.class); rc.register(new JacksonFeature().withMapper(mapper)); rc.register(MultiPartFeature.class); // adds support for multi-part API requests rc.registerInstances(allBinders); rc.registerInstances(new InjectableBinder(allInjectables), new AbstractBinder() { @Override protected void configure() { bind(server).to(Server.class); } }); if (supportCORS) { rc.register(CorsContainerResponseFilter.class); } for (ContainerRequestFilter containerRequestFilter : containerRequestFilters) { rc.register(containerRequestFilter); } for (ContainerResponseFilter containerResponseFilter : containerResponseFilters) { rc.register(containerResponseFilter); } ServletHolder servletHolder = new ServletHolder(new ServletContainer(rc)); ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SESSIONS); servletContextHandler.setContextPath(context); if (!applicationName.isEmpty()) { servletContextHandler.setDisplayName(applicationName); } servletContextHandler.addServlet(servletHolder, "/*"); servletContextHandler.addFilter(NewRelicRequestFilter.class, "/", EnumSet.of(DispatcherType.REQUEST)); return servletContextHandler; }
From source file:io.undertow.servlet.test.path.FilterPathMappingTestCase.java
@Test public void testExtensionMatchServletWithGlobalFilter() throws IOException, ServletException { DeploymentInfo builder = new DeploymentInfo(); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); builder.addServlet(new ServletInfo("*.jsp", PathMappingServlet.class).addMapping("*.jsp")); builder.addFilter(new FilterInfo("/*", PathFilter.class)); builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST); builder.setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(FilterPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext") .setDeploymentName("servletContext.war"); final DeploymentManager manager = container.addDeployment(builder); manager.deploy();//from ww w. ja v a 2 s . c o m root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); TestHttpClient client = new TestHttpClient(); try { runTest(client, "aa.jsp", "*.jsp - /aa.jsp - null", "/*"); } finally { client.getConnectionManager().shutdown(); } }
From source file:io.wcm.caravan.io.http.impl.servletclient.HttpServletRequestMapper.java
@Override public DispatcherType getDispatcherType() { return DispatcherType.REQUEST; }
From source file:com.evolveum.midpoint.web.boot.MidPointSpringApplication.java
@Bean public FilterRegistrationBean wicket() { FilterRegistrationBean registration = new FilterRegistrationBean(); registration.setFilter(new WicketFilter()); registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ERROR); registration.addUrlPatterns("/*"); registration.addInitParameter(WicketFilter.FILTER_MAPPING_PARAM, "/*"); registration.addInitParameter(Application.CONFIGURATION, "deployment"); // development registration.addInitParameter("applicationBean", "midpointApplication"); registration.addInitParameter(WicketFilter.APP_FACT_PARAM, "org.apache.wicket.spring.SpringWebApplicationFactory"); return registration; }
From source file:com.strandls.alchemy.webservices.testbase.JerseyTestEnv.java
/** * Get the test container factory./* w w w . j a v a 2 s . c om*/ * * @param contextListener * @return * @throws TestContainerException */ @Provides @Inject @TestScoped protected TestContainerFactory getTestContainerFactory(final WebserviceTestBaseContextListener contextListener) throws TestContainerException { return new TestContainerFactory() { /* * Create a test container. */ @Override public TestContainer create(final URI baseUri, final DeploymentContext deploymentContext) { return new TestContainer() { private HttpServer server; @Override public URI getBaseUri() { return baseUri; } @Override public ClientConfig getClientConfig() { return null; } public WebappContext getContext(final URI baseUri) { if (baseUri == null) { throw new IllegalArgumentException("The URI must not be null"); } String path = baseUri.getPath(); if (path == null) { throw new IllegalArgumentException( "The URI path, of the URI " + baseUri + ", must be non-null"); } else if (path.isEmpty()) { throw new IllegalArgumentException( "The URI path, of the URI " + baseUri + ", must be present"); } else if (path.charAt(0) != '/') { throw new IllegalArgumentException( "The URI path, of the URI " + baseUri + ". must start with a '/'"); } path = String.format("/%s", UriComponent.decodePath(baseUri.getPath(), true).get(1).toString()); final WebappContext context = new WebappContext("GrizzlyContext", path); final FilterRegistration filterRegistration = context.addFilter("Guice Filter", GuiceFilter.class); filterRegistration.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), "/*"); // Initialize and register JSP Servlet final ServletRegistration jspRegistration = context.addServlet("Jersey Servlet Container", ServletContainer.class); jspRegistration.addMapping("/*"); context.addListener(contextListener); return context; } @Override public void start() { try { final WebappContext context = getContext(getBaseUri()); server = GrizzlyHttpServerFactory.createHttpServer(getBaseUri(), deploymentContext.getResourceConfig()); server.getHttpHandler().setAllowEncodedSlash(true); context.setAttribute(ServerProperties.RESOURCE_VALIDATION_IGNORE_ERRORS, true); context.deploy(server); } catch (final ProcessingException e) { throw new TestContainerException(e); } } @Override public void stop() { this.server.shutdown(); } }; } }; }
From source file:com.thoughtworks.go.server.Jetty9ServerTest.java
@Test public void shouldAddDefaultHeadersForRootContext() throws Exception { jetty9Server.configure();/*from w ww . j ava 2 s. c o m*/ jetty9Server.startHandlers(); HttpServletResponse response = mock(HttpServletResponse.class); when(response.getWriter()).thenReturn(mock(PrintWriter.class)); HttpServletRequest request = mock(HttpServletRequest.class); Request baseRequest = mock(Request.class); when(baseRequest.getDispatcherType()).thenReturn(DispatcherType.REQUEST); when(baseRequest.getHttpFields()).thenReturn(mock(HttpFields.class)); ContextHandler rootPathHandler = getLoadedHandlers().get(GoServerLoadingIndicationHandler.class); rootPathHandler.setServer(server); rootPathHandler.start(); rootPathHandler.handle("/something", baseRequest, request, response); verify(response).setHeader("X-XSS-Protection", "1; mode=block"); verify(response).setHeader("X-Content-Type-Options", "nosniff"); verify(response).setHeader("X-Frame-Options", "SAMEORIGIN"); verify(response).setHeader("X-UA-Compatible", "chrome=1"); }
From source file:io.undertow.servlet.test.path.FilterPathMappingTestCase.java
@Test public void test_WFLY_1935() throws IOException, ServletException { DeploymentInfo builder = new DeploymentInfo(); final PathHandler root = new PathHandler(); final ServletContainer container = ServletContainer.Factory.newInstance(); builder.addServlet(new ServletInfo("*.a", PathMappingServlet.class).addMapping("*.a")); builder.addFilter(new FilterInfo("/*", PathFilter.class)); builder.addFilterUrlMapping("/*", "/*", DispatcherType.REQUEST); //non standard, but we still support it builder.addFilter(new FilterInfo("/SimpleServlet.a", PathFilter.class)); builder.addFilterUrlMapping("/SimpleServlet.a", "/SimpleServlet.a", DispatcherType.REQUEST); builder.setClassIntrospecter(TestClassIntrospector.INSTANCE) .setClassLoader(FilterPathMappingTestCase.class.getClassLoader()).setContextPath("/servletContext") .setDeploymentName("servletContext.war"); final DeploymentManager manager = container.addDeployment(builder); manager.deploy();/*from w ww. j a v a2 s. c o m*/ root.addPrefixPath(builder.getContextPath(), manager.start()); DefaultServer.setRootHandler(root); TestHttpClient client = new TestHttpClient(); try { runTest(client, "SimpleServlet.a", "*.a - /SimpleServlet.a - null", "/*", "/SimpleServlet.a"); } finally { client.getConnectionManager().shutdown(); } }