List of usage examples for io.netty.handler.codec.http HttpResponseStatus SWITCHING_PROTOCOLS
HttpResponseStatus SWITCHING_PROTOCOLS
To view the source code for io.netty.handler.codec.http HttpResponseStatus SWITCHING_PROTOCOLS.
Click Source Link
From source file:org.jboss.aerogear.simplepush.server.netty.SimplePushSockJSServiceTest.java
License:Apache License
@Test public void websocketUpgradeRequest() throws Exception { final EmbeddedChannel channel = createChannel(factory); final HttpResponse response = websocketHttpUpgradeRequest(sessionUrl, channel); assertThat(response.getStatus(), is(HttpResponseStatus.SWITCHING_PROTOCOLS)); assertThat(response.headers().get(HttpHeaders.Names.UPGRADE), equalTo("websocket")); assertThat(response.headers().get(HttpHeaders.Names.CONNECTION), equalTo("Upgrade")); assertThat(response.headers().get(Names.SEC_WEBSOCKET_ACCEPT), equalTo("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")); channel.close();// w w w.j a va2 s . c om }
From source file:org.jboss.aerogear.simplepush.server.netty.SimplePushSockJSServiceTest.java
License:Apache License
@Test public void rawWebSocketUpgradeRequest() throws Exception { final SimplePushServerConfig simplePushConfig = DefaultSimplePushConfig.create().password("test").build(); final SockJsConfig sockjsConf = SockJsConfig.withPrefix("/simplepush") .webSocketProtocols("push-notification").build(); final byte[] privateKey = CryptoUtil.secretKey(simplePushConfig.password(), "someSaltForTesting".getBytes()); final SimplePushServer pushServer = new DefaultSimplePushServer(new InMemoryDataStore(), simplePushConfig, privateKey);/*from w w w . j ava 2 s .c o m*/ final SimplePushServiceFactory factory = new SimplePushServiceFactory(sockjsConf, pushServer); final EmbeddedChannel channel = createChannel(factory); final FullHttpRequest request = websocketUpgradeRequest( factory.config().prefix() + Transports.Type.WEBSOCKET.path()); request.headers().set(Names.SEC_WEBSOCKET_PROTOCOL, "push-notification"); channel.writeInbound(request); final FullHttpResponse response = decodeFullHttpResponse(channel); assertThat(response.getStatus(), is(HttpResponseStatus.SWITCHING_PROTOCOLS)); assertThat(response.headers().get(HttpHeaders.Names.UPGRADE), equalTo("websocket")); assertThat(response.headers().get(HttpHeaders.Names.CONNECTION), equalTo("Upgrade")); assertThat(response.headers().get(Names.SEC_WEBSOCKET_PROTOCOL), equalTo("push-notification")); assertThat(response.headers().get(Names.SEC_WEBSOCKET_ACCEPT), equalTo("s3pPLMBiTxaQ9kYGzzhZRbK+xOo=")); channel.close(); }
From source file:org.jooby.internal.netty.NettyResponse.java
License:Apache License
@Override public void end() { if (ctx != null) { Attribute<NettyWebSocket> ws = ctx.channel().attr(NettyWebSocket.KEY); if (ws != null && ws.get() != null) { status = HttpResponseStatus.SWITCHING_PROTOCOLS; ws.get().hankshake();//from www .ja va 2s.com ctx = null; committed = true; return; } if (!committed) { DefaultHttpResponse rsp = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, status); // dump headers rsp.headers().set(headers); keepAlive(ctx.write(rsp)); } committed = true; ctx = null; } }