Search in sources :

Example 1 with HibernateValidationFeature

use of io.dropwizard.jersey.validation.HibernateValidationFeature in project dropwizard by dropwizard.

the class JerseyClientBuilder method buildConfig.

private Configuration buildConfig(final String name, final ExecutorService threadPool, final ObjectMapper objectMapper, final Validator validator) {
    final ClientConfig config = new ClientConfig();
    for (Object singleton : this.singletons) {
        config.register(singleton);
    }
    for (Class<?> provider : this.providers) {
        config.register(provider);
    }
    config.register(new JacksonBinder(objectMapper));
    config.register(new HibernateValidationFeature(validator));
    for (Map.Entry<String, Object> property : this.properties.entrySet()) {
        config.property(property.getKey(), property.getValue());
    }
    config.register(new DropwizardExecutorProvider(threadPool, shutdownGracePeriod));
    if (connectorProvider == null) {
        final ConfiguredCloseableHttpClient apacheHttpClient = apacheHttpClientBuilder.buildWithDefaultRequestConfiguration(name);
        connectorProvider = (client, runtimeConfig) -> new DropwizardApacheConnector(apacheHttpClient.getClient(), apacheHttpClient.getDefaultRequestConfig(), configuration.isChunkedEncodingEnabled());
    }
    config.connectorProvider(connectorProvider);
    return config;
}
Also used : HibernateValidationFeature(io.dropwizard.jersey.validation.HibernateValidationFeature) JacksonBinder(io.dropwizard.jersey.jackson.JacksonBinder) ClientConfig(org.glassfish.jersey.client.ClientConfig) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 2 with HibernateValidationFeature

use of io.dropwizard.jersey.validation.HibernateValidationFeature 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)

Aggregations

JacksonBinder (io.dropwizard.jersey.jackson.JacksonBinder)2 HibernateValidationFeature (io.dropwizard.jersey.validation.HibernateValidationFeature)2 InstrumentedHandler (com.codahale.metrics.jetty9.InstrumentedHandler)1 AllowedMethodsFilter (io.dropwizard.jersey.filter.AllowedMethodsFilter)1 NonblockingServletHolder (io.dropwizard.jetty.NonblockingServletHolder)1 ExceptionMapperBinder (io.dropwizard.setup.ExceptionMapperBinder)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 ClientConfig (org.glassfish.jersey.client.ClientConfig)1