Home / Class/ WebSocketServerHandshakerTest Class — netty Architecture

WebSocketServerHandshakerTest Class — netty Architecture

Architecture documentation for the WebSocketServerHandshakerTest class in WebSocketServerHandshakerTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  4971cbc5_410e_2355_1704_f949800b95fc["WebSocketServerHandshakerTest"]
  95292bc6_c071_8a41_479c_666cdde53d5f["WebSocketServerHandshakerTest.java"]
  4971cbc5_410e_2355_1704_f949800b95fc -->|defined in| 95292bc6_c071_8a41_479c_666cdde53d5f
  7e014a28_6e4b_c19c_b2c7_70f1ac96b3fb["WebSocketServerHandshaker()"]
  4971cbc5_410e_2355_1704_f949800b95fc -->|method| 7e014a28_6e4b_c19c_b2c7_70f1ac96b3fb
  00108660_9234_0f36_78ec_e28a0a64a6e9["WebSocketVersion()"]
  4971cbc5_410e_2355_1704_f949800b95fc -->|method| 00108660_9234_0f36_78ec_e28a0a64a6e9
  d1d44bec_ad1b_542c_2d51_c2ae47daafa1["testDuplicateHandshakeResponseHeaders()"]
  4971cbc5_410e_2355_1704_f949800b95fc -->|method| d1d44bec_ad1b_542c_2d51_c2ae47daafa1
  7692aa17_7240_e214_e3b8_46d08462a73b["testWebSocketServerHandshakeException()"]
  4971cbc5_410e_2355_1704_f949800b95fc -->|method| 7692aa17_7240_e214_e3b8_46d08462a73b
  2d9a7b93_82f5_2f86_b59b_e9d9b313f68d["testHandshakeForHttpRequestWithoutAggregator()"]
  4971cbc5_410e_2355_1704_f949800b95fc -->|method| 2d9a7b93_82f5_2f86_b59b_e9d9b313f68d

Relationship Graph

Source Code

codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerTest.java lines 45–180

public abstract class WebSocketServerHandshakerTest {

    protected abstract WebSocketServerHandshaker newHandshaker(String webSocketURL, String subprotocols,
                                                               WebSocketDecoderConfig decoderConfig);

    protected abstract WebSocketVersion webSocketVersion();

    @Test
    public void testDuplicateHandshakeResponseHeaders() {
        WebSocketServerHandshaker serverHandshaker = newHandshaker("ws://example.com/chat",
                                                                   "chat", WebSocketDecoderConfig.DEFAULT);
        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/chat");
        request.headers()
               .set(HttpHeaderNames.HOST, "example.com")
               .set(HttpHeaderNames.ORIGIN, "example.com")
               .set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET)
               .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
               .set(HttpHeaderNames.SEC_WEBSOCKET_KEY, "dGhlIHNhbXBsZSBub25jZQ==")
               .set(HttpHeaderNames.SEC_WEBSOCKET_ORIGIN, "http://example.com")
               .set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "chat, superchat")
               .set(HttpHeaderNames.WEBSOCKET_PROTOCOL, "chat, superchat")
               .set(HttpHeaderNames.SEC_WEBSOCKET_VERSION, webSocketVersion().toAsciiString());
        HttpHeaders customResponseHeaders = new DefaultHttpHeaders();
        // set duplicate required headers and one custom
        customResponseHeaders
                .set(HttpHeaderNames.CONNECTION, HttpHeaderValues.UPGRADE)
                .set(HttpHeaderNames.UPGRADE, HttpHeaderValues.WEBSOCKET)
                .set(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL, "superchat")
                .set(HttpHeaderNames.WEBSOCKET_PROTOCOL, "superchat")
                .set("custom", "header");

        if (webSocketVersion() != WebSocketVersion.V00) {
            customResponseHeaders.set(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, "12345");
        }

        FullHttpResponse response = null;
        try {
            response = serverHandshaker.newHandshakeResponse(request, customResponseHeaders);
            HttpHeaders responseHeaders = response.headers();

            assertEquals(1, responseHeaders.getAll(HttpHeaderNames.CONNECTION).size());
            assertEquals(1, responseHeaders.getAll(HttpHeaderNames.UPGRADE).size());
            assertTrue(responseHeaders.containsValue("custom", "header", true));

            if (webSocketVersion() != WebSocketVersion.V00) {
                assertFalse(responseHeaders.containsValue(HttpHeaderNames.SEC_WEBSOCKET_ACCEPT, "12345", false));
                assertEquals(1, responseHeaders.getAll(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL).size());
                assertEquals("chat", responseHeaders.get(HttpHeaderNames.SEC_WEBSOCKET_PROTOCOL));
            } else {
                assertEquals(1, responseHeaders.getAll(HttpHeaderNames.WEBSOCKET_PROTOCOL).size());
                assertEquals("chat", responseHeaders.get(HttpHeaderNames.WEBSOCKET_PROTOCOL));
            }
        } finally {
            request.release();
            if (response != null) {
                response.release();
            }
        }
    }

    @Test
    public void testWebSocketServerHandshakeException() {
        WebSocketServerHandshaker serverHandshaker = newHandshaker("ws://example.com/chat",
                                                                   "chat", WebSocketDecoderConfig.DEFAULT);

        FullHttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET,
                                                             "ws://example.com/chat");
        request.headers().set("x-client-header", "value");
        try {
            serverHandshaker.handshake(null, request, null, null);
        } catch (WebSocketServerHandshakeException exception) {
            assertNotNull(exception.getMessage());
            assertEquals(request.headers(), exception.request().headers());
            assertEquals(HttpMethod.GET, exception.request().method());
        } finally {
            request.release();
        }
    }

    @Test
    public void testHandshakeForHttpRequestWithoutAggregator() {

Frequently Asked Questions

What is the WebSocketServerHandshakerTest class?
WebSocketServerHandshakerTest is a class in the netty codebase, defined in codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerTest.java.
Where is WebSocketServerHandshakerTest defined?
WebSocketServerHandshakerTest is defined in codec-http/src/test/java/io/netty/handler/codec/http/websocketx/WebSocketServerHandshakerTest.java at line 45.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free