Skip to content

Commit 8f24479

Browse files
committed
netty 4.1.1.Final fix #383
1 parent 4fe264a commit 8f24479

10 files changed

Lines changed: 503 additions & 448 deletions

File tree

jooby-netty/src/main/java/org/jooby/internal/netty/NettyHandler.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,10 +69,10 @@ public NettyHandler(final HttpHandler handler, final Config config) {
6969
@Override
7070
public void channelRead0(final ChannelHandlerContext ctx, final Object msg) {
7171
if (msg instanceof FullHttpRequest) {
72-
ctx.attr(NettyRequest.NEED_FLUSH).set(true);
72+
ctx.channel().attr(NettyRequest.NEED_FLUSH).set(true);
7373

7474
FullHttpRequest req = (FullHttpRequest) msg;
75-
ctx.attr(PATH).set(req.method().name() + " " + req.uri());
75+
ctx.channel().attr(PATH).set(req.method().name() + " " + req.uri());
7676

7777
if (HttpUtil.is100ContinueExpected(req)) {
7878
ctx.write(new DefaultFullHttpResponse(HTTP_1_1, HttpResponseStatus.CONTINUE));
@@ -89,14 +89,14 @@ public void channelRead0(final ChannelHandlerContext ctx, final Object msg) {
8989
exceptionCaught(ctx, ex);
9090
}
9191
} else if (msg instanceof WebSocketFrame) {
92-
Attribute<NettyWebSocket> ws = ctx.attr(NettyWebSocket.KEY);
92+
Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY);
9393
ws.get().handle(msg);
9494
}
9595
}
9696

9797
@Override
9898
public void channelReadComplete(final ChannelHandlerContext ctx) throws Exception {
99-
Attribute<Boolean> attr = ctx.attr(NettyRequest.NEED_FLUSH);
99+
Attribute<Boolean> attr = ctx.channel().attr(NettyRequest.NEED_FLUSH);
100100
boolean needFlush = (attr == null || attr.get() == Boolean.TRUE);
101101
if (needFlush) {
102102
ctx.flush();
@@ -107,13 +107,13 @@ public void channelReadComplete(final ChannelHandlerContext ctx) throws Exceptio
107107
public void exceptionCaught(final ChannelHandlerContext ctx, final Throwable cause) {
108108
try {
109109
if (connectionResetByPeer(cause)) {
110-
log.trace("execution of: " + ctx.attr(PATH).get() + " resulted in error", cause);
110+
log.trace("execution of: " + ctx.channel().attr(PATH).get() + " resulted in error", cause);
111111
} else {
112-
Attribute<NettyWebSocket> ws = ctx.attr(NettyWebSocket.KEY);
112+
Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY);
113113
if (ws != null && ws.get() != null) {
114114
ws.get().handle(cause);
115115
} else {
116-
log.error("execution of: " + ctx.attr(PATH).get() + " resulted in error", cause);
116+
log.error("execution of: " + ctx.channel().attr(PATH).get() + " resulted in error", cause);
117117
}
118118
}
119119
} finally {

jooby-netty/src/main/java/org/jooby/internal/netty/NettyRequest.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ public NettyRequest(final ChannelHandlerContext ctx, final HttpRequest req, fina
9797
this.query = new QueryStringDecoder(req.uri());
9898
this.path = URLDecoder.decode(query.path(), "UTF-8");
9999
this.wsMaxMessageSize = wsMaxMessageSize;
100-
ctx.attr(ASYNC).set(false);
100+
ctx.channel().attr(ASYNC).set(false);
101101
}
102102

103103
@Override
@@ -203,7 +203,7 @@ public <T> T upgrade(final Class<T> type) throws Exception {
203203
.addListener(payload -> ws.connect())
204204
.addListener(FIRE_EXCEPTION_ON_FAILURE);
205205
});
206-
ctx.attr(NettyWebSocket.KEY).set(result);
206+
ctx.channel().attr(NettyWebSocket.KEY).set(result);
207207
return (T) result;
208208
} else if (type == Sse.class) {
209209
NettySse sse = new NettySse(ctx);
@@ -214,8 +214,8 @@ public <T> T upgrade(final Class<T> type) throws Exception {
214214

215215
@Override
216216
public void startAsync() {
217-
ctx.attr(NEED_FLUSH).set(false);
218-
ctx.attr(ASYNC).set(true);
217+
ctx.channel().attr(NEED_FLUSH).set(false);
218+
ctx.channel().attr(ASYNC).set(true);
219219
}
220220

221221
private org.jooby.Cookie cookie(final Cookie c) {

jooby-netty/src/main/java/org/jooby/internal/netty/NettyResponse.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ public void send(final InputStream stream) throws Exception {
130130
// dump headers
131131
rsp.headers().set(headers);
132132
ChannelHandlerContext ctx = this.ctx;
133-
ctx.attr(NettyRequest.NEED_FLUSH).set(false);
133+
ctx.channel().attr(NettyRequest.NEED_FLUSH).set(false);
134134

135135
// add chunker
136136
ChannelPipeline pipeline = ctx.pipeline();
@@ -170,7 +170,7 @@ public void send(final FileChannel channel) throws Exception {
170170
// dump headers
171171
rsp.headers().set(headers);
172172
ChannelHandlerContext ctx = this.ctx;
173-
ctx.attr(NettyRequest.NEED_FLUSH).set(false);
173+
ctx.channel().attr(NettyRequest.NEED_FLUSH).set(false);
174174
ctx.channel().eventLoop().execute(() -> {
175175
// send headers
176176
ctx.write(rsp);
@@ -196,7 +196,7 @@ private void send(final ByteBuf buffer) throws Exception {
196196
// dump headers
197197
rsp.headers().set(headers);
198198

199-
Attribute<Boolean> async = ctx.attr(NettyRequest.ASYNC);
199+
Attribute<Boolean> async = ctx.channel().attr(NettyRequest.ASYNC);
200200
boolean isAsync = async != null && async.get() == Boolean.TRUE;
201201
if (isAsync) {
202202
// we need flush, from async
@@ -237,7 +237,7 @@ public boolean committed() {
237237
@Override
238238
public void end() {
239239
if (ctx != null) {
240-
Attribute<NettyWebSocket> ws = ctx.attr(NettyWebSocket.KEY);
240+
Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY);
241241
if (ws != null && ws.get() != null) {
242242
status = HttpResponseStatus.SWITCHING_PROTOCOLS;
243243
ws.get().hankshake();

jooby-netty/src/main/java/org/jooby/internal/netty/NettyWebSocket.java

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,6 @@
2020

2121
import static io.netty.channel.ChannelFutureListener.FIRE_EXCEPTION_ON_FAILURE;
2222
import static java.util.Objects.requireNonNull;
23-
import io.netty.buffer.ByteBuf;
24-
import io.netty.buffer.Unpooled;
25-
import io.netty.channel.ChannelConfig;
26-
import io.netty.channel.ChannelHandlerContext;
27-
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
28-
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
29-
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
30-
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
31-
import io.netty.util.Attribute;
32-
import io.netty.util.AttributeKey;
33-
import io.netty.util.concurrent.Future;
34-
import io.netty.util.concurrent.GenericFutureListener;
3523

3624
import java.io.IOException;
3725
import java.nio.ByteBuffer;
@@ -47,6 +35,19 @@
4735
import org.slf4j.Logger;
4836
import org.slf4j.LoggerFactory;
4937

38+
import io.netty.buffer.ByteBuf;
39+
import io.netty.buffer.Unpooled;
40+
import io.netty.channel.ChannelConfig;
41+
import io.netty.channel.ChannelHandlerContext;
42+
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
43+
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
44+
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
45+
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
46+
import io.netty.util.Attribute;
47+
import io.netty.util.AttributeKey;
48+
import io.netty.util.concurrent.Future;
49+
import io.netty.util.concurrent.GenericFutureListener;
50+
5051
public class NettyWebSocket implements NativeWebSocket {
5152

5253
public static final AttributeKey<NettyWebSocket> KEY =
@@ -84,7 +85,7 @@ public NettyWebSocket(final ChannelHandlerContext ctx,
8485
public void close(final int status, final String reason) {
8586
handshaker.close(ctx.channel(), new CloseWebSocketFrame(status, reason))
8687
.addListener(FIRE_EXCEPTION_ON_FAILURE);
87-
Attribute<NettyWebSocket> ws = ctx.attr(KEY);
88+
Attribute<NettyWebSocket> ws = ctx.channel().attr(KEY);
8889
if (ws != null) {
8990
ws.remove();
9091
}

0 commit comments

Comments
 (0)