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())); ctx.writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
return false; 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())); throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass().getName()));
} }
return true; return true;

View File

@ -18,8 +18,13 @@ package org.apache.activemq.artemis.tests.integration.stomp;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets; 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.Channel;
import io.netty.channel.ChannelDuplexHandler; import io.netty.channel.ChannelDuplexHandler;
import io.netty.channel.ChannelHandlerContext; 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.WebSocketFrame;
import io.netty.handler.codec.http.websocketx.WebSocketVersion; import io.netty.handler.codec.http.websocketx.WebSocketVersion;
import io.netty.handler.codec.string.StringDecoder; 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 { public class StompOverWebsocketTest extends StompTest {
private ChannelPromise handshakeFuture; 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 @Override
protected void addChannelHandlers(SocketChannel ch) throws URISyntaxException { protected void addChannelHandlers(SocketChannel ch) throws URISyntaxException {
ch.pipeline().addLast("http-codec", new HttpClientCodec()); 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 { public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception {
try { try {
if (msg instanceof String) { if (msg instanceof String) {
TextWebSocketFrame frame = new TextWebSocketFrame((String) msg); ctx.write(createFrame((String) msg), promise);
ctx.write(frame, promise);
} }
else { else {
super.write(ctx, msg, promise); 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);
}
}
} }