From 57af07c950342afcbea7eb3513cfd53a2dbabe04 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=CC=88rg=20Prante?= Date: Thu, 10 Sep 2020 18:11:53 +0200 Subject: [PATCH] update to netty 4.1.52, add exception handler for HTTP pipeline handler --- gradle.properties | 10 +++++----- .../java/org/xbib/netty/http/server/Server.java | 1 + .../protocol/http1/HttpPipeliningHandler.java | 17 +++++++++++++++++ 3 files changed, 23 insertions(+), 5 deletions(-) diff --git a/gradle.properties b/gradle.properties index a972173..ba0d50b 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,19 +1,19 @@ group = org.xbib name = netty-http -version = 4.1.51.5 +version = 4.1.52.0 gradle.wrapper.version = 6.4.1 -netty.version = 4.1.51.Final -tcnative.version = 2.0.31.Final -xbib.net.version = 2.1.0 +netty.version = 4.1.52.Final +tcnative.version = 2.0.34.Final bouncycastle.version = 1.66 reactivestreams.version = 1.0.2 -xbib-guice.version = 4.0.4 reactivex.version = 1.3.8 conscrypt.version = 2.4.0 javassist.version = 3.27.0-GA jackson.version = 2.11.1 mockito.version = 3.4.4 +xbib.net.version = 2.1.0 +xbib-guice.version = 4.0.4 # uuhh, too many tests to update to jupiter in rx... junit.version = 5.6.2 junit4.version = 4.13 diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java index 1bfe1cd..0a47932 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/Server.java @@ -100,6 +100,7 @@ public final class Server implements AutoCloseable { * @param parentEventLoopGroup parent event loop group * @param childEventLoopGroup child event loop group * @param socketChannelClass socket channel class + * @param executor an extra blocking thread pool executor or null */ @SuppressWarnings("unchecked") private Server(DefaultServerConfig serverConfig, diff --git a/netty-http-server/src/main/java/org/xbib/netty/http/server/protocol/http1/HttpPipeliningHandler.java b/netty-http-server/src/main/java/org/xbib/netty/http/server/protocol/http1/HttpPipeliningHandler.java index beb6c25..6f40ec2 100644 --- a/netty-http-server/src/main/java/org/xbib/netty/http/server/protocol/http1/HttpPipeliningHandler.java +++ b/netty-http-server/src/main/java/org/xbib/netty/http/server/protocol/http1/HttpPipeliningHandler.java @@ -1,15 +1,22 @@ package org.xbib.netty.http.server.protocol.http1; +import io.netty.buffer.Unpooled; import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelPromise; +import io.netty.handler.codec.http.DefaultFullHttpResponse; +import io.netty.handler.codec.http.HttpResponseStatus; +import io.netty.handler.codec.http.HttpVersion; import io.netty.handler.codec.http.LastHttpContent; +import java.nio.charset.StandardCharsets; import java.util.PriorityQueue; import java.util.Queue; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; +import java.util.logging.Level; +import java.util.logging.Logger; /** * Implements HTTP pipelining ordering, ensuring that responses are completely served in the same order as their @@ -19,6 +26,8 @@ import java.util.concurrent.locks.ReentrantLock; */ public class HttpPipeliningHandler extends ChannelDuplexHandler { + private final Logger logger = Logger.getLogger(HttpPipeliningHandler.class.getName()); + private final int pipelineCapacity; private final Lock lock; @@ -80,4 +89,12 @@ public class HttpPipeliningHandler extends ChannelDuplexHandler { super.write(ctx, msg, promise); } } + + @Override + public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) { + logger.log(Level.SEVERE, cause.getMessage(), cause); + ctx.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, + HttpResponseStatus.INTERNAL_SERVER_ERROR, + Unpooled.copiedBuffer(cause.getMessage().getBytes(StandardCharsets.UTF_8)))); + } }