Search in sources :

Example 1 with ExecController

use of ratpack.exec.ExecController in project ratpack by ratpack.

the class DefaultRequestFixture method getEffectiveRegistry.

private Registry getEffectiveRegistry(final DefaultHandlingResult.ResultsHolder results) {
    ClientErrorHandler clientErrorHandler = (context, statusCode) -> {
        results.setClientError(statusCode);
        context.getResponse().status(statusCode);
        results.getLatch().countDown();
    };
    ServerErrorHandler serverErrorHandler = (context, throwable1) -> {
        results.setThrowable(throwable1);
        results.getLatch().countDown();
    };
    final Registry userRegistry = Registry.builder().add(ClientErrorHandler.class, clientErrorHandler).add(ServerErrorHandler.class, serverErrorHandler).build();
    return Exceptions.uncheck(() -> {
        ServerConfig serverConfig = serverConfigBuilder.build();
        DefaultExecController execController = new DefaultExecController(serverConfig.getThreads());
        return ServerRegistry.serverRegistry(new TestServer(), Impositions.none(), execController, serverConfig, r -> userRegistry.join(registryBuilder.build()));
    });
}
Also used : RatpackServer(ratpack.server.RatpackServer) HttpVersion(io.netty.handler.codec.http.HttpVersion) ClientErrorHandler(ratpack.error.ClientErrorHandler) RequestFixture(ratpack.test.handling.RequestFixture) RootPathBinding(ratpack.path.internal.RootPathBinding) HandlerTimeoutException(ratpack.test.handling.HandlerTimeoutException) Unpooled.unreleasableBuffer(io.netty.buffer.Unpooled.unreleasableBuffer) ServerRegistry(ratpack.server.internal.ServerRegistry) ByteBuf(io.netty.buffer.ByteBuf) MutableHeaders(ratpack.http.MutableHeaders) PathBindingStorage(ratpack.path.internal.PathBindingStorage) RequestBodyReader(ratpack.server.internal.RequestBodyReader) ServerConfig(ratpack.server.ServerConfig) ServerConfigBuilder(ratpack.server.ServerConfigBuilder) Registry(ratpack.registry.Registry) Map(java.util.Map) CharsetUtil(io.netty.util.CharsetUtil) DefaultPathBinding(ratpack.path.internal.DefaultPathBinding) DefaultRequest(ratpack.http.internal.DefaultRequest) Unpooled.buffer(io.netty.buffer.Unpooled.buffer) DefaultExecController(ratpack.exec.internal.DefaultExecController) Streams(ratpack.stream.Streams) RegistryBuilder(ratpack.registry.RegistryBuilder) ServerErrorHandler(ratpack.error.ServerErrorHandler) ImmutableMap(com.google.common.collect.ImmutableMap) HttpMethod(io.netty.handler.codec.http.HttpMethod) Promise(ratpack.exec.Promise) Block(ratpack.func.Block) Instant(java.time.Instant) HostAndPort(com.google.common.net.HostAndPort) InetSocketAddress(java.net.InetSocketAddress) Chain(ratpack.handling.Chain) RegistrySpec(ratpack.registry.RegistrySpec) Impositions(ratpack.impose.Impositions) DefaultHttpHeaders(io.netty.handler.codec.http.DefaultHttpHeaders) HandlingResult(ratpack.test.handling.HandlingResult) Action(ratpack.func.Action) Handler(ratpack.handling.Handler) Exceptions(ratpack.util.Exceptions) TransformablePublisher(ratpack.stream.TransformablePublisher) HttpHeaderNames(io.netty.handler.codec.http.HttpHeaderNames) Handlers(ratpack.handling.Handlers) NettyHeadersBackedMutableHeaders(ratpack.http.internal.NettyHeadersBackedMutableHeaders) ExecController(ratpack.exec.ExecController) ServerErrorHandler(ratpack.error.ServerErrorHandler) ServerConfig(ratpack.server.ServerConfig) ClientErrorHandler(ratpack.error.ClientErrorHandler) DefaultExecController(ratpack.exec.internal.DefaultExecController) ServerRegistry(ratpack.server.internal.ServerRegistry) Registry(ratpack.registry.Registry)

Example 2 with ExecController

use of ratpack.exec.ExecController 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

ClientErrorHandler (ratpack.error.ClientErrorHandler)2 ServerErrorHandler (ratpack.error.ServerErrorHandler)2 ExecController (ratpack.exec.ExecController)2 Impositions (ratpack.impose.Impositions)2 RegistryBuilder (ratpack.registry.RegistryBuilder)2 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 HostAndPort (com.google.common.net.HostAndPort)1 ByteBuf (io.netty.buffer.ByteBuf)1 Unpooled.buffer (io.netty.buffer.Unpooled.buffer)1 Unpooled.unreleasableBuffer (io.netty.buffer.Unpooled.unreleasableBuffer)1 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 HttpHeaderNames (io.netty.handler.codec.http.HttpHeaderNames)1 HttpMethod (io.netty.handler.codec.http.HttpMethod)1 HttpVersion (io.netty.handler.codec.http.HttpVersion)1 CharsetUtil (io.netty.util.CharsetUtil)1 InetSocketAddress (java.net.InetSocketAddress)1 Instant (java.time.Instant)1 Map (java.util.Map)1 DefaultDevelopmentErrorHandler (ratpack.error.internal.DefaultDevelopmentErrorHandler)1