diff --git a/jawampa-netty/pom.xml b/jawampa-netty/pom.xml index 51a3487..bc7d163 100644 --- a/jawampa-netty/pom.xml +++ b/jawampa-netty/pom.xml @@ -50,5 +50,10 @@ netty-codec-http 4.1.11.Final + + io.netty + netty-handler + 4.1.11.Final + diff --git a/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/NettyWampClientConnectorProvider.java b/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/NettyWampClientConnectorProvider.java index 908cb1e..e791b61 100644 --- a/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/NettyWampClientConnectorProvider.java +++ b/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/NettyWampClientConnectorProvider.java @@ -57,6 +57,7 @@ import io.netty.handler.codec.http.websocketx.WebSocketFrameAggregator; import io.netty.handler.codec.http.websocketx.WebSocketVersion; import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.InsecureTrustManagerFactory; /** @@ -109,7 +110,10 @@ public IWampConnector createConnector(final URI uri, if (needSsl && (nettyConfig == null || nettyConfig.sslContext() == null)) { // Create a default SslContext when we got none provided through the constructor try { - sslCtx0 = SslContext.newClientContext(InsecureTrustManagerFactory.INSTANCE); + sslCtx0 = + SslContextBuilder.forClient() + .trustManager(InsecureTrustManagerFactory.INSTANCE) + .build(); } catch (SSLException e) { throw e; @@ -175,7 +179,6 @@ public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws E // The transport closed before the websocket handshake was completed connectListener.connectFailed(cause); } - super.exceptionCaught(ctx, cause); } @Override diff --git a/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/SimpleWampWebsocketListener.java b/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/SimpleWampWebsocketListener.java index d2f29c8..23c45ca 100644 --- a/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/SimpleWampWebsocketListener.java +++ b/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/SimpleWampWebsocketListener.java @@ -41,13 +41,14 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpObjectAggregator; import io.netty.handler.codec.http.HttpServerCodec; +import io.netty.handler.codec.http.HttpUtil; import io.netty.handler.ssl.SslContext; +import io.netty.handler.ssl.SslContextBuilder; import io.netty.handler.ssl.util.SelfSignedCertificate; import io.netty.util.CharsetUtil; -import static io.netty.handler.codec.http.HttpHeaders.Names.*; +import static io.netty.handler.codec.http.HttpHeaderNames.*; import static io.netty.handler.codec.http.HttpMethod.*; import static io.netty.handler.codec.http.HttpResponseStatus.*; import static io.netty.handler.codec.http.HttpVersion.*; @@ -119,7 +120,10 @@ public void start() { if (uri.getScheme().equalsIgnoreCase("wss") && sslCtx == null) { // Use a self signed certificate when we got none provided through the constructor SelfSignedCertificate ssc = new SelfSignedCertificate(); - sslCtx = SslContext.newServerContext(ssc.certificate(), ssc.privateKey()); + sslCtx = + SslContextBuilder + .forServer(ssc.certificate(), ssc.privateKey()) + .build(); } // Use well-known ports if not explicitly specified @@ -199,17 +203,17 @@ public void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) { private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) { // Handle a bad request. - if (!req.getDecoderResult().isSuccess()) { + if (!req.decoderResult().isSuccess()) { sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, BAD_REQUEST)); return; } // Allow only GET methods. - if (req.getMethod() != GET) { + if (req.method() != GET) { sendHttpResponse(ctx, req, new DefaultFullHttpResponse(HTTP_1_1, FORBIDDEN)); return; } // Send the demo page and favicon.ico - if ("/".equals(req.getUri())) { + if ("/".equals(req.uri())) { ByteBuf content = Unpooled.copiedBuffer( "Wamp Router" + "

This server provides a wamp router on path " + @@ -218,11 +222,11 @@ private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) { , CharsetUtil.UTF_8); FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, OK, content); res.headers().set(CONTENT_TYPE, "text/html; charset=UTF-8"); - HttpHeaders.setContentLength(res, content.readableBytes()); + HttpUtil.setContentLength(res, content.readableBytes()); sendHttpResponse(ctx, req, res); return; } - if ("/favicon.ico".equals(req.getUri())) { + if ("/favicon.ico".equals(req.uri())) { FullHttpResponse res = new DefaultFullHttpResponse(HTTP_1_1, NOT_FOUND); sendHttpResponse(ctx, req, res); return; @@ -235,15 +239,15 @@ private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) { private static void sendHttpResponse( ChannelHandlerContext ctx, FullHttpRequest req, FullHttpResponse res) { // Generate an error page if response getStatus code is not OK (200). - if (res.getStatus().code() != 200) { - ByteBuf buf = Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8); + if (res.status().code() != 200) { + ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8); res.content().writeBytes(buf); buf.release(); - HttpHeaders.setContentLength(res, res.content().readableBytes()); + HttpUtil.setContentLength(res, res.content().readableBytes()); } // Send the response and close the connection if necessary. ChannelFuture f = ctx.channel().writeAndFlush(res); - if (!HttpHeaders.isKeepAlive(req) || res.getStatus().code() != 200) { + if (!HttpUtil.isKeepAlive(req) || res.status().code() != 200) { f.addListener(ChannelFutureListener.CLOSE); } } diff --git a/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/WampServerWebsocketHandler.java b/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/WampServerWebsocketHandler.java index e011701..3c598c3 100644 --- a/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/WampServerWebsocketHandler.java +++ b/jawampa-netty/src/main/java/ws/wamp/jawampa/transport/netty/WampServerWebsocketHandler.java @@ -27,6 +27,8 @@ import io.netty.handler.codec.http.DefaultFullHttpResponse; import io.netty.handler.codec.http.FullHttpRequest; import io.netty.handler.codec.http.FullHttpResponse; +import io.netty.handler.codec.http.HttpHeaderNames; +import io.netty.handler.codec.http.HttpHeaderValues; import io.netty.handler.codec.http.HttpHeaders; import io.netty.handler.codec.http.HttpResponseStatus; import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; @@ -37,8 +39,8 @@ import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker; import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory; import io.netty.handler.ssl.SslHandler; +import io.netty.util.AsciiString; import io.netty.util.ReferenceCountUtil; -import io.netty.util.internal.StringUtil; import ws.wamp.jawampa.WampSerialization; import ws.wamp.jawampa.WampMessages.WampMessage; import ws.wamp.jawampa.connection.IWampConnection; @@ -48,7 +50,7 @@ import java.util.List; -import static io.netty.handler.codec.http.HttpHeaders.Names.*; +import static io.netty.handler.codec.http.HttpHeaderNames.*; import static io.netty.handler.codec.http.HttpVersion.*; /** @@ -101,18 +103,23 @@ public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception } private boolean isUpgradeRequest(FullHttpRequest request) { - if (!request.getDecoderResult().isSuccess()) { + if (!request.decoderResult().isSuccess()) { return false; } - String connectionHeaderValue = request.headers().get(HttpHeaders.Names.CONNECTION); + CharSequence connectionHeaderValue = + request.headers().get(HttpHeaderNames.CONNECTION); if (connectionHeaderValue == null) { return false; } - String[] connectionHeaderFields = connectionHeaderValue.toLowerCase().split(","); + AsciiString connectionHeaderString = + new AsciiString(connectionHeaderValue); + AsciiString[] connectionHeaderFields = + connectionHeaderString.toLowerCase().split(','); boolean hasUpgradeField = false; - for (String s : connectionHeaderFields) { - if (s.trim().equals(HttpHeaders.Values.UPGRADE.toLowerCase())) { + AsciiString upgradeValue = HttpHeaderValues.UPGRADE.toLowerCase(); + for (AsciiString s : connectionHeaderFields) { + if (upgradeValue.equals(s.trim())) { hasUpgradeField = true; break; } @@ -121,11 +128,12 @@ private boolean isUpgradeRequest(FullHttpRequest request) { return false; } - if (!request.headers().contains(HttpHeaders.Names.UPGRADE, HttpHeaders.Values.WEBSOCKET, true)){ + if (!request.headers().contains( + HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET, true)) { return false; } - return request.getUri().equals(websocketPath); + return request.uri().equals(websocketPath); } // All methods inside the connection will be called from the WampRouters thread