Search in sources :

Example 1 with NonblockingServletHolder

use of io.dropwizard.jetty.NonblockingServletHolder in project dropwizard by dropwizard.

the class AbstractServerFactory method createAdminServlet.

protected Handler createAdminServlet(Server server, MutableServletContextHandler handler, MetricRegistry metrics, HealthCheckRegistry healthChecks) {
    configureSessionsAndSecurity(handler, server);
    handler.setServer(server);
    handler.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metrics);
    handler.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthChecks);
    handler.addServlet(new NonblockingServletHolder(new AdminServlet()), "/*");
    handler.addFilter(AllowedMethodsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)).setInitParameter(AllowedMethodsFilter.ALLOWED_METHODS_PARAM, Joiner.on(',').join(allowedMethods));
    return handler;
}
Also used : NonblockingServletHolder(io.dropwizard.jetty.NonblockingServletHolder) AdminServlet(com.codahale.metrics.servlets.AdminServlet) AllowedMethodsFilter(io.dropwizard.jersey.filter.AllowedMethodsFilter)

Example 2 with NonblockingServletHolder

use of io.dropwizard.jetty.NonblockingServletHolder in project dropwizard by dropwizard.

the class AbstractServerFactory method createAppServlet.

protected Handler createAppServlet(Server server, JerseyEnvironment jersey, ObjectMapper objectMapper, Validator validator, MutableServletContextHandler handler, @Nullable Servlet jerseyContainer, MetricRegistry metricRegistry) {
    configureSessionsAndSecurity(handler, server);
    handler.addFilter(AllowedMethodsFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST)).setInitParameter(AllowedMethodsFilter.ALLOWED_METHODS_PARAM, Joiner.on(',').join(allowedMethods));
    handler.addFilter(ThreadNameFilter.class, "/*", EnumSet.of(DispatcherType.REQUEST));
    serverPush.addFilter(handler);
    if (jerseyContainer != null) {
        jerseyRootPath.ifPresent(jersey::setUrlPattern);
        jersey.register(new JacksonBinder(objectMapper));
        jersey.register(new HibernateValidationFeature(validator));
        if (registerDefaultExceptionMappers == null || registerDefaultExceptionMappers) {
            jersey.register(new ExceptionMapperBinder(detailedJsonProcessingExceptionMapper));
        }
        handler.addServlet(new NonblockingServletHolder(jerseyContainer), jersey.getUrlPattern());
    }
    final InstrumentedHandler instrumented = new InstrumentedHandler(metricRegistry);
    instrumented.setServer(server);
    instrumented.setHandler(handler);
    return instrumented;
}
Also used : NonblockingServletHolder(io.dropwizard.jetty.NonblockingServletHolder) InstrumentedHandler(com.codahale.metrics.jetty9.InstrumentedHandler) HibernateValidationFeature(io.dropwizard.jersey.validation.HibernateValidationFeature) ExceptionMapperBinder(io.dropwizard.setup.ExceptionMapperBinder) JacksonBinder(io.dropwizard.jersey.jackson.JacksonBinder) AllowedMethodsFilter(io.dropwizard.jersey.filter.AllowedMethodsFilter)

Example 3 with NonblockingServletHolder

use of io.dropwizard.jetty.NonblockingServletHolder in project dropwizard by dropwizard.

the class ServletEnvironment method addServlet.

/**
     * Add a servlet instance.
     *
     * @param name    the servlet's name
     * @param servlet the servlet instance
     * @return a {@link javax.servlet.ServletRegistration.Dynamic} instance allowing for further
     *         configuration
     */
public ServletRegistration.Dynamic addServlet(String name, Servlet servlet) {
    final ServletHolder holder = new NonblockingServletHolder(requireNonNull(servlet));
    holder.setName(name);
    handler.getServletHandler().addServlet(holder);
    final ServletRegistration.Dynamic registration = holder.getRegistration();
    checkDuplicateRegistration(name, servlets, "servlet");
    return registration;
}
Also used : NonblockingServletHolder(io.dropwizard.jetty.NonblockingServletHolder) ServletRegistration(javax.servlet.ServletRegistration) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) NonblockingServletHolder(io.dropwizard.jetty.NonblockingServletHolder)

Aggregations

NonblockingServletHolder (io.dropwizard.jetty.NonblockingServletHolder)3 AllowedMethodsFilter (io.dropwizard.jersey.filter.AllowedMethodsFilter)2 InstrumentedHandler (com.codahale.metrics.jetty9.InstrumentedHandler)1 AdminServlet (com.codahale.metrics.servlets.AdminServlet)1 JacksonBinder (io.dropwizard.jersey.jackson.JacksonBinder)1 HibernateValidationFeature (io.dropwizard.jersey.validation.HibernateValidationFeature)1 ExceptionMapperBinder (io.dropwizard.setup.ExceptionMapperBinder)1 ServletRegistration (javax.servlet.ServletRegistration)1 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)1