Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Following exception thrown when try to write DefaultHttpRequest to same channel after receiving response for the previous request in netty4.0.6 final #1700

Closed
ghost opened this issue Aug 5, 2013 · 6 comments

Comments

@ghost
Copy link

ghost commented Aug 5, 2013

Exception
5 Aug, 2013 2:59:51 PM io.netty.channel.DefaultChannelPipeline$TailHandler exceptionCaught
WARNING: An exceptionCaught() event was fired, and it reached at the tail of the pipeline. It usually means the last handler in the pipeline did not handle the exception.
io.netty.handler.codec.EncoderException: java.lang.IllegalStateException: unexpected message type: DefaultHttpRequest
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:107)
at io.netty.channel.CombinedChannelDuplexHandler.write(CombinedChannelDuplexHandler.java:193)
at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:647)
at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:632)
at io.netty.handler.stream.ChunkedWriteHandler.doFlush(ChunkedWriteHandler.java:319)
at io.netty.handler.stream.ChunkedWriteHandler.flush(ChunkedWriteHandler.java:150)
at io.netty.channel.DefaultChannelHandlerContext.invokeFlush(DefaultChannelHandlerContext.java:677)
at io.netty.channel.DefaultChannelHandlerContext.flush(DefaultChannelHandlerContext.java:658)
at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:686)
at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:692)
at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:897)
at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:239)
at com.rancore.sdk.websocket.handler.RTSaaSSDKP2CSClientHandler.handle401UnauthorizedResponse(RTSaaSSDKP2CSClientHandler.java:174)
at com.rancore.sdk.websocket.handler.RTSaaSSDKP2CSClientHandler.handleHttpResponse(RTSaaSSDKP2CSClientHandler.java:77)
at com.rancore.sdk.websocket.handler.RTSaaSSDKP2CSClientHandler.channelRead0(RTSaaSSDKP2CSClientHandler.java:63)
at com.rancore.sdk.websocket.handler.RTSaaSSDKP2CSClientHandler.channelRead0(RTSaaSSDKP2CSClientHandler.java:28)
at io.netty.channel.SimpleChannelInboundHandler.channelRead(SimpleChannelInboundHandler.java:98)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:333)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:319)
at io.netty.handler.codec.MessageToMessageDecoder.channelRead(MessageToMessageDecoder.java:102)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:333)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:319)
at io.netty.channel.ChannelInboundHandlerAdapter.channelRead(ChannelInboundHandlerAdapter.java:86)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:333)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:319)
at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:173)
at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:148)
at io.netty.channel.DefaultChannelHandlerContext.invokeChannelRead(DefaultChannelHandlerContext.java:333)
at io.netty.channel.DefaultChannelHandlerContext.fireChannelRead(DefaultChannelHandlerContext.java:319)
at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:789)
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:100)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:497)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:465)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:359)
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:101)
at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.IllegalStateException: unexpected message type: DefaultHttpRequest
at io.netty.handler.codec.http.HttpObjectEncoder.encode(HttpObjectEncoder.java:59)
at io.netty.handler.codec.http.HttpClientCodec$Encoder.encode(HttpClientCodec.java:94)
at io.netty.handler.codec.http.HttpClientCodec$Encoder.encode(HttpClientCodec.java:85)
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:89)
... 35 more

My code:

if (headerField.split(" ")[1].equals("realm="saas_service"")) {
System.out.println(uri.toASCIIString());
HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri.toASCIIString());
req.headers().set(HttpHeaders.Names.AUTHORIZATION, "Basic " + authHeaderString());
// if (action == RTCloudDataSmsActions.SMS_DOWNLOAD)
// req.headers().set(RTSaaSSDKP2PRequestParams.ACTION, RTCloudDataSmsActions.SMS_DOWNLOAD);
try {
ctx.channel().writeAndFlush(req).sync();
} catch (InterruptedException e) {

                }
            }
@ghost
Copy link
Author

ghost commented Aug 5, 2013

this is my code

if (headerField.split(" ")[1].equals("realm="saas_service"")) {
System.out.println(uri.toASCIIString());
HttpRequest req = new DefaultHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, uri.toASCIIString());
req.headers().set(HttpHeaders.Names.AUTHORIZATION, "Basic " + authHeaderString());
// if (action == RTCloudDataSmsActions.SMS_DOWNLOAD)
// req.headers().set(RTSaaSSDKP2PRequestParams.ACTION, RTCloudDataSmsActions.SMS_DOWNLOAD);
try {
ctx.channel().writeAndFlush(req).sync();
} catch (InterruptedException e) {

                }
            }

@normanmaurer
Copy link
Member

Most likely you wanted to use DefaultFullHttpRequest ?

@ghost
Copy link
Author

ghost commented Aug 5, 2013

i tried with DefaultFullHttpRequest also i got same exception

@normanmaurer
Copy link
Member

@Chandru2012 show me the ChannelPipeline

@ghost
Copy link
Author

ghost commented Aug 5, 2013

bootstrap.channel(NioSocketChannel.class)
.group(group)
.option(ChannelOption.SO_KEEPALIVE, true)
.option(ChannelOption.TCP_NODELAY, true)
.option(ChannelOption.SO_REUSEADDR,true)
.handler(new ChannelInitializer() {
@OverRide
protected void initChannel(SocketChannel ch) throws Exception {
// TODO: add ssl handler
//ch.pipeline().addLast("ssl-handler", null);
// ch.pipeline().addLast("logging", new LoggingHandler(LogLevel.INFO));
ch.pipeline().addLast("client-codec", new HttpClientCodec());
ch.pipeline().addLast("chunked-write-handler", new ChunkedWriteHandler());
ch.pipeline().addLast("client-handler", clientHandler);
}
});

@ghost
Copy link
Author

ghost commented Aug 5, 2013

please comment ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant