Search in sources :

Example 1 with HttpClient

use of ratpack.http.client.HttpClient in project ratpack by ratpack.

the class ServerRegistry method buildBaseRegistry.

public static Registry buildBaseRegistry(RatpackServer ratpackServer, Impositions impositions, ExecController execController, ServerConfig serverConfig) {
    ErrorHandler errorHandler = serverConfig.isDevelopment() ? new DefaultDevelopmentErrorHandler() : new DefaultProductionErrorHandler();
    RegistryBuilder baseRegistryBuilder;
    try {
        HttpClient httpClient = HttpClient.of(s -> s.poolSize(0).byteBufAllocator(PooledByteBufAllocator.DEFAULT).maxContentLength(serverConfig.getMaxContentLength()));
        baseRegistryBuilder = Registry.builder().add(ServerConfig.class, serverConfig).add(Impositions.class, impositions).add(ByteBufAllocator.class, PooledByteBufAllocator.DEFAULT).add(ExecController.class, execController).add(MimeTypes.class, ActivationBackedMimeTypes.INSTANCE).add(PublicAddress.class, Optional.ofNullable(serverConfig.getPublicAddress()).map(PublicAddress::of).orElseGet(() -> PublicAddress.inferred(serverConfig.getSslContext() == null ? HTTP_SCHEME : HTTPS_SCHEME))).add(Redirector.TYPE, Redirector.standard()).add(ClientErrorHandler.class, errorHandler).add(ServerErrorHandler.class, errorHandler).add(FileRenderer.TYPE, serverConfig.isDevelopment() ? FileRenderer.NON_CACHING : FileRenderer.CACHING).add(PromiseRenderer.TYPE, PromiseRenderer.INSTANCE).add(PublisherRenderer.TYPE, PublisherRenderer.INSTANCE).add(OptionalRenderer.TYPE, OptionalRenderer.INSTANCE).add(RenderableRenderer.TYPE, RenderableRenderer.INSTANCE).add(CharSequenceRenderer.TYPE, CharSequenceRenderer.INSTANCE).add(JsonRenderer.TYPE, JsonRenderer.INSTANCE).add(FormParser.TYPE, FormParser.INSTANCE).add(JsonParser.TYPE, JsonParser.INSTANCE).add(Clock.class, Clock.systemDefaultZone()).add(RatpackServer.class, ratpackServer).add(ObjectMapper.class, new ObjectMapper()).add(Stopper.class, () -> uncheck(() -> {
            ratpackServer.stop();
            return null;
        })).add(HttpClient.class, httpClient).add(ServerSentEventStreamClient.class, ServerSentEventStreamClient.of(httpClient)).add(HealthCheckResultsRenderer.TYPE, new HealthCheckResultsRenderer(PooledByteBufAllocator.DEFAULT)).add(RequestId.Generator.class, UuidBasedRequestIdGenerator.INSTANCE);
        addConfigObjects(serverConfig, baseRegistryBuilder);
    } catch (Exception e) {
        // Uncheck because it really shouldn't happen
        throw uncheck(e);
    }
    if (serverConfig.isHasBaseDir()) {
        baseRegistryBuilder.add(FileSystemBinding.class, serverConfig.getBaseDir());
    }
    return baseRegistryBuilder.build();
}
Also used : ClientErrorHandler(ratpack.error.ClientErrorHandler) ErrorHandler(ratpack.error.internal.ErrorHandler) ServerErrorHandler(ratpack.error.ServerErrorHandler) DefaultProductionErrorHandler(ratpack.error.internal.DefaultProductionErrorHandler) DefaultDevelopmentErrorHandler(ratpack.error.internal.DefaultDevelopmentErrorHandler) HealthCheckResultsRenderer(ratpack.health.internal.HealthCheckResultsRenderer) ClientErrorHandler(ratpack.error.ClientErrorHandler) DefaultProductionErrorHandler(ratpack.error.internal.DefaultProductionErrorHandler) ExecController(ratpack.exec.ExecController) ServerSentEventStreamClient(ratpack.sse.ServerSentEventStreamClient) HttpClient(ratpack.http.client.HttpClient) DefaultDevelopmentErrorHandler(ratpack.error.internal.DefaultDevelopmentErrorHandler) RegistryBuilder(ratpack.registry.RegistryBuilder) Impositions(ratpack.impose.Impositions) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) UuidBasedRequestIdGenerator(ratpack.handling.internal.UuidBasedRequestIdGenerator)

Aggregations

ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ClientErrorHandler (ratpack.error.ClientErrorHandler)1 ServerErrorHandler (ratpack.error.ServerErrorHandler)1 DefaultDevelopmentErrorHandler (ratpack.error.internal.DefaultDevelopmentErrorHandler)1 DefaultProductionErrorHandler (ratpack.error.internal.DefaultProductionErrorHandler)1 ErrorHandler (ratpack.error.internal.ErrorHandler)1 ExecController (ratpack.exec.ExecController)1 UuidBasedRequestIdGenerator (ratpack.handling.internal.UuidBasedRequestIdGenerator)1 HealthCheckResultsRenderer (ratpack.health.internal.HealthCheckResultsRenderer)1 HttpClient (ratpack.http.client.HttpClient)1 Impositions (ratpack.impose.Impositions)1 RegistryBuilder (ratpack.registry.RegistryBuilder)1 ServerSentEventStreamClient (ratpack.sse.ServerSentEventStreamClient)1