Search in sources :

Example 6 with Handler

use of ratpack.handling.Handler in project ratpack by ratpack.

the class DefaultRequestFixture method handleChain.

@Override
public HandlingResult handleChain(Action<? super Chain> chainAction) throws Exception {
    final DefaultHandlingResult.ResultsHolder results = new DefaultHandlingResult.ResultsHolder();
    Registry registry = getEffectiveRegistry(results);
    ServerConfig serverConfig = registry.get(ServerConfig.class);
    Handler handler = Handlers.chain(serverConfig, registry, chainAction);
    return invoke(handler, registry, results);
}
Also used : ServerConfig(ratpack.server.ServerConfig) ClientErrorHandler(ratpack.error.ClientErrorHandler) ServerErrorHandler(ratpack.error.ServerErrorHandler) Handler(ratpack.handling.Handler) ServerRegistry(ratpack.server.internal.ServerRegistry) Registry(ratpack.registry.Registry)

Example 7 with Handler

use of ratpack.handling.Handler in project ratpack by ratpack.

the class FactoryHandler method describeTo.

@Override
public void describeTo(StringBuilder stringBuilder) {
    Handler last = this.last;
    if (last == null) {
        last = this;
    }
    DescribingHandlers.describeTo(last, stringBuilder);
}
Also used : Handler(ratpack.handling.Handler)

Example 8 with Handler

use of ratpack.handling.Handler in project ratpack by ratpack.

the class DefaultRequestFixture method invoke.

private HandlingResult invoke(Handler handler, Registry registry, DefaultHandlingResult.ResultsHolder results) throws HandlerTimeoutException {
    ServerConfig serverConfig = registry.get(ServerConfig.class);
    DefaultRequest request = new DefaultRequest(Instant.now(), requestHeaders, HttpMethod.valueOf(method.toUpperCase()), HttpVersion.valueOf(protocol), uri, new InetSocketAddress(remoteHostAndPort.getHostText(), remoteHostAndPort.getPort()), new InetSocketAddress(localHostAndPort.getHostText(), localHostAndPort.getPort()), serverConfig, new RequestBodyReader() {

        @Override
        public long getContentLength() {
            return requestBody.readableBytes();
        }

        @Override
        public Promise<? extends ByteBuf> read(long maxContentLength, Block onTooLarge) {
            return Promise.value(requestBody).route(r -> r.readableBytes() > maxContentLength, onTooLarge.action());
        }

        @Override
        public TransformablePublisher<? extends ByteBuf> readStream(long maxContentLength) {
            return Streams.<ByteBuf>yield(r -> {
                if (r.getRequestNum() > 0) {
                    return null;
                } else {
                    return requestBody;
                }
            });
        }
    });
    if (pathBinding != null) {
        handler = Handlers.chain(ctx -> {
            ctx.getExecution().get(PathBindingStorage.TYPE).push(pathBinding);
            ctx.next();
        }, handler);
    }
    try {
        return new DefaultHandlingResult(request, results, responseHeaders, registry, timeout, handler);
    } catch (Exception e) {
        throw Exceptions.uncheck(e);
    } finally {
        registry.get(ExecController.class).close();
    }
}
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) TransformablePublisher(ratpack.stream.TransformablePublisher) DefaultRequest(ratpack.http.internal.DefaultRequest) InetSocketAddress(java.net.InetSocketAddress) DefaultExecController(ratpack.exec.internal.DefaultExecController) ExecController(ratpack.exec.ExecController) ByteBuf(io.netty.buffer.ByteBuf) RequestBodyReader(ratpack.server.internal.RequestBodyReader) HandlerTimeoutException(ratpack.test.handling.HandlerTimeoutException) ServerConfig(ratpack.server.ServerConfig) Promise(ratpack.exec.Promise) Block(ratpack.func.Block)

Aggregations

Handler (ratpack.handling.Handler)8 Registry (ratpack.registry.Registry)3 ServerConfig (ratpack.server.ServerConfig)3 ByteBuf (io.netty.buffer.ByteBuf)2 CharsetUtil (io.netty.util.CharsetUtil)2 InetSocketAddress (java.net.InetSocketAddress)2 Instant (java.time.Instant)2 ClientErrorHandler (ratpack.error.ClientErrorHandler)2 ServerErrorHandler (ratpack.error.ServerErrorHandler)2 ExecController (ratpack.exec.ExecController)2 Action (ratpack.func.Action)2 Handlers (ratpack.handling.Handlers)2 MutableHeaders (ratpack.http.MutableHeaders)2 ImmutableMap (com.google.common.collect.ImmutableMap)1 HostAndPort (com.google.common.net.HostAndPort)1 ByteBufUtil (io.netty.buffer.ByteBufUtil)1 Unpooled (io.netty.buffer.Unpooled)1 Unpooled.buffer (io.netty.buffer.Unpooled.buffer)1 Unpooled.unreleasableBuffer (io.netty.buffer.Unpooled.unreleasableBuffer)1 io.netty.channel (io.netty.channel)1