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:org.mayocat.application.AbstractService.java
private void registerServletFilters(Environment environment) throws ComponentLookupException { Map<String, ServletFilter> servletFilters = componentManager.getInstanceMap(ServletFilter.class); for (Map.Entry<String, ServletFilter> filter : servletFilters.entrySet()) { if (!Filter.class.isAssignableFrom(filter.getValue().getClass())) { LOGGER.warn("Ignoring servlet filter of class {} which does not implement Filter"); } else {//from w w w.ja v a 2s . c om environment.servlets() .addFilter(filter.getValue().getClass().getSimpleName(), (Filter) filter.getValue()) .addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, filter.getValue().urlPattern()); } } }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerIdpServlet(ServletContext servletContext) { String serviceProvidersUrls = AppContext.getProperty(IDP_SERVICE_PROVIDERS_URLS); if (StringUtils.isEmpty(serviceProvidersUrls)) { log.debug("No service providers were found. IDP Servlet will not be started"); return;//w w w . j a v a 2s. c o m } CubaIdpServlet idpServlet = new SingleAppIdpServlet(dependencyJars); try { idpServlet.init(new CubaServletConfig("idp", servletContext)); } catch (ServletException e) { throw new RuntimeException("An error occurred while initializing idp servlet", e); } ServletRegistration.Dynamic idpServletRegistration = servletContext.addServlet("idp", idpServlet); idpServletRegistration.setLoadOnStartup(4); idpServletRegistration.addMapping("/idp/*"); DelegatingFilterProxy idpSpringSecurityFilterChain = new DelegatingFilterProxy(); idpSpringSecurityFilterChain .setContextAttribute("org.springframework.web.servlet.FrameworkServlet.CONTEXT.idp"); idpSpringSecurityFilterChain.setTargetBeanName("springSecurityFilterChain"); FilterRegistration.Dynamic idpSpringSecurityFilterChainReg = servletContext .addFilter("idpSpringSecurityFilterChain", idpSpringSecurityFilterChain); idpSpringSecurityFilterChainReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/idp/*"); }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerCubaHttpFilter(ServletContext servletContext) { CubaHttpFilter cubaHttpFilter = new CubaHttpFilter(); FilterRegistration.Dynamic cubaHttpFilterReg = servletContext.addFilter("CubaHttpFilter", cubaHttpFilter); cubaHttpFilterReg.setAsyncSupported(true); cubaHttpFilterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), true, "/*"); }
From source file:io.confluent.rest.Application.java
/** * Configure and create the server.//from ww w. j av a 2s .c om */ public Server createServer() throws RestConfigException { // The configuration for the JAX-RS REST service ResourceConfig resourceConfig = new ResourceConfig(); Map<String, String> metricTags = getMetricsTags(); configureBaseApplication(resourceConfig, metricTags); setupResources(resourceConfig, getConfiguration()); // Configure the servlet container ServletContainer servletContainer = new ServletContainer(resourceConfig); ServletHolder servletHolder = new ServletHolder(servletContainer); server = new Server() { @Override protected void doStop() throws Exception { super.doStop(); Application.this.metrics.close(); Application.this.onShutdown(); Application.this.shutdownLatch.countDown(); } }; MetricsListener metricsListener = new MetricsListener(metrics, "jetty", metricTags); List<URI> listeners = parseListeners(config.getList(RestConfig.LISTENERS_CONFIG), config.getInt(RestConfig.PORT_CONFIG)); for (URI listener : listeners) { log.info("Adding listener: " + listener.toString()); NetworkTrafficServerConnector connector; if (listener.getScheme().equals("http")) { connector = new NetworkTrafficServerConnector(server); } else { SslContextFactory sslContextFactory = new SslContextFactory(); // IMPORTANT: the key's CN, stored in the keystore, must match the FQDN. This is a Jetty requirement. // TODO: investigate this further. Would be better to use SubjectAltNames. if (!config.getString(RestConfig.SSL_KEYSTORE_LOCATION_CONFIG).isEmpty()) { sslContextFactory.setKeyStorePath(config.getString(RestConfig.SSL_KEYSTORE_LOCATION_CONFIG)); sslContextFactory .setKeyStorePassword(config.getString(RestConfig.SSL_KEYSTORE_PASSWORD_CONFIG)); sslContextFactory.setKeyManagerPassword(config.getString(RestConfig.SSL_KEY_PASSWORD_CONFIG)); sslContextFactory.setKeyStoreType(config.getString(RestConfig.SSL_KEYSTORE_TYPE_CONFIG)); if (!config.getString(RestConfig.SSL_KEYMANAGER_ALGORITHM_CONFIG).isEmpty()) { sslContextFactory.setSslKeyManagerFactoryAlgorithm( config.getString(RestConfig.SSL_KEYMANAGER_ALGORITHM_CONFIG)); } } sslContextFactory.setNeedClientAuth(config.getBoolean(RestConfig.SSL_CLIENT_AUTH_CONFIG)); List<String> enabledProtocols = config.getList(RestConfig.SSL_ENABLED_PROTOCOLS_CONFIG); if (!enabledProtocols.isEmpty()) { sslContextFactory.setIncludeProtocols((String[]) enabledProtocols.toArray()); } List<String> cipherSuites = config.getList(RestConfig.SSL_CIPHER_SUITES_CONFIG); if (!cipherSuites.isEmpty()) { sslContextFactory.setIncludeCipherSuites((String[]) cipherSuites.toArray()); } if (!config.getString(RestConfig.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG).isEmpty()) { sslContextFactory.setEndpointIdentificationAlgorithm( config.getString(RestConfig.SSL_ENDPOINT_IDENTIFICATION_ALGORITHM_CONFIG)); } if (!config.getString(RestConfig.SSL_TRUSTSTORE_LOCATION_CONFIG).isEmpty()) { sslContextFactory .setTrustStorePath(config.getString(RestConfig.SSL_TRUSTSTORE_LOCATION_CONFIG)); sslContextFactory .setTrustStorePassword(config.getString(RestConfig.SSL_TRUSTSTORE_PASSWORD_CONFIG)); sslContextFactory.setTrustStoreType(config.getString(RestConfig.SSL_TRUSTSTORE_TYPE_CONFIG)); if (!config.getString(RestConfig.SSL_TRUSTMANAGER_ALGORITHM_CONFIG).isEmpty()) { sslContextFactory.setTrustManagerFactoryAlgorithm( config.getString(RestConfig.SSL_TRUSTMANAGER_ALGORITHM_CONFIG)); } } sslContextFactory.setProtocol(config.getString(RestConfig.SSL_PROTOCOL_CONFIG)); if (!config.getString(RestConfig.SSL_PROVIDER_CONFIG).isEmpty()) { sslContextFactory.setProtocol(config.getString(RestConfig.SSL_PROVIDER_CONFIG)); } connector = new NetworkTrafficServerConnector(server, sslContextFactory); } connector.addNetworkTrafficListener(metricsListener); connector.setPort(listener.getPort()); connector.setHost(listener.getHost()); server.addConnector(connector); } ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); context.addServlet(servletHolder, "/*"); String allowedOrigins = getConfiguration().getString(RestConfig.ACCESS_CONTROL_ALLOW_ORIGIN_CONFIG); if (allowedOrigins != null && !allowedOrigins.trim().isEmpty()) { FilterHolder filterHolder = new FilterHolder(CrossOriginFilter.class); filterHolder.setName("cross-origin"); filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, allowedOrigins); String allowedMethods = getConfiguration().getString(RestConfig.ACCESS_CONTROL_ALLOW_METHODS); if (allowedMethods != null && !allowedOrigins.trim().isEmpty()) { filterHolder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, allowedMethods); } context.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST)); } RequestLogHandler requestLogHandler = new RequestLogHandler(); Slf4jRequestLog requestLog = new Slf4jRequestLog(); requestLog.setLoggerName(config.getString(RestConfig.REQUEST_LOGGER_NAME_CONFIG)); requestLog.setLogLatency(true); requestLogHandler.setRequestLog(requestLog); HandlerCollection handlers = new HandlerCollection(); handlers.setHandlers(new Handler[] { context, new DefaultHandler(), requestLogHandler }); /* Needed for graceful shutdown as per `setStopTimeout` documentation */ StatisticsHandler statsHandler = new StatisticsHandler(); statsHandler.setHandler(handlers); server.setHandler(statsHandler); int gracefulShutdownMs = getConfiguration().getInt(RestConfig.SHUTDOWN_GRACEFUL_MS_CONFIG); if (gracefulShutdownMs > 0) { server.setStopTimeout(gracefulShutdownMs); } server.setStopAtShutdown(true); return server; }
From source file:com.haulmont.cuba.web.sys.singleapp.SingleAppWebContextLoader.java
protected void registerClassLoaderFilter(ServletContext servletContext) { FilterRegistration.Dynamic filterReg = servletContext.addFilter("WebSingleWarHttpFilter", new SetClassLoaderFilter()); filterReg.setAsyncSupported(true);/*from w ww . ja va 2 s . c om*/ filterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/*"); filterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/dispatch/*"); filterReg.addMappingForUrlPatterns(EnumSet.of(DispatcherType.REQUEST), false, "/rest/*"); }
From source file:org.tdmx.server.runtime.ServerContainer.java
public void runUntilStopped() { // Create a basic jetty server object without declaring the port. Since we are configuring connectors // directly we'll be setting ports on those connectors. Server server = new Server(); TrustingSslContextFactory sslExt = new TrustingSslContextFactory(); // we trust all client certs, with security in servlet "filters" // sslContextFactory.setCertAlias("server"); sslExt.setRenegotiationAllowed(isRenegotiationAllowed()); // we don't NEED client auth if we want to co-host a Restfull API on this server. sslExt.setWantClientAuth(true);//from w ww . j a v a 2 s. c o m sslExt.setIncludeCipherSuites(getHttpsCiphers()); sslExt.setIncludeProtocols(getHttpsProtocols()); sslExt.setKeyStoreType("jks"); sslExt.setKeyStorePath(getKeyStoreFile()); sslExt.setKeyStorePassword(getKeyStorePassword()); // TODO check if needed // sslContextFactory.setKeyManagerPassword("changeme"); // HTTPS Configuration // A new HttpConfiguration object is needed for the next connector and you can pass the old one as an // argument to effectively clone the contents. On this HttpConfiguration object we add a // SecureRequestCustomizer which is how a new connector is able to resolve the https connection before // handing control over to the Jetty Server. HttpConfiguration httpsConfigExt = new HttpConfiguration(); httpsConfigExt.setSecureScheme(HTTPS); httpsConfigExt.setSecurePort(getHttpsPort()); httpsConfigExt.setOutputBufferSize(32768); httpsConfigExt.addCustomizer(new SecureRequestCustomizer()); // HTTPS connector // We create a second ServerConnector, passing in the http configuration we just made along with the // previously created ssl context factory. Next we set the port and a longer idle timeout. ServerConnector httpsExt = new ServerConnector(server, new SslConnectionFactory(sslExt, HTTP_1_1), new HttpConnectionFactory(httpsConfigExt)); httpsExt.setPort(getHttpsPort()); httpsExt.setHost(getServerAddress()); httpsExt.setIdleTimeout(getConnectionIdleTimeoutSec() * MILLIS_IN_ONE_SECOND); TrustingSslContextFactory sslInt = new TrustingSslContextFactory(); // we trust all client certs, with security in servlet "filters" // sslContextFactory.setCertAlias("server"); sslInt.setRenegotiationAllowed(isRenegotiationAllowed()); // we don't want client auth on internal apis sslInt.setWantClientAuth(false); sslInt.setIncludeCipherSuites(getHttpsCiphers()); sslInt.setIncludeProtocols(getHttpsProtocols()); sslInt.setKeyStoreType("jks"); sslInt.setKeyStorePath(getKeyStoreFile()); sslInt.setKeyStorePassword(getKeyStorePassword()); // HTTPS Configuration // A new HttpConfiguration object is needed for the next connector and you can pass the old one as an // argument to effectively clone the contents. On this HttpConfiguration object we add a // SecureRequestCustomizer which is how a new connector is able to resolve the https connection before // handing control over to the Jetty Server. HttpConfiguration httpsConfigInt = new HttpConfiguration(); httpsConfigInt.setSecureScheme(HTTPS); httpsConfigInt.setSecurePort(getHttpsPort() + 1); httpsConfigInt.setOutputBufferSize(32768); httpsConfigInt.addCustomizer(new SecureRequestCustomizer()); // HTTPS connector ServerConnector httpsInt = new ServerConnector(server, new SslConnectionFactory(sslInt, HTTP_1_1), new HttpConnectionFactory(httpsConfigInt)); httpsInt.setPort(getHttpsPort() + 1); httpsInt.setHost(getServerAddress()); httpsInt.setIdleTimeout(getConnectionIdleTimeoutSec() * MILLIS_IN_ONE_SECOND); // Here you see the server having multiple connectors registered with it, now requests can flow into the server // from both http and https urls to their respective ports and be processed accordingly by jetty. A simple // handler is also registered with the server so the example has something to pass requests off to. // Set the connectors server.setConnectors(new Connector[] { httpsExt, httpsInt }); // The following section adds some handlers, deployers and webapp providers. // See: http://www.eclipse.org/jetty/documentation/current/advanced-embedding.html for details. // Setup handlers HandlerCollection handlers = new HandlerCollection(); ContextHandlerCollection contexts = new ContextHandlerCollection(); RequestLogHandler requestLogHandler = new RequestLogHandler(); HSTSHandler hstsHandler = new HSTSHandler(); NotFoundHandler notfoundHandler = new NotFoundHandler(); handlers.setHandlers(new Handler[] { hstsHandler, contexts, requestLogHandler, notfoundHandler }); StatisticsHandler stats = new StatisticsHandler(); stats.setHandler(handlers); server.setHandler(stats); NCSARequestLog requestLog = new AsyncNCSARequestLog(); requestLog.setFilename("jetty-yyyy_mm_dd.log"); requestLog.setExtended(true); requestLog.setRetainDays(7); requestLogHandler.setRequestLog(requestLog); ServletContextHandler wsContext = new ServletContextHandler( ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS); wsContext.setContextPath("/api"); // Setup Spring context wsContext.addEventListener(new org.springframework.web.context.ContextLoaderListener()); wsContext.setInitParameter("parentContextKey", "applicationContext"); wsContext.setInitParameter("locatorFactorySelector", "classpath*:beanRefContext.xml"); wsContext.setInitParameter("contextConfigLocation", "classpath:/ws-context.xml"); // Add filters FilterHolder sf = new FilterHolder(); sf.setFilter(new SessionProhibitionFilter()); wsContext.addFilter(sf, "/*", EnumSet.allOf(DispatcherType.class)); FilterHolder cf = new FilterHolder(); cf.setFilter(new RequireClientCertificateFilter()); wsContext.addFilter(cf, "/*", EnumSet.allOf(DispatcherType.class)); FilterHolder fh = new FilterHolder(); fh.setFilter(getAgentAuthorizationFilter()); wsContext.addFilter(fh, "/v1.0/sp/mds/*", EnumSet.of(DispatcherType.REQUEST)); wsContext.addFilter(fh, "/v1.0/sp/mos/*", EnumSet.of(DispatcherType.REQUEST)); wsContext.addFilter(fh, "/v1.0/sp/zas/*", EnumSet.of(DispatcherType.REQUEST)); // the MRS endpoint is not filtered by any authorization filter because // each ServiceProvider is automatically "authorized" but only to operate // sending data which is signed to be relevant to that service provider, so service // layer checking takes place. // Add servlets ServletHolder sh = new ServletHolder(CXFServlet.class); sh.setInitOrder(1); wsContext.addServlet(sh, "/*"); ServletContextHandler rsContext = new ServletContextHandler( ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS); rsContext.setContextPath("/rs"); // Setup Spring context rsContext.addEventListener(new org.springframework.web.context.ContextLoaderListener()); rsContext.setInitParameter("parentContextKey", "applicationContext"); rsContext.setInitParameter("locatorFactorySelector", "classpath*:beanRefContext.xml"); rsContext.setInitParameter("contextConfigLocation", "classpath:/rs-context.xml"); // Add filters /* * FilterHolder rsfh = new FilterHolder(); rsfh.setFilter(getAgentAuthorizationFilter()); * rsContext.addFilter(rsfh, "/sas/*", EnumSet.of(DispatcherType.REQUEST)); */ // Add servlets ServletHolder rsSh = new ServletHolder(CXFServlet.class); rsSh.setInitOrder(1); rsContext.addServlet(rsSh, "/*"); contexts.addHandler(wsContext); contexts.addHandler(rsContext); try { // start jobs actionOnManageables(true); // Start the server server.start(); Thread monitor = new MonitorThread(server, getStopPort(), getStopCommand(), getStopAddress()); monitor.start(); // Wait for the server to be stopped by the MonitorThread. server.join(); } catch (InterruptedException ie) { log.warn("Container running thread interrupted.", ie); } catch (Exception e) { log.error("Starting failed.", e); } // Exiting here will terminate the application. }
From source file:com.mirth.connect.server.MirthWebServer.java
public MirthWebServer(PropertiesConfiguration mirthProperties) throws Exception { // this disables a "form too large" error for occuring by setting // form size to infinite System.setProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "0"); String baseAPI = "/api"; boolean apiAllowHTTP = Boolean.parseBoolean(mirthProperties.getString("server.api.allowhttp", "false")); // add HTTP listener connector = new ServerConnector(this); connector.setName(CONNECTOR);/* w w w .j a v a 2 s . com*/ connector.setHost(mirthProperties.getString("http.host", "0.0.0.0")); connector.setPort(mirthProperties.getInt("http.port")); // add HTTPS listener sslConnector = createSSLConnector(CONNECTOR_SSL, mirthProperties); handlers = new HandlerList(); String contextPath = mirthProperties.getString("http.contextpath", ""); // Add a starting slash if one does not exist if (!contextPath.startsWith("/")) { contextPath = "/" + contextPath; } // Remove a trailing slash if one exists if (contextPath.endsWith("/")) { contextPath = contextPath.substring(0, contextPath.length() - 1); } // find the client-lib path String clientLibPath = null; if (ClassPathResource.getResourceURI("client-lib") != null) { clientLibPath = ClassPathResource.getResourceURI("client-lib").getPath() + File.separator; } else { clientLibPath = ControllerFactory.getFactory().createConfigurationController().getBaseDir() + File.separator + "client-lib" + File.separator; } // Create the lib context ContextHandler libContextHandler = new ContextHandler(); libContextHandler.setContextPath(contextPath + "/webstart/client-lib"); libContextHandler.setResourceBase(clientLibPath); libContextHandler.setHandler(new ResourceHandler()); handlers.addHandler(libContextHandler); // Create the extensions context ContextHandler extensionsContextHandler = new ContextHandler(); extensionsContextHandler.setContextPath(contextPath + "/webstart/extensions/libs"); String extensionsPath = new File(ExtensionController.getExtensionsPath()).getPath(); extensionsContextHandler.setResourceBase(extensionsPath); extensionsContextHandler.setHandler(new ResourceHandler()); handlers.addHandler(extensionsContextHandler); // Create the public_html context ContextHandler publicContextHandler = new ContextHandler(); publicContextHandler.setContextPath(contextPath); String publicPath = ControllerFactory.getFactory().createConfigurationController().getBaseDir() + File.separator + "public_html"; publicContextHandler.setResourceBase(publicPath); publicContextHandler.setHandler(new ResourceHandler()); handlers.addHandler(publicContextHandler); // Create the javadocs context ContextHandler javadocsContextHandler = new ContextHandler(); javadocsContextHandler.setContextPath(contextPath + "/javadocs"); String javadocsPath = ControllerFactory.getFactory().createConfigurationController().getBaseDir() + File.separator + "docs" + File.separator + "javadocs"; javadocsContextHandler.setResourceBase(javadocsPath); ResourceHandler javadocsResourceHandler = new ResourceHandler(); javadocsResourceHandler.setDirectoriesListed(true); javadocsContextHandler.setHandler(javadocsResourceHandler); handlers.addHandler(javadocsContextHandler); // Load all web apps dynamically webapps = new ArrayList<WebAppContext>(); FileFilter filter = new FileFilter() { @Override public boolean accept(File file) { return file.getName().endsWith(".war"); } }; /* * If in an IDE, webapps will be on the classpath as a resource. If that's the case, use * that directory. Otherwise, use the mirth home directory and append webapps. */ String webappsDir = null; if (ClassPathResource.getResourceURI("webapps") != null) { webappsDir = ClassPathResource.getResourceURI("webapps").getPath() + File.separator; } else { webappsDir = ControllerFactory.getFactory().createConfigurationController().getBaseDir() + File.separator + "webapps" + File.separator; } File[] listOfFiles = new File(webappsDir).listFiles(filter); if (listOfFiles != null) { // Since webapps may use JSP and JSTL, we need to enable the AnnotationConfiguration in order to correctly set up the JSP container. Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(this); classlist.addBefore("org.eclipse.jetty.webapp.JettyWebXmlConfiguration", "org.eclipse.jetty.annotations.AnnotationConfiguration"); for (File file : listOfFiles) { logger.debug("webApp File Path: " + file.getAbsolutePath()); WebAppContext webapp = new WebAppContext(); webapp.setContextPath(contextPath + "/" + file.getName().substring(0, file.getName().length() - 4)); /* * Set the ContainerIncludeJarPattern so that Jetty examines these JARs for TLDs, * web fragments, etc. If you omit the jar that contains the JSTL TLDs, the JSP * engine will scan for them instead. */ webapp.setAttribute("org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", ".*/[^/]*(javax\\.servlet-api|taglibs)[^/]*\\.jar$"); logger.debug("webApp Context Path: " + webapp.getContextPath()); webapp.setWar(file.getPath()); handlers.addHandler(webapp); webapps.add(webapp); } } // Add Jersey API / swagger servlets for each specific version Version version = Version.getApiEarliest(); while (version != null) { addApiServlets(handlers, contextPath, baseAPI, apiAllowHTTP, version); version = version.getNextVersion(); } // Add servlets for the main (default) API endpoint addApiServlets(handlers, contextPath, baseAPI, apiAllowHTTP, null); // Create the webstart servlet handler ServletContextHandler servletContextHandler = new ServletContextHandler(); servletContextHandler.setContextPath(contextPath); servletContextHandler.addFilter(new FilterHolder(new MethodFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)); servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart.jnlp"); servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart"); servletContextHandler.addServlet(new ServletHolder(new WebStartServlet()), "/webstart/extensions/*"); handlers.addHandler(servletContextHandler); // add the default handler for misc requests (favicon, etc.) DefaultHandler defaultHandler = new DefaultHandler(); defaultHandler.setServeIcon(false); // don't serve the Jetty favicon handlers.addHandler(defaultHandler); setHandler(handlers); setConnectors(new Connector[] { connector, sslConnector }); }
From source file:com.github.tomakehurst.wiremock.jetty9.JettyHttpServer.java
@SuppressWarnings({ "rawtypes", "unchecked" }) private ServletContextHandler addMockServiceContext(StubRequestHandler stubRequestHandler, FileSource fileSource, Notifier notifier) { ServletContextHandler mockServiceContext = new ServletContextHandler(jettyServer, "/"); mockServiceContext.setInitParameter("org.eclipse.jetty.servlet.Default.maxCacheSize", "0"); mockServiceContext.setInitParameter("org.eclipse.jetty.servlet.Default.resourceBase", fileSource.getPath()); mockServiceContext.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false"); mockServiceContext.addServlet(DefaultServlet.class, FILES_URL_MATCH); mockServiceContext.setAttribute(JettyFaultInjectorFactory.class.getName(), new JettyFaultInjectorFactory()); mockServiceContext.setAttribute(StubRequestHandler.class.getName(), stubRequestHandler); mockServiceContext.setAttribute(Notifier.KEY, notifier); ServletHolder servletHolder = mockServiceContext.addServlet(WireMockHandlerDispatchingServlet.class, "/"); servletHolder.setInitParameter(RequestHandler.HANDLER_CLASS_KEY, StubRequestHandler.class.getName()); servletHolder.setInitParameter(FaultInjectorFactory.INJECTOR_CLASS_KEY, JettyFaultInjectorFactory.class.getName()); servletHolder.setInitParameter(WireMockHandlerDispatchingServlet.SHOULD_FORWARD_TO_FILES_CONTEXT, "true"); MimeTypes mimeTypes = new MimeTypes(); mimeTypes.addMimeMapping("json", "application/json"); mimeTypes.addMimeMapping("html", "text/html"); mimeTypes.addMimeMapping("xml", "application/xml"); mimeTypes.addMimeMapping("txt", "text/plain"); mockServiceContext.setMimeTypes(mimeTypes); mockServiceContext.setWelcomeFiles(new String[] { "index.json", "index.html", "index.xml", "index.txt" }); mockServiceContext.addFilter(GzipFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST, DispatcherType.FORWARD)); mockServiceContext.addFilter(ContentTypeSettingFilter.class, FILES_URL_MATCH, EnumSet.of(DispatcherType.FORWARD)); mockServiceContext.addFilter(TrailingSlashFilter.class, FILES_URL_MATCH, EnumSet.allOf(DispatcherType.class)); return mockServiceContext; }
From source file:org.italiangrid.storm.webdav.server.WebDAVServer.java
private Handler configureSAHandler() { FilterHolder springSecurityFilter = new FilterHolder( new DelegatingFilterProxy("springSecurityFilterChain")); FilterHolder miltonFilter = new FilterHolder(new MiltonFilter( applicationContext.getBean(FilesystemAccess.class), extendedAttrsHelper, pathResolver)); FilterHolder securityFilter = new FilterHolder(new LogRequestFilter()); ServletHolder metricsServlet = new ServletHolder(MetricsServlet.class); ServletHolder pingServlet = new ServletHolder(PingServlet.class); ServletHolder threadDumpServlet = new ServletHolder(ThreadDumpServlet.class); PathResolver resolver = new DefaultPathResolver(saConfiguration); ServletHolder servlet = new ServletHolder(new StoRMServlet(resolver)); ServletHolder index = new ServletHolder(new SAIndexServlet(saConfiguration, templateEngine)); WebAppContext ch = new WebAppContext(); ch.setContextPath("/"); ch.setWar("/"); ch.setThrowUnavailableOnStartupException(true); ch.setCompactPath(true);/*from w w w . j av a2s . c o m*/ ch.setInitParameter("contextClass", AnnotationConfigWebApplicationContext.class.getName()); ch.setInitParameter("contextConfigLocation", SecurityConfig.class.getName()); ch.setInitParameter("org.eclipse.jetty.servlet.Default.acceptRanges", "true"); ch.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "true"); ch.setInitParameter("org.eclipse.jetty.servlet.Default.aliases", "false"); ch.setInitParameter("org.eclipse.jetty.servlet.Default.gzip", "false"); EnumSet<DispatcherType> dispatchFlags = EnumSet.of(DispatcherType.REQUEST); ch.addServlet(index, ""); ch.addFilter(springSecurityFilter, "/*", dispatchFlags); ch.addFilter(securityFilter, "/*", dispatchFlags); ch.addFilter(miltonFilter, "/*", dispatchFlags); ch.addServlet(metricsServlet, "/status/metrics"); ch.addServlet(pingServlet, "/status/ping"); ch.addServlet(threadDumpServlet, "/status/threads"); ch.addServlet(servlet, "/*"); ServletContextListener springContextListener = new MyLoaderListener(applicationContext); ch.addEventListener(new MetricsContextListener(metricRegistry)); ch.addEventListener(springContextListener); return ch; }