Search in sources :

Example 11 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project drill by axbaretto.

the class WebServer method buildServlets.

/**
 * Build the web app with embedded servlets.
 * <p>
 * <b>ServletContextHandler</b>: is a Jetty-provided handler that add the
 * extra bits needed to set up the context that servlets expect. Think of it
 * as an adapter between the (simple) Jetty handler and the (more complex)
 * servlet API.
 */
private void buildServlets(Config config) {
    final ServletContextHandler servletContextHandler = new ServletContextHandler(null, "/");
    servletContextHandler.setErrorHandler(createErrorHandler());
    jettyServer.setHandler(servletContextHandler);
    // Servlet holder for the pages of the Drill AM web app. The web app is a
    // javax.ws application driven from annotations. The servlet holder "does
    // the right thing" to drive the application, which is rooted at "/".
    // The servlet container comes from Jersey, and manages the servlet
    // lifecycle.
    final ServletHolder servletHolder = new ServletHolder(new ServletContainer(new WebUiPageTree(dispatcher)));
    servletHolder.setInitOrder(1);
    servletContextHandler.addServlet(servletHolder, "/*");
    final ServletHolder restHolder = new ServletHolder(new ServletContainer(new AmRestApi(dispatcher)));
    restHolder.setInitOrder(2);
    servletContextHandler.addServlet(restHolder, "/rest/*");
    // Static resources (CSS, images, etc.)
    setupStaticResources(servletContextHandler);
    if (AMSecurityManagerImpl.isEnabled()) {
        servletContextHandler.setSecurityHandler(createSecurityHandler(config));
        servletContextHandler.setSessionHandler(createSessionHandler(config, servletContextHandler.getSecurityHandler()));
    }
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 12 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project drill by axbaretto.

the class WebServer method createServletContextHandler.

private ServletContextHandler createServletContextHandler(final boolean authEnabled) throws DrillbitStartupException {
    // Add resources
    final ErrorHandler errorHandler = new DrillErrorHandler();
    errorHandler.setShowStacks(true);
    errorHandler.setShowMessageInTitle(true);
    final ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
    servletContextHandler.setErrorHandler(errorHandler);
    servletContextHandler.setContextPath("/");
    final ServletHolder servletHolder = new ServletHolder(new ServletContainer(new DrillRestServer(workManager, servletContextHandler.getServletContext(), drillbit)));
    servletHolder.setInitOrder(1);
    servletContextHandler.addServlet(servletHolder, "/*");
    servletContextHandler.addServlet(new ServletHolder(new MetricsServlet(metrics)), "/status/metrics");
    servletContextHandler.addServlet(new ServletHolder(new ThreadDumpServlet()), "/status/threads");
    final ServletHolder staticHolder = new ServletHolder("static", DefaultServlet.class);
    // Get resource URL for Drill static assets, based on where Drill icon is located
    String drillIconResourcePath = Resource.newClassPathResource(BASE_STATIC_PATH + DRILL_ICON_RESOURCE_RELATIVE_PATH).getURL().toString();
    staticHolder.setInitParameter("resourceBase", drillIconResourcePath.substring(0, drillIconResourcePath.length() - DRILL_ICON_RESOURCE_RELATIVE_PATH.length()));
    staticHolder.setInitParameter("dirAllowed", "false");
    staticHolder.setInitParameter("pathInfoOnly", "true");
    servletContextHandler.addServlet(staticHolder, "/static/*");
    if (authEnabled) {
        // DrillSecurityHandler is used to support SPNEGO and FORM authentication together
        servletContextHandler.setSecurityHandler(new DrillHttpSecurityHandlerProvider(config, workManager.getContext()));
        servletContextHandler.setSessionHandler(createSessionHandler(servletContextHandler.getSecurityHandler()));
    }
    if (isImpersonationOnlyEnabled(workManager.getContext().getConfig())) {
        for (String path : new String[] { "/query", "/query.json" }) {
            servletContextHandler.addFilter(UserNameFilter.class, path, EnumSet.of(DispatcherType.REQUEST));
        }
    }
    if (config.getBoolean(ExecConstants.HTTP_CORS_ENABLED)) {
        FilterHolder holder = new FilterHolder(CrossOriginFilter.class);
        holder.setInitParameter(CrossOriginFilter.ALLOWED_ORIGINS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_ORIGINS), ","));
        holder.setInitParameter(CrossOriginFilter.ALLOWED_METHODS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_METHODS), ","));
        holder.setInitParameter(CrossOriginFilter.ALLOWED_HEADERS_PARAM, StringUtils.join(config.getStringList(ExecConstants.HTTP_CORS_ALLOWED_HEADERS), ","));
        holder.setInitParameter(CrossOriginFilter.ALLOW_CREDENTIALS_PARAM, String.valueOf(config.getBoolean(ExecConstants.HTTP_CORS_CREDENTIALS)));
        for (String path : new String[] { "*.json", "/storage/*/enable/*", "/status*" }) {
            servletContextHandler.addFilter(holder, path, EnumSet.of(DispatcherType.REQUEST));
        }
    }
    return servletContextHandler;
}
Also used : DrillErrorHandler(org.apache.drill.exec.server.rest.auth.DrillErrorHandler) ErrorHandler(org.eclipse.jetty.server.handler.ErrorHandler) DrillErrorHandler(org.apache.drill.exec.server.rest.auth.DrillErrorHandler) DrillHttpSecurityHandlerProvider(org.apache.drill.exec.server.rest.auth.DrillHttpSecurityHandlerProvider) FilterHolder(org.eclipse.jetty.servlet.FilterHolder) MetricsServlet(com.codahale.metrics.servlets.MetricsServlet) ThreadDumpServlet(com.codahale.metrics.servlets.ThreadDumpServlet) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler)

Example 13 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project samza by apache.

the class SamzaRestService method main.

/**
 * Command line interface to run the server.
 *
 * @param args arguments supported by {@link org.apache.samza.util.CommandLine}.
 *             In particular, --config job.config.loader.properties.path and
 *             --config job.config.loader.factory are used to read the Samza REST config file.
 * @throws Exception if the server could not be successfully started.
 */
public static void main(String[] args) throws Exception {
    SamzaMonitorService monitorService = null;
    try {
        SamzaRestConfig config = parseConfig(args);
        ReadableMetricsRegistry metricsRegistry = new MetricsRegistryMap();
        log.info("Creating new SamzaRestService with config: {}", config);
        MetricsConfig metricsConfig = new MetricsConfig(config);
        Map<String, MetricsReporter> metricsReporters = MetricsReporterLoader.getMetricsReporters(metricsConfig, Util.getLocalHost().getHostName());
        SamzaRestService restService = new SamzaRestService(new Server(config.getPort()), metricsRegistry, metricsReporters, new ServletContextHandler(ServletContextHandler.SESSIONS));
        // Add applications
        SamzaRestApplication samzaRestApplication = new SamzaRestApplication(config);
        ServletContainer container = new ServletContainer(samzaRestApplication);
        restService.addServlet(container, "/*");
        monitorService = new SamzaMonitorService(config, metricsRegistry);
        monitorService.start();
        restService.runBlocking();
    } catch (Throwable t) {
        log.error("Exception in main.", t);
    } finally {
        if (monitorService != null) {
            monitorService.stop();
        }
    }
}
Also used : ReadableMetricsRegistry(org.apache.samza.metrics.ReadableMetricsRegistry) Server(org.eclipse.jetty.server.Server) MetricsConfig(org.apache.samza.config.MetricsConfig) MetricsReporter(org.apache.samza.metrics.MetricsReporter) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) MetricsRegistryMap(org.apache.samza.metrics.MetricsRegistryMap) ServletContextHandler(org.eclipse.jetty.servlet.ServletContextHandler) SamzaMonitorService(org.apache.samza.monitor.SamzaMonitorService)

Example 14 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project JsonPath by jayway.

the class Main method createJerseyServlet.

private static ServletContainer createJerseyServlet() throws IOException {
    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.register(JacksonFeature.class);
    resourceConfig.register(new ApiResource());
    return new ServletContainer(resourceConfig);
}
Also used : ApiResource(com.jayway.jsonpath.web.resource.ApiResource) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Example 15 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project neo4j by neo4j.

the class JaxRsServletHolderFactory method create.

public ServletHolder create(ComponentsBinder binder, boolean wadlEnabled) {
    for (Injectable<?> injectable : injectables) {
        Supplier<?> getValue = injectable::getValue;
        Class<?> type = injectable.getType();
        binder.addLazyBinding(getValue, type);
    }
    ResourceConfig resourceConfig = new ResourceConfig().register(binder).register(XForwardFilter.class).packages(packages.toArray(new String[0])).registerClasses(classes).property(WADL_FEATURE_DISABLE, String.valueOf(!wadlEnabled));
    ServletContainer container = new ServletContainer(resourceConfig);
    return new ServletHolder(container);
}
Also used : ServletHolder(org.eclipse.jetty.servlet.ServletHolder) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig)

Aggregations

ServletContainer (org.glassfish.jersey.servlet.ServletContainer)49 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)30 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)29 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)24 Server (org.eclipse.jetty.server.Server)10 IOException (java.io.IOException)7 DispatcherType (javax.servlet.DispatcherType)6 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)6 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)5 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)5 Bean (org.springframework.context.annotation.Bean)5 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)4 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)4 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)4 StatisticsHandler (org.eclipse.jetty.server.handler.StatisticsHandler)4 ServletRegistration (javax.servlet.ServletRegistration)3 ConnectException (org.apache.kafka.connect.errors.ConnectException)3 ConnectorPluginsResource (org.apache.kafka.connect.runtime.rest.resources.ConnectorPluginsResource)3 ConnectorsResource (org.apache.kafka.connect.runtime.rest.resources.ConnectorsResource)3 Slf4jRequestLog (org.eclipse.jetty.server.Slf4jRequestLog)3