Search in sources :

Example 91 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project rest.li by linkedin.

the class HttpNettyServerPipelineInitializer method initChannel.

@Override
protected void initChannel(NioSocketChannel ch) throws Exception {
    SslHandlerUtil.validateSslParameters(_sslContext, _sslParameters);
    // If _sslContext is not NULL, we should first add SSL handler to the pipeline to secure the channel.
    if (_sslContext != null) {
        final SslHandler sslHandler = SslHandlerUtil.getServerSslHandler(_sslContext, _sslParameters);
        ch.pipeline().addLast(SslHandlerUtil.PIPELINE_SSL_HANDLER, sslHandler);
    }
    ch.pipeline().addLast("decoder", new HttpRequestDecoder());
    ch.pipeline().addLast("aggregator", new HttpObjectAggregator(1048576));
    ch.pipeline().addLast("encoder", new HttpResponseEncoder());
    ch.pipeline().addLast("rapi", new RAPServerCodec());
    final SimpleChannelInboundHandler<RestRequest> restHandler = _restOverStream ? new PipelineStreamHandler(_dispatcher) : new PipelineRestHandler(_dispatcher);
    ch.pipeline().addLast(_eventExecutors, "handler", restHandler);
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) RestRequest(com.linkedin.r2.message.rest.RestRequest) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) SslHandler(io.netty.handler.ssl.SslHandler)

Example 92 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project zuul by Netflix.

the class PushChannelInitializer method addHttp1Handlers.

@Override
protected void addHttp1Handlers(ChannelPipeline pipeline) {
    pipeline.addLast(HTTP_CODEC_HANDLER_NAME, new HttpServerCodec(MAX_INITIAL_LINE_LENGTH.get(), MAX_HEADER_SIZE.get(), MAX_CHUNK_SIZE.get(), false));
    pipeline.addLast(new HttpObjectAggregator(8192));
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpServerCodec(io.netty.handler.codec.http.HttpServerCodec)

Example 93 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project flink by apache.

the class AbstractHandler method respondAsLeader.

@Override
protected void respondAsLeader(ChannelHandlerContext ctx, RoutedRequest routedRequest, T gateway) {
    HttpRequest httpRequest = routedRequest.getRequest();
    if (log.isTraceEnabled()) {
        log.trace("Received request " + httpRequest.uri() + '.');
    }
    FileUploads uploadedFiles = null;
    try {
        if (!inFlightRequestTracker.registerRequest()) {
            log.debug("The handler instance for {} had already been closed.", untypedResponseMessageHeaders.getTargetRestEndpointURL());
            ctx.channel().close();
            return;
        }
        if (!(httpRequest instanceof FullHttpRequest)) {
            // The RestServerEndpoint defines a HttpObjectAggregator in the pipeline that always
            // returns
            // FullHttpRequests.
            log.error("Implementation error: Received a request that wasn't a FullHttpRequest.");
            throw new RestHandlerException("Bad request received.", HttpResponseStatus.BAD_REQUEST);
        }
        final ByteBuf msgContent = ((FullHttpRequest) httpRequest).content();
        uploadedFiles = FileUploadHandler.getMultipartFileUploads(ctx);
        if (!untypedResponseMessageHeaders.acceptsFileUploads() && !uploadedFiles.getUploadedFiles().isEmpty()) {
            throw new RestHandlerException("File uploads not allowed.", HttpResponseStatus.BAD_REQUEST);
        }
        R request;
        if (msgContent.capacity() == 0) {
            try {
                request = MAPPER.readValue("{}", untypedResponseMessageHeaders.getRequestClass());
            } catch (JsonParseException | JsonMappingException je) {
                throw new RestHandlerException("Bad request received. Request did not conform to expected format.", HttpResponseStatus.BAD_REQUEST, je);
            }
        } else {
            try {
                InputStream in = new ByteBufInputStream(msgContent);
                request = MAPPER.readValue(in, untypedResponseMessageHeaders.getRequestClass());
            } catch (JsonParseException | JsonMappingException je) {
                throw new RestHandlerException(String.format("Request did not match expected format %s.", untypedResponseMessageHeaders.getRequestClass().getSimpleName()), HttpResponseStatus.BAD_REQUEST, je);
            }
        }
        final HandlerRequest<R> handlerRequest;
        try {
            handlerRequest = HandlerRequest.resolveParametersAndCreate(request, untypedResponseMessageHeaders.getUnresolvedMessageParameters(), routedRequest.getRouteResult().pathParams(), routedRequest.getRouteResult().queryParams(), uploadedFiles.getUploadedFiles());
        } catch (HandlerRequestException hre) {
            log.error("Could not create the handler request.", hre);
            throw new RestHandlerException(String.format("Bad request, could not parse parameters: %s", hre.getMessage()), HttpResponseStatus.BAD_REQUEST, hre);
        }
        log.trace("Starting request processing.");
        CompletableFuture<Void> requestProcessingFuture = respondToRequest(ctx, httpRequest, handlerRequest, gateway);
        final FileUploads finalUploadedFiles = uploadedFiles;
        requestProcessingFuture.handle((Void ignored, Throwable throwable) -> {
            if (throwable != null) {
                return handleException(ExceptionUtils.stripCompletionException(throwable), ctx, httpRequest);
            }
            return CompletableFuture.<Void>completedFuture(null);
        }).thenCompose(Function.identity()).whenComplete((Void ignored, Throwable throwable) -> {
            if (throwable != null) {
                log.warn("An exception occurred while handling another exception.", throwable);
            }
            finalizeRequestProcessing(finalUploadedFiles);
        });
    } catch (Throwable e) {
        final FileUploads finalUploadedFiles = uploadedFiles;
        handleException(e, ctx, httpRequest).whenComplete((Void ignored, Throwable throwable) -> finalizeRequestProcessing(finalUploadedFiles));
    }
}
Also used : HttpRequest(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpRequest) FullHttpRequest(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest) FullHttpRequest(org.apache.flink.shaded.netty4.io.netty.handler.codec.http.FullHttpRequest) ByteBufInputStream(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream) InputStream(java.io.InputStream) ByteBufInputStream(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBufInputStream) ByteBuf(org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf) JsonParseException(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.core.JsonParseException) JsonMappingException(org.apache.flink.shaded.jackson2.com.fasterxml.jackson.databind.JsonMappingException)

Example 94 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project graylog2-server by Graylog2.

the class HttpTransport method getCustomChildChannelHandlers.

@Override
protected LinkedHashMap<String, Callable<? extends ChannelHandler>> getCustomChildChannelHandlers(MessageInput input) {
    final LinkedHashMap<String, Callable<? extends ChannelHandler>> handlers = new LinkedHashMap<>();
    if (idleWriterTimeout > 0) {
        // Install read timeout handler to close idle connections after a timeout.
        // This avoids dangling HTTP connections when the HTTP client does not close the connection properly.
        // For details see: https://github.com/Graylog2/graylog2-server/issues/3223#issuecomment-270350500
        handlers.put("read-timeout-handler", () -> new ReadTimeoutHandler(idleWriterTimeout, TimeUnit.SECONDS));
    }
    handlers.put("decoder", () -> new HttpRequestDecoder(DEFAULT_MAX_INITIAL_LINE_LENGTH, DEFAULT_MAX_HEADER_SIZE, maxChunkSize));
    handlers.put("decompressor", HttpContentDecompressor::new);
    handlers.put("encoder", HttpResponseEncoder::new);
    handlers.put("aggregator", () -> new HttpObjectAggregator(maxChunkSize));
    handlers.put("http-handler", () -> new HttpHandler(enableCors));
    handlers.putAll(super.getCustomChildChannelHandlers(input));
    return handlers;
}
Also used : HttpResponseEncoder(io.netty.handler.codec.http.HttpResponseEncoder) HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) HttpHandler(org.graylog2.inputs.transports.netty.HttpHandler) HttpRequestDecoder(io.netty.handler.codec.http.HttpRequestDecoder) ReadTimeoutHandler(io.netty.handler.timeout.ReadTimeoutHandler) ChannelHandler(io.netty.channel.ChannelHandler) Callable(java.util.concurrent.Callable) LinkedHashMap(java.util.LinkedHashMap) HttpContentDecompressor(io.netty.handler.codec.http.HttpContentDecompressor)

Example 95 with HttpObjectAggregator

use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpObjectAggregator in project reactor-netty by reactor.

the class HttpClientOperations method withWebsocketSupport.

@SuppressWarnings("FutureReturnValueIgnored")
final void withWebsocketSupport(WebsocketClientSpec websocketClientSpec, boolean compress) {
    URI url = websocketUri();
    // prevent further header to be sent for handshaking
    if (markSentHeaders()) {
        // Returned value is deliberately ignored
        addHandlerFirst(NettyPipeline.HttpAggregator, new HttpObjectAggregator(8192));
        removeHandler(NettyPipeline.HttpMetricsHandler);
        if (websocketClientSpec.compress()) {
            requestHeaders().remove(HttpHeaderNames.ACCEPT_ENCODING);
            // Returned value is deliberately ignored
            removeHandler(NettyPipeline.HttpDecompressor);
            // Returned value is deliberately ignored
            addHandlerFirst(NettyPipeline.WsCompressionHandler, WebSocketClientCompressionHandler.INSTANCE);
        }
        if (log.isDebugEnabled()) {
            log.debug(format(channel(), "Attempting to perform websocket handshake with {}"), url);
        }
        WebsocketClientOperations ops = new WebsocketClientOperations(url, websocketClientSpec, this);
        if (!rebind(ops)) {
            log.error(format(channel(), "Error while rebinding websocket in channel attribute: " + get(channel()) + " to " + ops));
        }
    }
}
Also used : HttpObjectAggregator(io.netty.handler.codec.http.HttpObjectAggregator) URI(java.net.URI)

Aggregations

HttpObjectAggregator (io.netty.handler.codec.http.HttpObjectAggregator)95 ChannelPipeline (io.netty.channel.ChannelPipeline)60 HttpServerCodec (io.netty.handler.codec.http.HttpServerCodec)34 HttpRequestDecoder (io.netty.handler.codec.http.HttpRequestDecoder)29 HttpResponseEncoder (io.netty.handler.codec.http.HttpResponseEncoder)28 HttpClientCodec (io.netty.handler.codec.http.HttpClientCodec)25 SocketChannel (io.netty.channel.socket.SocketChannel)20 ChunkedWriteHandler (io.netty.handler.stream.ChunkedWriteHandler)18 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)17 NioSocketChannel (io.netty.channel.socket.nio.NioSocketChannel)17 NioEventLoopGroup (io.netty.channel.nio.NioEventLoopGroup)16 Bootstrap (io.netty.bootstrap.Bootstrap)13 Channel (io.netty.channel.Channel)12 EventLoopGroup (io.netty.channel.EventLoopGroup)11 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)11 SslHandler (io.netty.handler.ssl.SslHandler)11 HttpContentCompressor (io.netty.handler.codec.http.HttpContentCompressor)10 IdleStateHandler (io.netty.handler.timeout.IdleStateHandler)9 ServerBootstrap (io.netty.bootstrap.ServerBootstrap)8 NioServerSocketChannel (io.netty.channel.socket.nio.NioServerSocketChannel)8