Fix a NoSuchElementException when WebSocketClientHandshaker is used with HttpRequestEncoder. This time for real

This commit is contained in:
Norman Maurer 2013-03-11 14:39:18 +01:00
parent 978cf0d98a
commit acde9a3f8e

View File

@ -205,15 +205,21 @@ public abstract class WebSocketClientHandshaker {
setHandshakeComplete(); setHandshakeComplete();
ChannelPipeline p = channel.pipeline(); ChannelPipeline p = channel.pipeline();
ChannelHandlerContext ctx = p.context(HttpRequestEncoder.class); ChannelHandlerContext ctx = p.context(HttpResponseDecoder.class);
if (ctx == null) { if (ctx == null) {
ctx = p.context(HttpClientCodec.class); ctx = p.context(HttpClientCodec.class);
if (ctx == null) { if (ctx == null) {
throw new IllegalStateException("ChannelPipeline does not contain " + throw new IllegalStateException("ChannelPipeline does not contain " +
"a HttpRequestEncoder or HttpClientCodec"); "a HttpRequestEncoder or HttpClientCodec");
} }
p.replaceAndForward(ctx.name(), "ws-decoder", newWebsocketDecoder());
} else {
if (p.get(HttpRequestEncoder.class) != null) {
p.remove(HttpRequestEncoder.class);
}
p.replaceAndForward(ctx.name(),
"ws-decoder", newWebsocketDecoder());
} }
p.replaceAndForward(ctx.name(), "ws-decoder", newWebsocketDecoder());
} }
/** /**