Skip to content

Commit

Permalink
ARTEMIS-5249 support WebSocket pong frames
Browse files Browse the repository at this point in the history
The broker should simply receive WebSocket pong frames and not respond
according to section 5.5.3 of RFC 6455 (i.e. the WebSocket Protocol
specification).
  • Loading branch information
jbertram authored and gemmellr committed Jan 21, 2025
1 parent 1ba0b65 commit 7c99a60
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,8 @@ private boolean handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame f
} else if (frame instanceof PingWebSocketFrame) {
ctx.writeAndFlush(new PongWebSocketFrame(frame.content().retain()));
return false;
} else if (frame instanceof PongWebSocketFrame) {
return false;
} else if (!(frame instanceof TextWebSocketFrame) && !(frame instanceof BinaryWebSocketFrame) && !(frame instanceof ContinuationWebSocketFrame)) {
throw new UnsupportedOperationException(String.format("%s frame types not supported", frame.getClass().getName()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,25 @@
*/
package org.apache.activemq.artemis.core.server.protocol.websocket;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

import java.util.Arrays;
import java.util.List;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.handler.codec.http.websocketx.BinaryWebSocketFrame;
import io.netty.handler.codec.http.websocketx.ContinuationWebSocketFrame;
import io.netty.handler.codec.http.websocketx.PongWebSocketFrame;
import io.netty.handler.codec.http.websocketx.TextWebSocketFrame;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.mockito.Mockito.any;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.verifyNoMoreInteractions;

/**
* WebSocketServerHandlerTest
Expand Down Expand Up @@ -76,6 +77,17 @@ public void testRead0HandleBinaryFrame() throws Exception {
verifyNoMoreInteractions(spy, ctx);
}

@Test
public void testRead0HandlePongFrame() throws Exception {
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
Object msg = new PongWebSocketFrame();

spy.channelRead0(ctx, msg);

verify(spy).channelRead0(ctx, msg);
verifyNoMoreInteractions(spy, ctx);
}

@Test
public void testRead0HandleTextFrame() throws Exception {
ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
Expand Down

0 comments on commit 7c99a60

Please sign in to comment.