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.thoughtworks.go.server.web.UrlRewriterIntegrationTest.java
@BeforeClass public static void beforeClass() throws Exception { ServletHelper.init();// www . j a v a2s . c o m httpUtil = new HttpTestUtil(new HttpTestUtil.ContextCustomizer() { public void customize(WebAppContext ctx) throws Exception { wac = mock(WebApplicationContext.class); ctx.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, wac); URL resource = getClass().getClassLoader().getResource("WEB-INF/urlrewrite.xml"); if (resource == null) { throw new RuntimeException("Cannot load WEB-INF/urlrewrite.xml"); } ctx.setBaseResource(Resource.newResource(new File(resource.getFile()).getParent())); ctx.addFilter(UrlRewriteFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)) .setInitParameter("confPath", "/urlrewrite.xml"); ctx.addServlet(HttpTestUtil.EchoServlet.class, "/*"); } }); httpUtil.httpConnector(HTTP); httpUtil.httpsConnector(HTTPS); when(wac.getBean("serverConfigService")).thenReturn(new BaseUrlProvider() { public boolean hasAnyUrlConfigured() { return useConfiguredUrls; } public String siteUrlFor(String url, boolean forceSsl) throws URISyntaxException { ServerSiteUrlConfig siteUrl = forceSsl ? new ServerSiteUrlConfig(HTTPS_SITE_URL) : new ServerSiteUrlConfig(HTTP_SITE_URL); return siteUrl.siteUrlFor(url); } }); httpUtil.start(); originalSslPort = System.getProperty(SystemEnvironment.CRUISE_SERVER_SSL_PORT); System.setProperty(SystemEnvironment.CRUISE_SERVER_SSL_PORT, String.valueOf(HTTPS)); FeatureToggleService featureToggleService = mock(FeatureToggleService.class); when(featureToggleService.isToggleOn(anyString())).thenReturn(true); Toggles.initializeWith(featureToggleService); }
From source file:com.github.tomakehurst.wiremock.jetty9.JettyHttpServer.java
private ServletContextHandler addAdminContext(AdminRequestHandler adminRequestHandler, Notifier notifier) { ServletContextHandler adminContext = new ServletContextHandler(jettyServer, ADMIN_CONTEXT_ROOT); adminContext.setInitParameter("org.eclipse.jetty.servlet.Default.maxCacheSize", "0"); String javaVendor = System.getProperty("java.vendor"); if (javaVendor != null && javaVendor.toLowerCase().contains("android")) { //Special case for Android, fixes IllegalArgumentException("resource assets not found."): // The Android ClassLoader apparently does not resolve directories. // Furthermore, lib assets will be merged into a single asset directory when a jar file is assimilated into an apk. // As resources can be addressed like "assets/swagger-ui/index.html", a static path element will suffice. adminContext.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", "assets"); } else {// ww w. j a va 2 s . c o m adminContext.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", Resources.getResource("assets").toString()); } Resources.getResource("assets/swagger-ui/index.html"); adminContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); adminContext.addServlet(DefaultServlet.class, "/swagger-ui/*"); adminContext.addServlet(DefaultServlet.class, "/recorder/*"); ServletHolder servletHolder = adminContext.addServlet(WireMockHandlerDispatchingServlet.class, "/"); servletHolder.setInitParameter(RequestHandler.HANDLER_CLASS_KEY, AdminRequestHandler.class.getName()); adminContext.setAttribute(AdminRequestHandler.class.getName(), adminRequestHandler); adminContext.setAttribute(Notifier.KEY, notifier); FilterHolder filterHolder = new FilterHolder(CrossOriginFilter.class); filterHolder.setInitParameters(ImmutableMap.of("chainPreflight", "false", "allowedOrigins", "*", "allowedHeaders", "X-Requested-With,Content-Type,Accept,Origin,Authorization", "allowedMethods", "OPTIONS,GET,POST,PUT,PATCH,DELETE")); adminContext.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); return adminContext; }
From source file:org.ireland.jnetty.webapp.WebApp.java
private void initConstructor() { _beanFactory = new BeanFactory(getClassLoader()); _servletManager = new ServletManager(this); _servletMapper = new ServletMapper(this, this, _servletManager); _filterManager = new FilterManager(this, this); _dispatchFilterMapper = new FilterMapper(this, _filterManager, DispatcherType.REQUEST); _includeFilterMapper = new FilterMapper(this, _filterManager, DispatcherType.INCLUDE); _forwardFilterMapper = new FilterMapper(this, _filterManager, DispatcherType.FORWARD); _errorFilterMapper = new FilterMapper(this, _filterManager, DispatcherType.ERROR); // _errorPageManager = new ErrorPageManager(_server, this); // Use JVM temp dir as ServletContext temp dir. _tempDir = System.getProperty(TEMPDIR); _sessionManager = new SessionManager(this); }
From source file:com.mirth.connect.server.MirthWebServer.java
private void addApiServlets(HandlerList handlers, String contextPath, String baseAPI, boolean apiAllowHTTP, Version version) {/*from w ww . ja v a 2 s .co m*/ String apiPath = ""; Version apiVersion = version; if (apiVersion != null) { apiPath += "/" + apiVersion.toString(); } else { apiVersion = Version.getLatest(); } // Create the servlet handler for the API ServletContextHandler apiServletContextHandler = new ServletContextHandler(); apiServletContextHandler.setMaxFormContentSize(0); apiServletContextHandler.setSessionHandler(new SessionHandler()); apiServletContextHandler.setContextPath(contextPath + baseAPI + apiPath); apiServletContextHandler.addFilter(new FilterHolder(new ApiOriginFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)); apiServletContextHandler.addFilter(new FilterHolder(new MethodFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)); setConnectorNames(apiServletContextHandler, apiAllowHTTP); ApiProviders apiProviders = getApiProviders(apiVersion); // Add versioned Jersey API servlet ServletHolder jerseyVersionedServlet = apiServletContextHandler.addServlet(ServletContainer.class, "/*"); jerseyVersionedServlet.setInitOrder(1); jerseyVersionedServlet.setInitParameter(ServerProperties.PROVIDER_PACKAGES, StringUtils.join(apiProviders.providerPackages, ',')); jerseyVersionedServlet.setInitParameter(ServerProperties.PROVIDER_CLASSNAMES, joinClasses(apiProviders.providerClasses)); // Add versioned Swagger bootstrap configuration servlet ServletHolder swaggerVersionedServlet = new ServletHolder( new SwaggerServlet(contextPath + baseAPI + apiPath, version, apiVersion, apiProviders.servletInterfacePackages, apiProviders.servletInterfaces, apiAllowHTTP)); swaggerVersionedServlet.setInitOrder(2); apiServletContextHandler.addServlet(swaggerVersionedServlet, "/swagger*"); // Add Swagger UI web page servlet handlers.addHandler(getSwaggerContextHandler(contextPath, baseAPI, apiAllowHTTP, version)); // Add API handler handlers.addHandler(apiServletContextHandler); }
From source file:com.erudika.scoold.ScooldServer.java
/** * @return CSRF protection filter bean// w ww. j a v a2 s . co m */ @Bean public FilterRegistrationBean<CsrfFilter> csrfFilterRegistrationBean() { String path = "/*"; logger.debug("Initializing CSRF filter [{}]...", path); FilterRegistrationBean<CsrfFilter> frb = new FilterRegistrationBean<>(new CsrfFilter()); frb.setDispatcherTypes(EnumSet.of(DispatcherType.REQUEST)); frb.setName("csrfFilter"); frb.setAsyncSupported(true); frb.addUrlPatterns(path); frb.setMatchAfter(false); frb.setEnabled(true); frb.setOrder(2); return frb; }
From source file:org.apache.eagle.service.app.ServiceApp.java
@Override public void run(AlertDropWizardConfiguration configuration, Environment environment) throws Exception { if (StringUtils.isNotEmpty(configuration.getApplicationConfPath())) { // setup config if given System.setProperty("config.resource", configuration.getApplicationConfPath()); ConfigFactory.invalidateCaches(); ConfigFactory.load();/* w w w . ja v a 2s . c o m*/ } environment.getApplicationContext().setContextPath("/rest"); environment.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL); environment.jersey().register(MetadataResource.class); environment.jersey().register(CoordinatorResource.class); // swagger resources environment.jersey().register(new ApiListingResource()); BeanConfig swaggerConfig = new BeanConfig(); swaggerConfig.setTitle("Alert engine service: metadata and coordinator"); swaggerConfig.setVersion("v1.2"); swaggerConfig.setBasePath("/rest"); swaggerConfig.setResourcePackage( "org.apache.eagle.alert.coordinator.resource,org.apache.eagle.service.metadata.resource"); swaggerConfig.setScan(true); // simple CORS filter environment.servlets().addFilter("corsFilter", new SimpleCORSFiler()) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); // context listener environment.servlets().addServletListeners(new CoordinatorListener()); }
From source file:org.apache.hive.hcatalog.templeton.Main.java
public Server runServer(int port) throws Exception { //Authenticate using keytab if (UserGroupInformation.isSecurityEnabled()) { UserGroupInformation.loginUserFromKeytab(conf.kerberosPrincipal(), conf.kerberosKeytab()); }//w w w . j a va2 s. co m // Create the Jetty server. If jetty conf file exists, use that to create server // to have more control. Server server = null; if (StringUtils.isEmpty(conf.jettyConfiguration())) { server = new Server(port); } else { FileInputStream jettyConf = new FileInputStream(conf.jettyConfiguration()); XmlConfiguration configuration = new XmlConfiguration(jettyConf); server = (Server) configuration.configure(); } ServletContextHandler root = new ServletContextHandler(server, "/"); // Add the Auth filter FilterHolder fHolder = makeAuthFilter(); EnumSet<DispatcherType> dispatches = EnumSet.of(DispatcherType.REQUEST); /* * We add filters for each of the URIs supported by templeton. * If we added the entire sub-structure using '/*', the mapreduce * notification cannot give the callback to templeton in secure mode. * This is because mapreduce does not use secure credentials for * callbacks. So jetty would fail the request as unauthorized. */ root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/ddl/*", dispatches); root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/pig/*", dispatches); root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/hive/*", dispatches); root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/sqoop/*", dispatches); root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/queue/*", dispatches); root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/jobs/*", dispatches); root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/mapreduce/*", dispatches); root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/status/*", dispatches); root.addFilter(fHolder, "/" + SERVLET_PATH + "/v1/version/*", dispatches); if (conf.getBoolean(AppConfig.XSRF_FILTER_ENABLED, false)) { root.addFilter(makeXSRFFilter(), "/" + SERVLET_PATH + "/*", dispatches); LOG.debug("XSRF filter enabled"); } else { LOG.warn("XSRF filter disabled"); } // Connect Jersey ServletHolder h = new ServletHolder(new ServletContainer(makeJerseyConfig())); root.addServlet(h, "/" + SERVLET_PATH + "/*"); // Add any redirects addRedirects(server); // Start the server server.start(); this.server = server; return server; }
From source file:org.apache.marmotta.platform.core.test.base.JettyMarmotta.java
public JettyMarmotta(Configuration override, String context, int port, Set<Class<?>> webservices) { super();// ww w . j a v a 2s.c o m this.port = port; this.context = (context != null ? context : "/"); List<Configuration> configurations = new ArrayList<>(); if (override != null) { configurations.add(override); } configurations.add(this.override); // create a new jetty & run it on port 8080 jetty = new Server(this.port); TestInjectorFactory.setManager(container.getBeanManager()); ServletContextHandler ctx = new ServletContextHandler(jetty, this.context); // now we have a context, start up the first phase of the LMF initialisation startupService.startupConfiguration(home.getAbsolutePath(), new CompositeConfiguration(configurations), ctx.getServletContext()); // register the RestEasy CDI injector factory ctx.setAttribute("resteasy.injector.factory", TestInjectorFactory.class.getCanonicalName()); // register filters FilterHolder resourceFilter = new FilterHolder(CDIContext.getInstance(MarmottaResourceFilter.class)); resourceFilter.setInitParameter("kiwi.resourceCaching", "true"); ctx.addFilter(resourceFilter, "/*", EnumSet.of(DispatcherType.REQUEST)); // register RestEasy so we can run web services // if a single web service is given, only register that webservice, otherwise startup the default configuration //FilterHolder restEasyFilter = new FilterHolder(org.jboss.resteasy.plugins.server.servlet.FilterDispatcher.class); ServletHolder restEasyFilter = new ServletHolder( org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.class); restEasyFilter.setInitParameter("resteasy.injector.factory", TestInjectorFactory.class.getCanonicalName()); if (webservices != null) { TestApplication.setTestedWebServices(webservices); //restEasyFilter.setInitParameter("resteasy.resources", webservice.getName()); restEasyFilter.setInitParameter("javax.ws.rs.Application", TestApplication.class.getCanonicalName()); } else { restEasyFilter.setInitParameter("javax.ws.rs.Application", CoreApplication.class.getCanonicalName()); } //ctx.addFilter(restEasyFilter,"/*", Handler.ALL); ctx.addServlet(restEasyFilter, "/*"); try { jetty.start(); String url = "http://localhost:" + this.port + this.context + "/"; startupService.startupHost(url, url); } catch (Exception e) { log.error("could not start up embedded jetty server", e); } // make sure exception mappers are loaded and registered ExceptionMapperServiceImpl mapperService = CDIContext.getInstance(ExceptionMapperServiceImpl.class); try { mapperService.register( ((HttpServletDispatcher) restEasyFilter.getServlet()).getDispatcher().getProviderFactory()); } catch (ServletException e) { log.warn("could not register exception mappers"); } // make sure interceptors are loaded and registered InterceptorServiceImpl interceptorService = CDIContext.getInstance(InterceptorServiceImpl.class); try { interceptorService.register( ((HttpServletDispatcher) restEasyFilter.getServlet()).getDispatcher().getProviderFactory()); } catch (ServletException e) { log.warn("could not register interceptors"); } }
From source file:org.artificer.devsvr.ArtificerDevServer.java
/** * @see org.overlord.commons.dev.server.DevServer#addModulesToJetty(org.overlord.commons.dev.server.DevServerEnvironment, org.eclipse.jetty.server.handler.ContextHandlerCollection) *//*from w w w . j av a2s. c o m*/ @Override protected void addModulesToJetty(DevServerEnvironment environment, ContextHandlerCollection handlers) throws Exception { super.addModulesToJetty(environment, handlers); /* ********* * S-RAMP UI * ********* */ ServletContextHandler artificerUI = new ServletContextHandler(ServletContextHandler.SESSIONS); artificerUI.setSecurityHandler(createSecurityHandler(true)); artificerUI.setContextPath("/artificer-ui"); artificerUI.setResourceBase(environment.getModuleDir("artificer-ui").getCanonicalPath()); artificerUI.addFilter(GWTCacheControlFilter.class, "/app/*", EnumSet.of(DispatcherType.REQUEST)); artificerUI.addFilter(GWTCacheControlFilter.class, "/rest/*", EnumSet.of(DispatcherType.REQUEST)); artificerUI.addFilter(GWTCacheControlFilter.class, "/", EnumSet.of(DispatcherType.REQUEST)); artificerUI.addFilter(GWTCacheControlFilter.class, "*.html", EnumSet.of(DispatcherType.REQUEST)); artificerUI.addFilter(ResourceCacheControlFilter.class, "/css/*", EnumSet.of(DispatcherType.REQUEST)); artificerUI.addFilter(ResourceCacheControlFilter.class, "/images/*", EnumSet.of(DispatcherType.REQUEST)); artificerUI.addFilter(ResourceCacheControlFilter.class, "/js/*", EnumSet.of(DispatcherType.REQUEST)); artificerUI.addFilter(LocaleFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); // Servlets artificerUI.addServlet(new ServletHolder(ArtifactUploadServlet.class), "/app/services/artifactUpload"); artificerUI.addServlet(new ServletHolder(ArtifactCreateServlet.class), "/app/services/artifactCreate"); artificerUI.addServlet(new ServletHolder(ArtifactDownloadServlet.class), "/app/services/artifactDownload"); artificerUI.addServlet(new ServletHolder(OntologyUploadServlet.class), "/app/services/ontologyUpload"); artificerUI.addServlet(new ServletHolder(OntologyDownloadServlet.class), "/app/services/ontologyDownload"); artificerUI.addServlet(new ServletHolder(KeyCloakLogoutServlet.class), "/app/services/logout"); ServletHolder resteasyUIServlet = new ServletHolder(new HttpServletDispatcher()); resteasyUIServlet.setInitParameter("javax.ws.rs.Application", JettyArtificerApplication.class.getName()); resteasyUIServlet.setInitParameter("resteasy.servlet.mapping.prefix", "/rest"); artificerUI.addServlet(resteasyUIServlet, "/rest/*"); // File resources ServletHolder resources = new ServletHolder(new MultiDefaultServlet()); resources.setInitParameter("resourceBase", "/"); resources.setInitParameter("resourceBases", environment.getModuleDir("artificer-ui").getCanonicalPath()); resources.setInitParameter("dirAllowed", "true"); resources.setInitParameter("pathInfoOnly", "false"); String[] fileTypes = new String[] { "html", "js", "css", "png", "gif" }; for (String fileType : fileTypes) { artificerUI.addServlet(resources, "*." + fileType); } // Jetty will 404 http://localhost:8080/artificer-ui, since a welcome file doesn't physically exist. Instead, // setup a servlet on that root context and have it forward to /artificer-ui/index.html. artificerUI.addServlet(new ServletHolder(RootContextServlet.class), "/"); /* ************* * S-RAMP server * ************* */ ServletContextHandler artificerServer = new ServletContextHandler(ServletContextHandler.SESSIONS); artificerServer.setSecurityHandler(createSecurityHandler(false)); artificerServer.setContextPath("/artificer-server"); artificerServer.addEventListener(new ArtificerLifeCycle()); ServletHolder resteasyServerServlet = new ServletHolder(new HttpServletDispatcher()); resteasyServerServlet.setInitParameter("javax.ws.rs.Application", ArtificerApplication.class.getName()); artificerServer.addServlet(resteasyServerServlet, "/s-ramp/*"); artificerServer.addServlet(resteasyServerServlet, "/artificer/*"); //maven repository servlet: ServletHolder mvnServlet = new ServletHolder(new MavenFacadeServlet()); artificerServer.addServlet(mvnServlet, "/maven/repository/*"); artificerServer.addServlet(mvnServlet, "/maven/repository"); // TODO enable JSP support to test the repository listing artificerServer.addFilter(BasicAuthFilter.class, "/s-ramp/*", EnumSet.of(DispatcherType.REQUEST)) .setInitParameter("allowedIssuers", "/artificer-ui,/dtgov,/dtgov-ui"); artificerServer.addFilter(BasicAuthFilter.class, "/artificer/*", EnumSet.of(DispatcherType.REQUEST)) .setInitParameter("allowedIssuers", "/artificer-ui,/dtgov,/dtgov-ui"); artificerServer .addFilter(MavenRepositoryAuthFilter.class, "/maven/repository/*", EnumSet.of(DispatcherType.REQUEST)) .setInitParameter("allowedIssuers", "/artificer-ui,/dtgov,/dtgov-ui"); artificerServer.addFilter(org.artificer.server.filters.LocaleFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); artificerServer.addFilter(ServletCredentialsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)); // Add to handlers handlers.addHandler(artificerUI); handlers.addHandler(artificerServer); }
From source file:org.cryptomator.frontend.webdav.servlet.WebDavServletModule.java
@PerServlet @Provides//from w w w . j a v a 2s . co m public ServletContextHandler provideServletContext(WebDavServlet servlet) { final ServletContextHandler servletContext = new ServletContextHandler(null, contextPath, ServletContextHandler.SESSIONS); final ServletHolder servletHolder = new ServletHolder(contextPath, servlet); servletContext.addServlet(servletHolder, WILDCARD); servletContext.addFilter(LoggingFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST)); servletContext.addFilter(UnicodeResourcePathNormalizationFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST)); servletContext.addFilter(PostRequestBlockingFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST)); servletContext.addFilter(MkcolComplianceFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST)); servletContext.addFilter(AcceptRangeFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST)); servletContext.addFilter(MacChunkedPutCompatibilityFilter.class, WILDCARD, EnumSet.of(DispatcherType.REQUEST)); return servletContext; }