activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From clebertsuco...@apache.org
Subject [1/3] activemq-artemis git commit: ARTEMIS-228 accept binary WebSocket frames
Date Fri, 25 Sep 2015 18:53:54 GMT
Repository: activemq-artemis
Updated Branches:
  refs/heads/master 230aba76a -> 616f68372


ARTEMIS-228 accept binary WebSocket frames


Project: http://git-wip-us.apache.org/repos/asf/activemq-artemis/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq-artemis/commit/f64c4357
Tree: http://git-wip-us.apache.org/repos/asf/activemq-artemis/tree/f64c4357
Diff: http://git-wip-us.apache.org/repos/asf/activemq-artemis/diff/f64c4357

Branch: refs/heads/master
Commit: f64c43572730630916786d01daceec35a9341190
Parents: 230aba7
Author: Julian Scheid <julians37@gmail.com>
Authored: Fri Sep 25 14:10:20 2015 +0200
Committer: Clebert Suconic <clebertsuconic@apache.org>
Committed: Fri Sep 25 14:37:21 2015 -0400

----------------------------------------------------------------------
 .../protocol/stomp/WebSocketServerHandler.java  |   4 +-
 .../stomp/AbstractStompOverWebsocketTest.java   | 127 +++++++++++++++++++
 .../stomp/StompOverWebsocketBinaryTest.java     |  30 +++++
 .../stomp/StompOverWebsocketTest.java           | 127 -------------------
 .../stomp/StompOverWebsocketTextTest.java       |  27 ++++
 5 files changed, 186 insertions(+), 129 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f64c4357/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/WebSocketServerHandler.java
----------------------------------------------------------------------
diff --git a/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/WebSocketServerHandler.java
b/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/WebSocketServerHandler.java
index 92493fe..62c41d3 100644
--- a/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/WebSocketServerHandler.java
+++ b/artemis-server/src/main/java/org/apache/activemq/artemis/core/protocol/stomp/WebSocketServerHandler.java
@@ -110,7 +110,7 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
          ctx.writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
          return false;
       }
-      else if (!(frame instanceof TextWebSocketFrame)) {
+      else if (!(frame instanceof TextWebSocketFrame) && !(frame instanceof BinaryWebSocketFrame))
{
          throw new UnsupportedOperationException(String.format("%s frame types not supported",
frame.getClass().getName()));
       }
       return true;
@@ -153,4 +153,4 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
       }
 
    }
-}
\ No newline at end of file
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f64c4357/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/AbstractStompOverWebsocketTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/AbstractStompOverWebsocketTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/AbstractStompOverWebsocketTest.java
new file mode 100644
index 0000000..ba760fb
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/AbstractStompOverWebsocketTest.java
@@ -0,0 +1,127 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.stomp;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.nio.charset.StandardCharsets;
+
+import io.netty.channel.Channel;
+import io.netty.channel.ChannelDuplexHandler;
+import io.netty.channel.ChannelHandlerContext;
+import io.netty.channel.ChannelPromise;
+import io.netty.channel.socket.SocketChannel;
+import io.netty.handler.codec.http.FullHttpResponse;
+import io.netty.handler.codec.http.HttpClientCodec;
+import io.netty.handler.codec.http.HttpObjectAggregator;
+import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
+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.WebSocketClientHandshakerFactory;
+import io.netty.handler.codec.http.websocketx.WebSocketFrame;
+import io.netty.handler.codec.http.websocketx.WebSocketVersion;
+import io.netty.handler.codec.string.StringDecoder;
+
+public abstract class AbstractStompOverWebsocketTest extends StompTest {
+
+   private ChannelPromise handshakeFuture;
+
+   @Override
+   protected void addChannelHandlers(SocketChannel ch) throws URISyntaxException {
+      ch.pipeline().addLast("http-codec", new HttpClientCodec());
+      ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
+      ch.pipeline().addLast(new WebsocketHandler(WebSocketClientHandshakerFactory.newHandshaker(new
URI("ws://localhost:8080/websocket"), WebSocketVersion.V13, null, false, null)));
+      ch.pipeline().addLast("decoder", new StringDecoder(StandardCharsets.UTF_8));
+      ch.pipeline().addLast(new StompClientHandler());
+   }
+
+   @Override
+   protected void handshake() throws InterruptedException {
+      handshakeFuture.sync();
+   }
+
+   class WebsocketHandler extends ChannelDuplexHandler {
+
+      private WebSocketClientHandshaker handshaker;
+
+      public WebsocketHandler(WebSocketClientHandshaker webSocketClientHandshaker) {
+         this.handshaker = webSocketClientHandshaker;
+      }
+
+      @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 {
+         System.out.println("WebSocket Client disconnected!");
+      }
+
+      @Override
+      public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
+         Channel ch = ctx.channel();
+         if (!handshaker.isHandshakeComplete()) {
+            handshaker.finishHandshake(ch, (FullHttpResponse) msg);
+            System.out.println("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(StandardCharsets.UTF_8) + ')');
+         }
+
+         WebSocketFrame frame = (WebSocketFrame) msg;
+         if (frame instanceof BinaryWebSocketFrame) {
+            BinaryWebSocketFrame dataFrame = (BinaryWebSocketFrame) frame;
+            super.channelRead(ctx, dataFrame.content());
+         }
+         else if (frame instanceof PongWebSocketFrame) {
+            System.out.println("WebSocket Client received pong");
+         }
+         else if (frame instanceof CloseWebSocketFrame) {
+            System.out.println("WebSocket Client received closing");
+            ch.close();
+         }
+      }
+
+      @Override
+      public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws
Exception {
+         try {
+            if (msg instanceof String) {
+               ctx.write(createFrame((String) msg), promise);
+            }
+            else {
+               super.write(ctx, msg, promise);
+            }
+         }
+         catch (Exception e) {
+            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
+         }
+      }
+   }
+
+   abstract WebSocketFrame createFrame(String msg);
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f64c4357/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketBinaryTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketBinaryTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketBinaryTest.java
new file mode 100644
index 0000000..f0d3782
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketBinaryTest.java
@@ -0,0 +1,30 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.stomp;
+
+import java.nio.charset.Charset;
+
+import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
+import io.netty.handler.codec.http.websocketx.WebSocketFrame;
+import io.netty.buffer.Unpooled;
+
+public class StompOverWebsocketBinaryTest extends AbstractStompOverWebsocketTest {
+
+   protected WebSocketFrame createFrame(String msg) {
+      return new BinaryWebSocketFrame(Unpooled.copiedBuffer(msg, Charset.forName("UTF-8")));
+   }
+}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f64c4357/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java
deleted file mode 100644
index 38e9e69..0000000
--- a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTest.java
+++ /dev/null
@@ -1,127 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- *     http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.activemq.artemis.tests.integration.stomp;
-
-import java.net.URI;
-import java.net.URISyntaxException;
-import java.nio.charset.StandardCharsets;
-
-import io.netty.channel.Channel;
-import io.netty.channel.ChannelDuplexHandler;
-import io.netty.channel.ChannelHandlerContext;
-import io.netty.channel.ChannelPromise;
-import io.netty.channel.socket.SocketChannel;
-import io.netty.handler.codec.http.FullHttpResponse;
-import io.netty.handler.codec.http.HttpClientCodec;
-import io.netty.handler.codec.http.HttpObjectAggregator;
-import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
-import io.netty.handler.codec.http.websocketx.WebSocketClientHandshaker;
-import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
-import io.netty.handler.codec.http.websocketx.WebSocketFrame;
-import io.netty.handler.codec.http.websocketx.WebSocketVersion;
-import io.netty.handler.codec.string.StringDecoder;
-
-public class StompOverWebsocketTest extends StompTest {
-
-   private ChannelPromise handshakeFuture;
-
-   @Override
-   protected void addChannelHandlers(SocketChannel ch) throws URISyntaxException {
-      ch.pipeline().addLast("http-codec", new HttpClientCodec());
-      ch.pipeline().addLast("aggregator", new HttpObjectAggregator(8192));
-      ch.pipeline().addLast(new WebsocketHandler(WebSocketClientHandshakerFactory.newHandshaker(new
URI("ws://localhost:8080/websocket"), WebSocketVersion.V13, null, false, null)));
-      ch.pipeline().addLast("decoder", new StringDecoder(StandardCharsets.UTF_8));
-      ch.pipeline().addLast(new StompClientHandler());
-   }
-
-   @Override
-   protected void handshake() throws InterruptedException {
-      handshakeFuture.sync();
-   }
-
-   class WebsocketHandler extends ChannelDuplexHandler {
-
-      private WebSocketClientHandshaker handshaker;
-
-      public WebsocketHandler(WebSocketClientHandshaker webSocketClientHandshaker) {
-         this.handshaker = webSocketClientHandshaker;
-      }
-
-      @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 {
-         System.out.println("WebSocket Client disconnected!");
-      }
-
-      @Override
-      public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
-         Channel ch = ctx.channel();
-         if (!handshaker.isHandshakeComplete()) {
-            handshaker.finishHandshake(ch, (FullHttpResponse) msg);
-            System.out.println("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(StandardCharsets.UTF_8) + ')');
-         }
-
-         WebSocketFrame frame = (WebSocketFrame) msg;
-         if (frame instanceof BinaryWebSocketFrame) {
-            BinaryWebSocketFrame dataFrame = (BinaryWebSocketFrame) frame;
-            super.channelRead(ctx, dataFrame.content());
-         }
-         else if (frame instanceof PongWebSocketFrame) {
-            System.out.println("WebSocket Client received pong");
-         }
-         else if (frame instanceof CloseWebSocketFrame) {
-            System.out.println("WebSocket Client received closing");
-            ch.close();
-         }
-      }
-
-      @Override
-      public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws
Exception {
-         try {
-            if (msg instanceof String) {
-               TextWebSocketFrame frame = new TextWebSocketFrame((String) msg);
-               ctx.write(frame, promise);
-            }
-            else {
-               super.write(ctx, msg, promise);
-            }
-         }
-         catch (Exception e) {
-            e.printStackTrace();  //To change body of catch statement use File | Settings
| File Templates.
-         }
-      }
-   }
-}

http://git-wip-us.apache.org/repos/asf/activemq-artemis/blob/f64c4357/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTextTest.java
----------------------------------------------------------------------
diff --git a/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTextTest.java
b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTextTest.java
new file mode 100644
index 0000000..ac11d71
--- /dev/null
+++ b/tests/integration-tests/src/test/java/org/apache/activemq/artemis/tests/integration/stomp/StompOverWebsocketTextTest.java
@@ -0,0 +1,27 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.activemq.artemis.tests.integration.stomp;
+
+import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
+import io.netty.handler.codec.http.websocketx.WebSocketFrame;
+
+public class StompOverWebsocketTextTest extends AbstractStompOverWebsocketTest {
+
+   protected WebSocketFrame createFrame(String msg) {
+      return new TextWebSocketFrame(msg);
+   }
+}


Mime
View raw message