Java Code Examples for org.eclipse.jetty.servlet.ServletHolder#setInitParameter()

The following examples show how to use org.eclipse.jetty.servlet.ServletHolder#setInitParameter() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TwootrServer.java    From Real-World-Software-Development with Apache License 2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        var websocketAddress = new InetSocketAddress("localhost", WEBSOCKET_PORT);
        var twootrServer = new TwootrServer(websocketAddress);
        twootrServer.start();

        System.setProperty("org.eclipse.jetty.LEVEL", "INFO");

        var context = new ServletContextHandler(ServletContextHandler.SESSIONS);
        context.setResourceBase(System.getProperty("user.dir") + "/src/main/webapp");
        context.setContextPath("/");

        ServletHolder staticContentServlet = new ServletHolder(
            "staticContentServlet", DefaultServlet.class);
        staticContentServlet.setInitParameter("dirAllowed", "true");
        context.addServlet(staticContentServlet, "/");

        var jettyServer = new Server(STATIC_PORT);
        jettyServer.setHandler(context);
        jettyServer.start();
        jettyServer.dumpStdErr();
        jettyServer.join();
    }
 
Example 2
Source File: Server.java    From cxf with Apache License 2.0 6 votes vote down vote up
protected Server() throws Exception {
    org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000);

    final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addServlet(servletHolder, "/*");
    servletHolder.setInitParameter("jaxrs.serviceClasses", Sample.class.getName());
    servletHolder.setInitParameter("jaxrs.features",
        Swagger2Feature.class.getName());
    servletHolder.setInitParameter("jaxrs.providers", StringUtils.join(
        new String[] {
            MultipartProvider.class.getName(),
            JacksonJsonProvider.class.getName(),
            ApiOriginFilter.class.getName()
        }, ",")
    );

    server.setHandler(context);
    server.start();
    server.join();
}
 
Example 3
Source File: ExplorerServer.java    From Explorer with Apache License 2.0 6 votes vote down vote up
/**
 * Swagger core handler - Needed for the RestFul api documentation
 *
 * @return ServletContextHandler of Swagger
 */
private static ServletContextHandler setupSwaggerContextHandler(int port) {
    // Configure Swagger-core
    final ServletHolder SwaggerServlet = new ServletHolder(
            new com.wordnik.swagger.jersey.config.JerseyJaxrsConfig());
    SwaggerServlet.setName("JerseyJaxrsConfig");
    SwaggerServlet.setInitParameter("api.version", "1.0.0");
    SwaggerServlet.setInitParameter("swagger.api.basepath", "http://localhost:" + port + "/api");
    SwaggerServlet.setInitOrder(2);

    // Setup the handler
    final ServletContextHandler handler = new ServletContextHandler();
    handler.setSessionHandler(new SessionHandler());
    handler.addServlet(SwaggerServlet, "/api-docs/*");
    return handler;
}
 
Example 4
Source File: EmissaryServer.java    From emissary with Apache License 2.0 6 votes vote down vote up
private ContextHandler buildStaticHandler() {
    // Add pathspec for static assets
    ServletHolder homeHolder = new ServletHolder("static-holder", DefaultServlet.class);
    // If no filesytem path was passed in, load assets from the classpath
    if (null == cmd.getStaticDir()) {
        LOG.debug("Loading static resources from the classpath");
        homeHolder.setInitParameter("resourceBase", this.getClass().getClassLoader().getResource("public").toExternalForm());
    } else {
        // use --staticDir ${project_loc}/src/main/resources/public as command args
        LOG.debug("Loading static resources from staticPath: {}", cmd.getStaticDir());
        homeHolder.setInitParameter("resourceBase", cmd.getStaticDir().toAbsolutePath().toString());
    }
    homeHolder.setInitParameter("dirAllowed", "true");
    homeHolder.setInitParameter("pathInfoOnly", "true");
    // homeHolder.setInitOrder(0);

    ServletContextHandler homeContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    homeContextHandler.addServlet(homeHolder, "/*");

    return homeContextHandler;
}
 
Example 5
Source File: SchemaTest.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws Exception {
  File tmpSolrHome = createTempDir().toFile();
  FileUtils.copyDirectory(new File(getFile("solrj/solr/collection1").getParent()), tmpSolrHome.getAbsoluteFile());

  final SortedMap<ServletHolder, String> extraServlets = new TreeMap<>();
  final ServletHolder solrRestApi = new ServletHolder("SolrSchemaRestApi", ServerServlet.class);
  solrRestApi.setInitParameter("org.restlet.application", "org.apache.solr.rest.SolrSchemaRestApi");
  extraServlets.put(solrRestApi, "/schema/*");  // '/schema/*' matches '/schema', '/schema/', and '/schema/whatever...'

  System.setProperty("managed.schema.mutable", "true");
  System.setProperty("enable.update.log", "false");

  createJettyAndHarness(tmpSolrHome.getAbsolutePath(), "solrconfig-managed-schema.xml", "schema.xml",
      "/solr", true, extraServlets);
}
 
Example 6
Source File: RestHelper.java    From kafka-connect-http with Apache License 2.0 6 votes vote down vote up
public void start() throws Exception {
    //flushCapturedRequests();
    server = new Server(0);
    ServerConnector connector = new ServerConnector(server);
    ServletContextHandler handler = new ServletContextHandler();
    ServletHolder testServ = new ServletHolder("test", RestHelper.class);
    testServ.setInitParameter("resourceBase",System.getProperty("user.dir"));
    testServ.setInitParameter("dirAllowed","true");
    handler.addServlet(testServ,"/test");
    handler.addServlet(testServ,"/someTopic");
    handler.addServlet(testServ,"/someKey");



    server.setHandler(handler);
    server.setConnectors(new Connector[]{connector});

    server.start();

    port = server.getURI().getPort();

}
 
Example 7
Source File: Server.java    From cxf with Apache License 2.0 5 votes vote down vote up
protected Server() throws Exception {
    org.eclipse.jetty.server.Server server = new org.eclipse.jetty.server.Server(9000);

    // Configuring all static web resource
    final ServletHolder staticHolder = new ServletHolder(new DefaultServlet());
    // Register and map the dispatcher servlet
    final ServletHolder servletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
    final ServletContextHandler context = new ServletContextHandler();
    context.setContextPath("/");
    context.addServlet(staticHolder, "/static/*");
    context.addServlet(servletHolder, "/*");
    context.setResourceBase(getClass().getResource("/browser").toURI().toString());

    servletHolder.setInitParameter("redirects-list",
        "/ /index.html /js/fileinput.min.js /css/fileinput.min.css");
    servletHolder.setInitParameter("redirect-servlet-name", staticHolder.getName());
    servletHolder.setInitParameter("redirect-attributes", "javax.servlet.include.request_uri");
    servletHolder.setInitParameter("jaxrs.serviceClasses", Catalog.class.getName());
    servletHolder.setInitParameter("jaxrs.properties", StringUtils.join(
        new String[] {
            "search.query.parameter.name=$filter",
            SearchUtils.DATE_FORMAT_PROPERTY + "=yyyy/MM/dd"
        }, " ")
    );
    servletHolder.setInitParameter("jaxrs.providers", StringUtils.join(
        new String[] {
            MultipartProvider.class.getName(),
            SearchContextProvider.class.getName(),
            JsrJsonpProvider.class.getName(),
            CrossOriginResourceSharingFilter.class.getName()
        }, ",")
    );

    server.setHandler(context);
    server.start();
    server.join();
}
 
Example 8
Source File: UnauthedAdminProxyHandlerTest.java    From pulsar with Apache License 2.0 5 votes vote down vote up
@Override
@BeforeClass
protected void setup() throws Exception {
    // enable tls and auth&auth at broker

    Set<String> superUserRoles = new HashSet<>();
    superUserRoles.add("localhost");
    superUserRoles.add("superUser");
    conf.setSuperUserRoles(superUserRoles);
    conf.setClusterName(configClusterName);

    super.init();

    // start proxy service
    proxyConfig.setServicePort(Optional.of(0));
    proxyConfig.setWebServicePort(Optional.of(0));
    proxyConfig.setBrokerWebServiceURL(brokerUrl.toString());
    proxyConfig.setStatusFilePath(STATUS_FILE_PATH);
    proxyConfig.setZookeeperServers(DUMMY_VALUE);
    proxyConfig.setGlobalZookeeperServers(DUMMY_VALUE);

    webServer = new WebServer(proxyConfig, new AuthenticationService(
                                      PulsarConfigurationLoader.convertFrom(proxyConfig)));

    discoveryProvider = spy(new BrokerDiscoveryProvider(proxyConfig, mockZooKeeperClientFactory));
    adminProxyHandler = new AdminProxyWrapper(proxyConfig, discoveryProvider);
    ServletHolder servletHolder = new ServletHolder(adminProxyHandler);
    servletHolder.setInitParameter("preserveHost", "true");
    webServer.addServlet("/admin", servletHolder);
    webServer.addServlet("/lookup", servletHolder);

    webServer.addRestResources("/", VipStatus.class.getPackage().getName(),
            VipStatus.ATTRIBUTE_STATUS_FILE_PATH, proxyConfig.getStatusFilePath());

    // start web-service
    webServer.start();

}
 
Example 9
Source File: GatewayMicroService.java    From apiman with Apache License 2.0 5 votes vote down vote up
/**
 * Configure the web application(s).
 * @param handlers
 * @throws Exception
 */
protected void addModulesToJetty(ContextHandlerCollection handlers) throws Exception {
	/* *************
     * Gateway API
     * ************* */
    ServletContextHandler gatewayApiServer = new ServletContextHandler(ServletContextHandler.SESSIONS);
    addSecurityHandler(gatewayApiServer);
    gatewayApiServer.setContextPath("/api");
    gatewayApiServer.addEventListener(new ResteasyBootstrap());
    gatewayApiServer.addEventListener(new WarGatewayBootstrapper());
    gatewayApiServer.addFilter(HttpRequestThreadLocalFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    gatewayApiServer.addFilter(LocaleFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    gatewayApiServer.addFilter(ApimanCorsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    gatewayApiServer.addFilter(DisableCachingFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    addApiAuthFilter(gatewayApiServer);
    gatewayApiServer.addFilter(RootResourceFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    ServletHolder resteasyServlet = new ServletHolder(new HttpServletDispatcher());
    resteasyServlet.setInitParameter("javax.ws.rs.Application", GatewayMicroServiceApplication.class.getName());
    gatewayApiServer.addServlet(resteasyServlet, "/*");
    gatewayApiServer.setInitParameter("resteasy.servlet.mapping.prefix", "");

    handlers.addHandler(gatewayApiServer);


    /* *************
     * Gateway
     * ************* */
    ServletContextHandler gatewayServer = new ServletContextHandler(ServletContextHandler.SESSIONS);
    addSecurityHandler(gatewayServer);
    gatewayServer.setContextPath("/gateway");
    ServletHolder servlet = new ServletHolder(new WarGatewayServlet());
    gatewayServer.addServlet(servlet, "/*");

    handlers.addHandler(gatewayServer);
}
 
Example 10
Source File: VarOneServer.java    From varOne with MIT License 5 votes vote down vote up
private static ServletContextHandler setupResourcesContextHandler(
		VarOneConfiguration conf) {
	final ServletHolder cxfServletHolder = new ServletHolder(new CXFNonSpringJaxrsServlet());
    cxfServletHolder.setInitParameter("javax.ws.rs.Application", VarOneServer.class.getName());
    cxfServletHolder.setName("rest");
    cxfServletHolder.setForcedPath("rest");

    final ServletContextHandler cxfContext = new ServletContextHandler();
    cxfContext.setSessionHandler(new SessionHandler());
    cxfContext.setContextPath(conf.getServerContextPath());
    cxfContext.addServlet(cxfServletHolder, "/rest/*");

    return cxfContext;
}
 
Example 11
Source File: HttpServer2.java    From knox with Apache License 2.0 5 votes vote down vote up
/**
 * Add a Jersey resource package.
 * @param packageName The Java package name containing the Jersey resource.
 * @param pathSpec The path spec for the servlet
 * @param params properties and features for ResourceConfig
 */
public void addJerseyResourcePackage(final String packageName,
                                     final String pathSpec, Map<String, String> params) {
  LOG.info("addJerseyResourcePackage: packageName=" + packageName
               + ", pathSpec=" + pathSpec);
  final ServletHolder sh = new ServletHolder(ServletContainer.class);
  sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
      "com.sun.jersey.api.core.PackagesResourceConfig");
  sh.setInitParameter("com.sun.jersey.config.property.packages", packageName);
  for (Map.Entry<String, String> entry : params.entrySet()) {
    sh.setInitParameter(entry.getKey(), entry.getValue());
  }
  webAppContext.addServlet(sh, pathSpec);
}
 
Example 12
Source File: JettyLauncher.java    From logsniffer with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Create JSP Servlet (must be named "jsp")
 */
private ServletHolder jspServletHolder() {
	ServletHolder holderJsp = new ServletHolder("jsp", JettyJspServlet.class);
	holderJsp.setInitOrder(0);
	holderJsp.setInitParameter("logVerbosityLevel", "DEBUG");
	holderJsp.setInitParameter("fork", "false");
	holderJsp.setInitParameter("xpoweredBy", "false");
	holderJsp.setInitParameter("compilerTargetVM", "1.7");
	holderJsp.setInitParameter("compilerSourceVM", "1.7");
	holderJsp.setInitParameter("keepgenerated", "true");
	return holderJsp;
}
 
Example 13
Source File: ClientProxy.java    From OmniOcular with Apache License 2.0 5 votes vote down vote up
@Override
public void startHttpServer() {
    Thread t = new Thread(new Runnable() {
        @Override
        public void run() {
            Server server = new Server(23333);
            try {
                ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
                context.setContextPath("/");
                ServletHolder wsHolder = new ServletHolder("echo", new WebSocketServlet() {
                    @Override
                    public void configure(WebSocketServletFactory factory) {
                        factory.register(WebSocketHandler.class);
                    }
                });
                context.addServlet(wsHolder, "/w");

                URI uri = OmniOcular.class.getResource("/assets/omniocular/static/").toURI();
                context.setBaseResource(Resource.newResource(uri));
                context.setWelcomeFiles(new String[]{"index.html"});
                ServletHolder holderPwd = new ServletHolder("default", DefaultServlet.class);
                holderPwd.setInitParameter("cacheControl", "max-age=0,public");
                holderPwd.setInitParameter("useFileMappedBuffer", "false");
                context.addServlet(holderPwd, "/");

                server.setHandler(context);
                server.start();
                server.join();
            } catch (Exception e) {
                e.printStackTrace();
            }
        }
    });
    t.start();

}
 
Example 14
Source File: RestEasyHelper.java    From java-jaxrs with Apache License 2.0 5 votes vote down vote up
public static void initServletContext(ServletContextHandler context) {
    ServletHolder restEasyServlet = context.addServlet(
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.class, "/*");
    restEasyServlet.setInitOrder(0);

    restEasyServlet.setInitParameter(
            "javax.ws.rs.Application", InstrumentedRestApplication.class.getCanonicalName());
}
 
Example 15
Source File: HttpServer2.java    From hadoop-ozone with Apache License 2.0 5 votes vote down vote up
/**
 * Add a Jersey resource package.
 * @param packageName The Java package name containing the Jersey resource.
 * @param pathSpec The path spec for the servlet
 */
public void addJerseyResourcePackage(final String packageName,
    final String pathSpec) {
  LOG.info("addJerseyResourcePackage: packageName={}, pathSpec={}",
          packageName, pathSpec);
  final ServletHolder sh = new ServletHolder(ServletContainer.class);
  sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass",
      "com.sun.jersey.api.core.PackagesResourceConfig");
  sh.setInitParameter("com.sun.jersey.config.property.packages", packageName);
  webAppContext.addServlet(sh, pathSpec);
}
 
Example 16
Source File: SubmarineServer.java    From submarine with Apache License 2.0 5 votes vote down vote up
private static void setupNotebookServer(WebAppContext webapp,
    SubmarineConfiguration conf, ServiceLocator serviceLocator) {
  String maxTextMessageSize = conf.getWebsocketMaxTextMessageSize();
  final ServletHolder servletHolder =
      new ServletHolder(serviceLocator.getService(NotebookServer.class));
  servletHolder.setInitParameter("maxTextMessageSize", maxTextMessageSize);

  final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
  webapp.addServlet(servletHolder, "/ws/*");
}
 
Example 17
Source File: SuperUserAuthedAdminProxyHandlerTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
@Override
protected void setup() throws Exception {
    // enable tls and auth&auth at broker
    conf.setAuthenticationEnabled(true);
    conf.setAuthorizationEnabled(true);

    conf.setBrokerServicePortTls(Optional.of(0));
    conf.setWebServicePortTls(Optional.of(0));
    conf.setTlsTrustCertsFilePath(getTlsFile("ca.cert"));
    conf.setTlsCertificateFilePath(getTlsFile("broker.cert"));
    conf.setTlsKeyFilePath(getTlsFile("broker.key-pk8"));
    conf.setTlsAllowInsecureConnection(false);
    conf.setSuperUserRoles(ImmutableSet.of("admin", "superproxy"));
    conf.setProxyRoles(ImmutableSet.of("superproxy"));
    conf.setAuthenticationProviders(ImmutableSet.of(AuthenticationProviderTls.class.getName()));

    super.internalSetup();

    // start proxy service
    proxyConfig.setAuthenticationEnabled(true);
    proxyConfig.setAuthorizationEnabled(true);
    proxyConfig.setServicePort(Optional.of(0));
    proxyConfig.setServicePortTls(Optional.of(0));
    proxyConfig.setWebServicePort(Optional.of(0));
    proxyConfig.setWebServicePortTls(Optional.of(0));
    proxyConfig.setTlsEnabledWithBroker(true);

    // enable tls and auth&auth at proxy
    proxyConfig.setTlsCertificateFilePath(getTlsFile("broker.cert"));
    proxyConfig.setTlsKeyFilePath(getTlsFile("broker.key-pk8"));
    proxyConfig.setTlsTrustCertsFilePath(getTlsFile("ca.cert"));

    proxyConfig.setBrokerClientAuthenticationPlugin(AuthenticationTls.class.getName());
    proxyConfig.setBrokerClientAuthenticationParameters(
            String.format("tlsCertFile:%s,tlsKeyFile:%s",
                          getTlsFile("superproxy.cert"), getTlsFile("superproxy.key-pk8")));
    proxyConfig.setBrokerClientTrustCertsFilePath(getTlsFile("ca.cert"));
    proxyConfig.setAuthenticationProviders(ImmutableSet.of(AuthenticationProviderTls.class.getName()));

    webServer = new WebServer(proxyConfig, new AuthenticationService(
                                      PulsarConfigurationLoader.convertFrom(proxyConfig)));
    discoveryProvider = spy(new BrokerDiscoveryProvider(proxyConfig, mockZooKeeperClientFactory));
    LoadManagerReport report = new LoadReport(brokerUrl.toString(), brokerUrlTls.toString(), null, null);
    doReturn(report).when(discoveryProvider).nextBroker();

    ServletHolder servletHolder = new ServletHolder(new AdminProxyHandler(proxyConfig, discoveryProvider));
    servletHolder.setInitParameter("preserveHost", "true");
    webServer.addServlet("/admin", servletHolder);
    webServer.addServlet("/lookup", servletHolder);

    // start web-service
    webServer.start();
}
 
Example 18
Source File: AuthedAdminProxyHandlerTest.java    From pulsar with Apache License 2.0 4 votes vote down vote up
@BeforeMethod
@Override
protected void setup() throws Exception {
    // enable tls and auth&auth at broker
    conf.setAuthenticationEnabled(true);
    conf.setAuthorizationEnabled(true);
    conf.setBrokerServicePortTls(Optional.of(0));
    conf.setWebServicePortTls(Optional.of(0));
    conf.setTlsTrustCertsFilePath(getTlsFile("ca.cert"));
    conf.setTlsCertificateFilePath(getTlsFile("broker.cert"));
    conf.setTlsKeyFilePath(getTlsFile("broker.key-pk8"));
    conf.setTlsAllowInsecureConnection(false);
    conf.setSuperUserRoles(ImmutableSet.of("admin"));
    conf.setProxyRoles(ImmutableSet.of("proxy"));
    conf.setAuthenticationProviders(ImmutableSet.of(AuthenticationProviderTls.class.getName()));

    super.internalSetup();

    // start proxy service
    proxyConfig.setAuthenticationEnabled(true);
    proxyConfig.setAuthorizationEnabled(true);
    proxyConfig.setServicePort(Optional.of(0));
    proxyConfig.setServicePortTls(Optional.of(0));
    proxyConfig.setWebServicePort(Optional.of(0));
    proxyConfig.setWebServicePortTls(Optional.of(0));
    proxyConfig.setTlsEnabledWithBroker(true);

    // enable tls and auth&auth at proxy
    proxyConfig.setTlsCertificateFilePath(getTlsFile("broker.cert"));
    proxyConfig.setTlsKeyFilePath(getTlsFile("broker.key-pk8"));
    proxyConfig.setTlsTrustCertsFilePath(getTlsFile("ca.cert"));

    proxyConfig.setBrokerClientAuthenticationPlugin(AuthenticationTls.class.getName());
    proxyConfig.setBrokerClientAuthenticationParameters(
            String.format("tlsCertFile:%s,tlsKeyFile:%s",
                          getTlsFile("proxy.cert"), getTlsFile("proxy.key-pk8")));
    proxyConfig.setBrokerClientTrustCertsFilePath(getTlsFile("ca.cert"));
    proxyConfig.setAuthenticationProviders(ImmutableSet.of(AuthenticationProviderTls.class.getName()));

    webServer = new WebServer(proxyConfig, new AuthenticationService(
                                      PulsarConfigurationLoader.convertFrom(proxyConfig)));
    discoveryProvider = spy(new BrokerDiscoveryProvider(proxyConfig, mockZooKeeperClientFactory));
    LoadManagerReport report = new LoadReport(brokerUrl.toString(), brokerUrlTls.toString(), null, null);
    doReturn(report).when(discoveryProvider).nextBroker();

    ServletHolder servletHolder = new ServletHolder(new AdminProxyHandler(proxyConfig, discoveryProvider));
    servletHolder.setInitParameter("preserveHost", "true");
    webServer.addServlet("/admin", servletHolder);
    webServer.addServlet("/lookup", servletHolder);

    // start web-service
    webServer.start();
}
 
Example 19
Source File: JettyEmbeddedContainer.java    From gravitee-management-rest-api with Apache License 2.0 3 votes vote down vote up
protected ServletContextHandler configureAPI(String apiContextPath, String applicationName, Class<? extends GlobalAuthenticationConfigurerAdapter> securityConfigurationClass) {
    final ServletContextHandler childContext = new ServletContextHandler(server, apiContextPath, ServletContextHandler.SESSIONS);

    final ServletHolder servletHolder = new ServletHolder(ServletContainer.class);
    servletHolder.setInitParameter("javax.ws.rs.Application", applicationName);
    servletHolder.setInitOrder(0);
    childContext.addServlet(servletHolder, "/*");

    AnnotationConfigWebApplicationContext webApplicationContext = new AnnotationConfigWebApplicationContext();
    webApplicationContext.register(securityConfigurationClass);

    webApplicationContext.setEnvironment((ConfigurableEnvironment) applicationContext.getEnvironment());
    webApplicationContext.setParent(applicationContext);

    childContext.addEventListener(new ContextLoaderListener(webApplicationContext));

    // Spring Security filter
    childContext.addFilter(new FilterHolder(new DelegatingFilterProxy("springSecurityFilterChain")),"/*", EnumSet.allOf(DispatcherType.class));
    return childContext;


}
 
Example 20
Source File: ServerRpcProvider.java    From swellrt with Apache License 2.0 3 votes vote down vote up
/**
 * Add a transparent proxy to the servlet registry. The servlet will proxy to
 * the specified URL pattern. For example:
 * addTransparentProxy("/gadgets/*","http://gmodules:80/gadgets", "/gadgets")
 *
 * @param urlPattern
 *          the URL pattern for paths. Eg, '/foo', '/foo/*'.
 * @param proxyTo
 *          the URL to proxy to.
 * @param prefix
 *          the prefix that should be proxied.
 */
public void addTransparentProxy(String urlPattern, String proxyTo, String prefix) {
  Preconditions.checkNotNull(urlPattern);
  Preconditions.checkNotNull(proxyTo);
  Preconditions.checkNotNull(prefix);

  ServletHolder proxy = new ServletHolder(ProxyServlet.Transparent.class);
  proxy.setInitParameter("proxyTo", proxyTo);
  proxy.setInitParameter("prefix", prefix);
  servletRegistry.add(Pair.of(urlPattern, proxy));
}