X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=restconf%2Frestconf-nb-rfc8040%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Frestconf%2Fnb%2Frfc8040%2Fstreams%2Fwebsockets%2FWebSocketServerHandler.java;h=697b220b8e6a25632d633036fa6cb1d38afef53e;hb=64544c4858ed3510c1c94f9969683b6a76b5b060;hp=55aacdaee809052c9a91119dac63fe233509f817;hpb=df1a4dbb37e0fb187c6d50d3bab1f9d88b888928;p=netconf.git diff --git a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/websockets/WebSocketServerHandler.java b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/websockets/WebSocketServerHandler.java index 55aacdaee8..697b220b8e 100755 --- a/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/websockets/WebSocketServerHandler.java +++ b/restconf/restconf-nb-rfc8040/src/main/java/org/opendaylight/restconf/nb/rfc8040/streams/websockets/WebSocketServerHandler.java @@ -8,12 +8,13 @@ package org.opendaylight.restconf.nb.rfc8040.streams.websockets; -import static io.netty.handler.codec.http.HttpHeaders.isKeepAlive; -import static io.netty.handler.codec.http.HttpHeaders.setContentLength; +import static io.netty.handler.codec.http.HttpHeaderNames.HOST; import static io.netty.handler.codec.http.HttpMethod.GET; import static io.netty.handler.codec.http.HttpResponseStatus.BAD_REQUEST; import static io.netty.handler.codec.http.HttpResponseStatus.FORBIDDEN; import static io.netty.handler.codec.http.HttpResponseStatus.INTERNAL_SERVER_ERROR; +import static io.netty.handler.codec.http.HttpUtil.isKeepAlive; +import static io.netty.handler.codec.http.HttpUtil.setContentLength; import static io.netty.handler.codec.http.HttpVersion.HTTP_1_1; import io.netty.buffer.ByteBuf; @@ -25,7 +26,6 @@ import io.netty.channel.SimpleChannelInboundHandler; 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.Names; import io.netty.handler.codec.http.HttpRequest; import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; import io.netty.handler.codec.http.websocketx.PingWebSocketFrame; @@ -64,25 +64,23 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler /** * Checks if HTTP request method is GET and if is possible to decode HTTP result of request. * - * @param ctx - * ChannelHandlerContext - * @param req - * FullHttpRequest + * @param ctx ChannelHandlerContext + * @param req FullHttpRequest */ private void handleHttpRequest(final ChannelHandlerContext ctx, final 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; } - final String streamName = Notificator.createStreamNameFromUri(req.getUri()); + final String streamName = Notificator.createStreamNameFromUri(req.uri()); if (streamName.contains(RestconfConstants.DATA_SUBSCR)) { final ListenerAdapter listener = Notificator.getListenerFor(streamName); if (listener != null) { @@ -121,18 +119,15 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler /** * Checks response status, send response and close connection if necessary. * - * @param ctx - * ChannelHandlerContext - * @param req - * HttpRequest - * @param res - * FullHttpResponse + * @param ctx ChannelHandlerContext + * @param req HttpRequest + * @param res FullHttpResponse */ private static void sendHttpResponse(final ChannelHandlerContext ctx, final HttpRequest req, final FullHttpResponse res) { // Generate an error page if response getStatus code is not OK (200). - if (res.getStatus().code() != 200) { - final ByteBuf buf = Unpooled.copiedBuffer(res.getStatus().toString(), CharsetUtil.UTF_8); + if (res.status().code() != 200) { + final ByteBuf buf = Unpooled.copiedBuffer(res.status().toString(), CharsetUtil.UTF_8); res.content().writeBytes(buf); buf.release(); setContentLength(res, res.content().readableBytes()); @@ -140,7 +135,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler // Send the response and close the connection if necessary. final ChannelFuture f = ctx.channel().writeAndFlush(res); - if (!isKeepAlive(req) || res.getStatus().code() != 200) { + if (!isKeepAlive(req) || res.status().code() != 200) { f.addListener(ChannelFutureListener.CLOSE); } } @@ -187,12 +182,10 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler /** * Get web socket location from HTTP request. * - * @param req - * HTTP request from which the location will be returned + * @param req HTTP request from which the location will be returned * @return String representation of web socket location. */ private static String getWebSocketLocation(final HttpRequest req) { - return "ws://" + req.headers().get(Names.HOST) + req.getUri(); + return "ws://" + req.headers().get(HOST) + req.uri(); } - }