This closes #176

This commit is contained in:
Clebert Suconic 2015-09-25 14:49:18 -04:00
commit 616f68372b
2 changed files with 35 additions and 4 deletions

View File

@ -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>
}
}
}
}

View File

@ -18,8 +18,13 @@ package org.apache.activemq.artemis.tests.integration.stomp;
import java.net.URI;
import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;
import io.netty.buffer.Unpooled;
import io.netty.channel.Channel;
import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext;
@ -37,11 +42,27 @@ 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;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
@RunWith(Parameterized.class)
public class StompOverWebsocketTest extends StompTest {
private ChannelPromise handshakeFuture;
private final boolean useBinaryFrames;
@Parameterized.Parameters(name = "useBinaryFrames={0}")
public static Collection<Object[]> data() {
List<Object[]> list = Arrays.asList(new Object[][]{{Boolean.TRUE}, {Boolean.FALSE}});
return list;
}
public StompOverWebsocketTest(Boolean useBinaryFrames) {
super();
this.useBinaryFrames = useBinaryFrames;
}
@Override
protected void addChannelHandlers(SocketChannel ch) throws URISyntaxException {
ch.pipeline().addLast("http-codec", new HttpClientCodec());
@ -112,8 +133,7 @@ public class StompOverWebsocketTest extends StompTest {
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);
ctx.write(createFrame((String) msg), promise);
}
else {
super.write(ctx, msg, promise);
@ -124,4 +144,15 @@ public class StompOverWebsocketTest extends StompTest {
}
}
}
protected WebSocketFrame createFrame(String msg) {
if (useBinaryFrames) {
return new BinaryWebSocketFrame(Unpooled.copiedBuffer(msg, Charset.forName("UTF-8")));
}
else {
return new TextWebSocketFrame(msg);
}
}
}