question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Pipeline configuration: Decoder, Handler, Encoder - throws: UnsupportedOperationException: unsupported message type: DefaultHttpResponse (expected: ByteBuf, FileRegion)

See original GitHub issue

Expected behavior

The pipeline configuration:

  • Decoder
  • Handler
  • Encoder should not throw exception when a client sends HTTP request.

image

By reading the documentation, the order should be executed like so:

Inbound: Decoder, Handler

Outbound: Encoder

Actual behavior

The pipeline thorws exception:

Aug 14, 2022 2:14:04 PM io.netty.channel.DefaultChannelPipeline onUnhandledInboundException
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.
java.lang.UnsupportedOperationException: unsupported message type: DefaultHttpResponse (expected: ByteBuf, FileRegion)

Steps to reproduce

  • Clone my repo: https://github.com/ShlomiRex/netty-pipeline-test
  • Run the code with the pipeline configuration: image
  • Send dummy HTTP request: curl -v 127.0.0.1:8080
  • The program throws exception.
  • Uncomment the ‘Works’ section, and comment the ‘Doesn’t work’ section and see that it works, but not the other way around.

Minimal yet complete reproducer code (or URL to code)

https://github.com/ShlomiRex/netty-pipeline-test

Netty version

4.1.10.Final

JVM version (e.g. java -version)

11

OS version (e.g. uname -a)

  • macOS 12.6, macbook pro 16 M1
  • Linux CentOS

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
chrisvestcommented, Aug 16, 2022

If your handler does a write to the ChannelHandlerContext it’s passed in, say, channelRead, then the write will propagate up from the handlers position in the pipeline. Otherwise handlers wouldn’t have a way to pass the write through.

If you do a write to the Channel, then it’ll propagate from the bottom of the pipeline.

0reactions
ShlomiRexcommented, Aug 17, 2022

If your handler does a write to the ChannelHandlerContext it’s passed in, say, channelRead, then the write will propagate up from the handlers position in the pipeline. Otherwise handlers wouldn’t have a way to pass the write through.

If you do a write to the Channel, then it’ll propagate from the bottom of the pipeline.

Thanks a lot! If I change ctx.write() to ctx.channel.write() it propogates to the next pipeline as expected! And so the code:

                            pipeline.addLast(new HttpRequestDecoder());
                            pipeline.addLast(new MyHandler());
                            pipeline.addLast(new HttpResponseEncoder());

works! (it didn’t work before because I was writing to context, and not channel).

Your a life savior!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Unable to write DefaultHttpResponse to a channel in netty ...
Unable to write DefaultHttpResponse to a channel in netty: "unsupported message type: class org.jboss.netty.handler.codec.http.
Read more >
Index (Netty API Reference (4.0.56.Final))
Returns true if and only if the specified message can be decoded by this codec. acceptInboundMessage(Object) - Method in class io.netty.handler.codec.
Read more >
Java Examples for io.netty.channel.ChannelHandler
Add a handler to pipeline if it is not already added * and configure the ... void channelRead0(ChannelHandlerContext ctx, HttpObject msg) throws Exception ......
Read more >
Netty in Action MEAP v05
A ByteBuffer is fundamental to both NIO APIs and, indeed, to Netty. ... There are various types of base classes for encoders and...
Read more >
Netty in Action v9 MEAP PDF | Thread (Computing) | Net Beans
6 ChannelHandler and ChannelPipeline 7 The Codec framework 8 Provided ChannelHandlers and Codecs 9 Bootstrapping Netty Applications PART 3: NETTY BY EXAMPLE
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found