ARTEMIS-228 accept binary WebSocket frames
This commit is contained in:
parent
230aba76a2
commit
f64c435727
|
@ -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;
|
||||||
|
@ -153,4 +153,4 @@ public class WebSocketServerHandler extends SimpleChannelInboundHandler<Object>
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,14 +31,13 @@ import io.netty.handler.codec.http.HttpObjectAggregator;
|
||||||
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
|
import io.netty.handler.codec.http.websocketx.CloseWebSocketFrame;
|
||||||
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
|
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.WebSocketClientHandshaker;
|
||||||
import io.netty.handler.codec.http.websocketx.WebSocketClientHandshakerFactory;
|
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;
|
||||||
|
|
||||||
public class StompOverWebsocketTest extends StompTest {
|
public abstract class AbstractStompOverWebsocketTest extends StompTest {
|
||||||
|
|
||||||
private ChannelPromise handshakeFuture;
|
private ChannelPromise handshakeFuture;
|
||||||
|
|
||||||
|
@ -112,8 +111,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 +122,6 @@ public class StompOverWebsocketTest extends StompTest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract WebSocketFrame createFrame(String msg);
|
||||||
}
|
}
|
|
@ -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")));
|
||||||
|
}
|
||||||
|
}
|
|
@ -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);
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue