I am trying to establish a web socket communication behind my corporate proxy. I can see that the proxy connection between my proxy server and remote host established and get back handshake response. After that when I try to send a message I get the exception.
Here is my channel init
Bootstrap b = new Bootstrap();
b.group(group).channel(NioSocketChannel.class).handler(new ChannelInitializer<SocketChannel>() {
@Override
protected void initChannel(SocketChannel ch) {
ChannelPipeline p = ch.pipeline();
if (sslCtx != null) {
p.addFirst("ssl", sslCtx.newHandler(ch.alloc(), host, port));
}
if(proxyHandler != null){
p.addFirst("proxyHandler", proxyHandler);
}
p.addLast(new LoggingHandler(LogLevel.DEBUG));
p.addLast("clientCodec", new HttpClientCodec());
p.addLast("decoder", new HttpRequestDecoder());
p.addLast("aggregator", new HttpObjectAggregator(65536));
p.addLast("encoder", new HttpResponseEncoder());
p.addLast(handler);
}
});
And exception is
io.netty.handler.codec.CorruptedFrameException: data frame using reserved opcode 7 at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.protocolViolation(WebSocket08FrameDecoder.java:412) at io.netty.handler.codec.http.websocketx.WebSocket08FrameDecoder.decode(WebSocket08FrameDecoder.java:229) at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:411) at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:248) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:351) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelRead(DefaultChannelPipeline.java:1334) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:373) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:359) at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:926) at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:129) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:651) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:574) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:488) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:450) at io.netty.util.concurrent.SingleThreadEventExecutor$5.run(SingleThreadEventExecutor.java:873) at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:144) at java.lang.Thread.run(Thread.java:745) WebSocket Client disconnected!
I have run into the same issue and found out that this issue appears as a result of the WebSocket upgrade operation as reported here: WebSocket upgrade wrecks HttpProxyHandler. Leaving a note in case anyone has the same problem.
The important part quoted:
Short story: WebSocketClientHandshaker reorganizes the Pipeline after receiving the upgrade from the server. If there is an HttpProxyHandler in the Pipeline, it has installed its own HttpClientCodec which gets wrecked by WebSocketClientHandshaker.
HttpClientCodec#0 <-- #finishHandshake hit this one. ws-decoder <-- We don't want this here. ws-encoder <-- We don't want this here. Http11ProxyHandler#0 SslHandler#0 HttpClientCodec#1 <-- ws-xxcoder should appear here. DownendChannelHandler#0 <-- My own stuff.
It seems there is no fix yet so one may need to hack into the WebSocketClientHandshaker or the post references kind of a workaround.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With