0

i'm working with Netty. I have a HttpObject and i need the content (HttpContent). A cast don't work. What can i do then?

Greetings Daniel

Daniel84
  • 1
  • 3

1 Answers1

3

HttpObject has a few subinterfaces. Among them are HttpMessage and HttpContent. In general the HttpMessage represents the headers and the HttpContent represents the data. Depending on how your pipeline is configured you may get the following:

There are a few http examples provided by Netty to demonstrate how to handle an HttpObject. The https://github.com/netty/netty/tree/master/example/src/main/java/io/netty/example/http/upload example shows how to handle the second option described above.

Scott Mitchell
  • 716
  • 4
  • 7
  • adding the request/response encoder/decoder or the codecs to the pipeline allow you to handle httpMessages. e.g. @Override protected void initChannel(Channel ch) throws Exception { ChannelPipeline pipeline = ch.pipeline(); if (isClient) { pipeline.addLast("codec", new HttpClientCodec()); } else { } pipeline.addLast("codec", new HttpServerCodec()); pipeline.addLast("aggegator", new HttpObjectAggregator(512 * 1024)); } – paziwatts Nov 05 '14 at 09:22
  • Thanks for your help. I'm using LittleProxy. There i become a HttpObject. But so i can't get from a HttpObject the content? I need a FullHTTPMessage? – Daniel84 Nov 05 '14 at 15:21
  • I'm not sure what interfaces LittleProxy provides but it sounds like it is exposing Netty's types. Also I'm not sure how LittleProxy provides messages to your application or how it allows configuration of the pipeline. In Netty you can configure the pipeline to control how objects are delivered to your application code. Ultimately the two bullet points I listed above are the two options so you can test with 1 response what approach LittleProxy is taking. If you get back a FullHttpMessage then it is option 1, else it is option 2. – Scott Mitchell Nov 06 '14 at 01:10
  • @Daniel84 Does this make sense? Did this info help for your situation? – Scott Mitchell Nov 08 '14 at 08:10
  • I don't know why but it don't work. I don't have FullHttpMessage only HttpObject. I think LittleProxy is buggy or so. Maybe you have a last idea? – Daniel84 Nov 08 '14 at 19:19
  • Again I'm not sure if LittleProxy is wrapping Netty interfaces or exposing different interfaces but from a Netty perspective this answer will give you the 2 ways to receive HTTP objects. Like I said above if you are not being passed a [FullHttpMessage](https://github.com/netty/netty/blob/master/codec-http/src/main/java/io/netty/handler/codec/http/FullHttpMessage.java) then you will receive 1 HttpMessage object followed by n-1 HttpContent objects followed by 1 LastHttpContent. What does the class hierarchy for HttpObject look like in LittleProxy? – Scott Mitchell Nov 08 '14 at 21:05
  • What do you mean with "n-1"? And which class hierarchy do you mean? It's using netty.. – Daniel84 Nov 08 '14 at 21:31
  • n = the number of chunks used to represent the content. You said "I don't have FullHttpMessage only HttpObject". Do you mean to say that LittleProxy is not exposing this class to you and has its own class hierarchy around Netty's classes, or you have not configured LittleProxy to provide these messages to you? You are going to have to explain exactly what you are receiving, how you are configuring your pipeline in order to get more help, and some code. What URL are you requesting content from, what does your request look like, and what do you expect the content to look like? – Scott Mitchell Nov 08 '14 at 22:30
  • Do you not understand how to configure the pipeline? You may want to follow the Netty examples as I suggested to understand the core concepts I am describing. – Scott Mitchell Nov 08 '14 at 22:31