Search in sources :

Example 81 with FilterHolder

use of org.eclipse.jetty.servlet.FilterHolder in project qi4j-sdk by Qi4j.

the class JettyConfigurationHelper method addFilters.

static void addFilters(ServletContextHandler root, Iterable<ServiceReference<Filter>> filters) {
    // Iterate the available filters and add them to the server
    for (ServiceReference<Filter> filter : filters) {
        FilterInfo filterInfo = filter.metaInfo(FilterInfo.class);
        String filterPath = filterInfo.getPath();
        Filter filterInstance = filter.get();
        FilterHolder holder = new FilterHolder(filterInstance);
        holder.setInitParameters(filterInfo.initParameters());
        root.addFilter(holder, filterPath, filterInfo.dispatchers());
    }
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Filter(javax.servlet.Filter)

Example 82 with FilterHolder

use of org.eclipse.jetty.servlet.FilterHolder in project platformlayer by platformlayer.

the class StandaloneXaasWebserver method start.

public boolean start() throws Exception {
    LogbackHook.attachToRootLogger();
    this.server = new Server();
    {
        SslContextFactory sslContextFactory = new SslContextFactory(SslContextFactory.DEFAULT_KEYSTORE_PATH);
        {
            CertificateAndKey certificateAndKey = encryptionStore.getCertificateAndKey("https");
            String secret = KeyStoreUtils.DEFAULT_KEYSTORE_SECRET;
            KeyStore keystore = KeyStoreUtils.createEmpty(secret);
            String alias = "https";
            KeyStoreUtils.put(keystore, alias, certificateAndKey, secret);
            sslContextFactory.setKeyStore(keystore);
            sslContextFactory.setKeyStorePassword(secret);
            sslContextFactory.setCertAlias(alias);
        }
        // TODO: Preconfigure a better SSLContext??
        SSLContext sslContext = SSLContext.getDefault();
        sslContextFactory.setIncludeCipherSuites(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledCipherSuites());
        sslContextFactory.setIncludeProtocols(SslPolicy.DEFAULT.getEngineConfig(sslContext).getEnabledProtocols());
        SslSelectChannelConnector connector = new SslSelectChannelConnector(sslContextFactory);
        connector.setPort(PORT);
        String host = configuration.lookup("http.host", null);
        if (host != null) {
            connector.setHost(host);
        }
        server.setConnectors(new Connector[] { connector });
    }
    ContextHandlerCollection contexts = new ContextHandlerCollection();
    {
        ServletContextHandler context = new ServletContextHandler(contexts, "/api");
        // context.setContextPath("/");
        context.addEventListener(guiceServletConfig);
        // Must add DefaultServlet for embedded Jetty
        // Failing to do this will cause 404 errors.
        context.addServlet(DefaultServlet.class, "/");
        FilterHolder filterHolder = new FilterHolder(GuiceFilter.class);
        context.addFilter(filterHolder, "*", EnumSet.of(DispatcherType.REQUEST));
        context.setClassLoader(Thread.currentThread().getContextClassLoader());
    }
    for (Entry<String, File> entry : wars.entrySet()) {
        String contextPath = entry.getKey();
        File war = entry.getValue();
        WebAppContext context = new WebAppContext();
        context.setWar(war.getAbsolutePath());
        context.setContextPath(contextPath);
        context.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", "false");
        context.addFilter(GwtCacheHeaderFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
        contexts.addHandler(context);
    }
    server.setHandler(contexts);
    server.addLifeCycleListener(new CloseOnFailLifecycleListener());
    server.start();
    if (!server.isStarted()) {
        return false;
    }
    if (configuration.lookup("jobrunner.enabled", true)) {
        scheduler.start();
        jobPoller.start();
    }
    return true;
}
Also used : SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) Connector(org.eclipse.jetty.server.Connector) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) ContextHandlerCollection(org.eclipse.jetty.server.handler.ContextHandlerCollection) SSLContext(javax.net.ssl.SSLContext) KeyStore(java.security.KeyStore) SslSelectChannelConnector(org.eclipse.jetty.server.ssl.SslSelectChannelConnector) WebAppContext(org.eclipse.jetty.webapp.WebAppContext) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) GuiceFilter(com.google.inject.servlet.GuiceFilter) DefaultServlet(org.eclipse.jetty.servlet.DefaultServlet) CertificateAndKey(com.fathomdb.crypto.CertificateAndKey) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) File(java.io.File)

Example 83 with FilterHolder

use of org.eclipse.jetty.servlet.FilterHolder in project pulsar by yahoo.

the class WebService method addServlet.

public void addServlet(String path, ServletHolder servletHolder, boolean requiresAuthentication) {
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath(path);
    context.addServlet(servletHolder, MATCH_ALL);
    context.setAttribute(WebService.ATTRIBUTE_PULSAR_NAME, pulsar);
    if (requiresAuthentication && pulsar.getConfiguration().isAuthenticationEnabled()) {
        FilterHolder filter = new FilterHolder(new AuthenticationFilter(pulsar));
        context.addFilter(filter, MATCH_ALL, EnumSet.allOf(DispatcherType.class));
    }
    log.info("Servlet path: '{}' -- Enable client version check: {} -- shouldCheckApiVersionOnPath: {}", path, pulsar.getConfiguration().isClientLibraryVersionCheckEnabled(), shouldCheckApiVersionOnPath(path));
    if (pulsar.getConfiguration().isClientLibraryVersionCheckEnabled() && shouldCheckApiVersionOnPath(path)) {
        // Add the ApiVersionFilter to reject request from deprecated
        // clients.
        FilterHolder holder = new FilterHolder(new ApiVersionFilter(pulsar, pulsar.getConfiguration().isClientLibraryVersionCheckAllowUnversioned()));
        context.addFilter(holder, MATCH_ALL, EnumSet.allOf(DispatcherType.class));
        log.info("Enabling ApiVersionFilter");
    }
    FilterHolder responseFilter = new FilterHolder(new ResponseHandlerFilter(pulsar));
    context.addFilter(responseFilter, MATCH_ALL, EnumSet.allOf(DispatcherType.class));
    handlers.add(context);
}
Also used : FilterHolder(org.eclipse.jetty.servlet.FilterHolder) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) DispatcherType(javax.servlet.DispatcherType)

Example 84 with FilterHolder

use of org.eclipse.jetty.servlet.FilterHolder in project symmetric-ds by JumpMind.

the class SymmetricWebServer method start.

public SymmetricWebServer start(int httpPort, int securePort, int httpJmxPort, Mode mode) throws Exception {
    TransportManagerFactory.initHttps(httpSslVerifiedServerNames, allowSelfSignedCerts);
    // indicate to the app that we are in stand alone mode
    System.setProperty(SystemConstants.SYSPROP_STANDALONE_WEB, "true");
    server = new Server();
    server.setConnectors(getConnectors(server, httpPort, securePort, mode));
    setupBasicAuthIfNeeded(server);
    webapp = new WebAppContext();
    webapp.setParentLoaderPriority(true);
    webapp.setConfigurationDiscovered(true);
    webapp.setContextPath(webHome);
    webapp.setWar(webAppDir);
    webapp.setResourceBase(webAppDir);
    webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed", allowDirListing);
    SessionManager sm = new SessionManager();
    webapp.getSessionHandler().setSessionManager(sm);
    FilterHolder filterHolder = new FilterHolder(HttpMethodFilter.class);
    filterHolder.setInitParameter("server.allow.http.methods", allowedMethods);
    filterHolder.setInitParameter("server.disallow.http.methods", disallowedMethods);
    webapp.addFilter(filterHolder, "/*", EnumSet.of(DispatcherType.REQUEST));
    webapp.getServletContext().getContextHandler().setMaxFormContentSize(Integer.parseInt(System.getProperty("org.eclipse.jetty.server.Request.maxFormContentSize", "800000")));
    webapp.getServletContext().getContextHandler().setMaxFormKeys(Integer.parseInt(System.getProperty("org.eclipse.jetty.server.Request.maxFormKeys", "100000")));
    if (propertiesFile != null) {
        webapp.getServletContext().getContextHandler().setInitParameter(WebConstants.INIT_SINGLE_SERVER_PROPERTIES_FILE, propertiesFile);
        webapp.getServletContext().getContextHandler().setInitParameter(WebConstants.INIT_PARAM_MULTI_SERVER_MODE, Boolean.toString(false));
    } else {
        webapp.getServletContext().getContextHandler().setInitParameter(WebConstants.INIT_PARAM_MULTI_SERVER_MODE, Boolean.toString(true));
    }
    server.setHandler(webapp);
    server.start();
    if (httpJmxPort > 0) {
        registerHttpJmxAdaptor(httpJmxPort);
    }
    if (join) {
        log.info("Joining the web server main thread");
        server.join();
    }
    return this;
}
Also used : WebAppContext(org.eclipse.jetty.webapp.WebAppContext) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) Server(org.eclipse.jetty.server.Server) MBeanServer(javax.management.MBeanServer) HashSessionManager(org.eclipse.jetty.server.session.HashSessionManager)

Aggregations

FilterHolder (org.eclipse.jetty.servlet.FilterHolder)84 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)44 Test (org.junit.Test)35 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)32 Server (org.eclipse.jetty.server.Server)21 CountDownLatch (java.util.concurrent.CountDownLatch)18 Filter (javax.servlet.Filter)11 IOException (java.io.IOException)10 URL (java.net.URL)10 DispatcherType (javax.servlet.DispatcherType)9 ServletException (javax.servlet.ServletException)8 AuthenticationToken (org.apache.hadoop.security.authentication.server.AuthenticationToken)8 ServerConnector (org.eclipse.jetty.server.ServerConnector)8 File (java.io.File)7 HttpURLConnection (java.net.HttpURLConnection)7 PrivilegedActionException (java.security.PrivilegedActionException)7 AuthenticationException (org.apache.hadoop.security.authentication.client.AuthenticationException)7 FilterMapping (org.eclipse.jetty.servlet.FilterMapping)7 WebAppContext (org.eclipse.jetty.webapp.WebAppContext)7 List (java.util.List)6