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);
}
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));
}
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));
}
}
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;
}
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));
}
}
}
Aggregations