X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Fwebsockets%2Fclient%2FWebSocketClientHandler.java;fp=opendaylight%2Fmd-sal%2Fsal-rest-connector%2Fsrc%2Ftest%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fsal%2Frestconf%2Fimpl%2Fwebsockets%2Fclient%2FWebSocketClientHandler.java;h=0000000000000000000000000000000000000000;hb=89b8b59cd26fd4810293ff14386eb29a71da9fac;hp=e07d8c48f0f2c9ba253a1282f4bf0e453ae19e3f;hpb=9ba2b4eca79bcc0e78099b133296801c8d45a6c4;p=controller.git diff --git a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/client/WebSocketClientHandler.java b/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/client/WebSocketClientHandler.java deleted file mode 100644 index e07d8c48f0..0000000000 --- a/opendaylight/md-sal/sal-rest-connector/src/test/java/org/opendaylight/controller/sal/restconf/impl/websockets/client/WebSocketClientHandler.java +++ /dev/null @@ -1,92 +0,0 @@ -/* - * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved. - * - * This program and the accompanying materials are made available under the - * terms of the Eclipse Public License v1.0 which accompanies this distribution, - * and is available at http://www.eclipse.org/legal/epl-v10.html - */ -package org.opendaylight.controller.sal.restconf.impl.websockets.client; - -import io.netty.channel.Channel; -import io.netty.channel.ChannelFuture; -import io.netty.channel.ChannelHandlerContext; -import io.netty.channel.ChannelPromise; -import io.netty.channel.SimpleChannelInboundHandler; -import io.netty.handler.codec.http.FullHttpResponse; -import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame; -import io.netty.handler.codec.http.websocketx.PongWebSocketFrame; -import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker; -import io.netty.handler.codec.http.websocketx.WebSocketFrame; -import io.netty.util.CharsetUtil; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class WebSocketClientHandler extends SimpleChannelInboundHandler { - - private static final Logger logger = LoggerFactory.getLogger(WebSocketClientHandler.class.toString()); - private final WebSocketClientHandshaker handshaker; - private ChannelPromise handshakeFuture; - private final IClientMessageCallback messageListener; - - public WebSocketClientHandler(WebSocketClientHandshaker handshaker, IClientMessageCallback listener) { - this.handshaker = handshaker; - this.messageListener = listener; - } - - public ChannelFuture handshakeFuture() { - return handshakeFuture; - } - - @Override - public void handlerAdded(ChannelHandlerContext ctx) throws Exception { - handshakeFuture = ctx.newPromise(); - } - - @Override - public void channelActive(ChannelHandlerContext ctx) throws Exception { - handshaker.handshake(ctx.channel()); - } - - @Override - public void channelInactive(ChannelHandlerContext ctx) throws Exception { - logger.info("WebSocket Client disconnected!"); - } - - @Override - public void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception { - Channel ch = ctx.channel(); - if (!handshaker.isHandshakeComplete()) { - handshaker.finishHandshake(ch, (FullHttpResponse) msg); - logger.info("WebSocket Client connected!"); - handshakeFuture.setSuccess(); - return; - } - - if (msg instanceof FullHttpResponse) { - FullHttpResponse response = (FullHttpResponse) msg; - throw new Exception("Unexpected FullHttpResponse (getStatus=" + response.getStatus() + ", content=" - + response.content().toString(CharsetUtil.UTF_8) + ')'); - } - - messageListener.onMessageReceived(msg); - WebSocketFrame frame = (WebSocketFrame) msg; - - if (frame instanceof PongWebSocketFrame) { - logger.info("WebSocket Client received pong"); - } else if (frame instanceof CloseWebSocketFrame) { - logger.info("WebSocket Client received closing"); - ch.close(); - } - } - - @Override - public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception { - cause.printStackTrace(); - - if (!handshakeFuture.isDone()) { - handshakeFuture.setFailure(cause); - } - - ctx.close(); - } -}