2

I have read several stackoverflow questions including

How to parse an HTTP Request in Java?

which directs to httpcomponents on apache which looks promising, but when you receive bytes asynchronously, you don't get the whole request always so I need something I can keep calling like

requestWriter.fillBuffer AND it looked like they had this but now it seems not to be there

http://hc.apache.org/httpcomponents-core-ga/httpcore/apidocs/org/apache/http/impl/io/HttpRequestParser.html

AND then I would need a return value from that function to tell me the parsing of the http request is complete(complete meaning it has the bytes of the body stuffed somewhere based on the ContentLength header and everything else)

Anyone have an example of this on the web. I keep running into wanting to do this and searching but finally broke down and decided to ask.

3 Answers 3

1

You can also simply use the message parser from the asynchronous version of Apache HttpClient:

http://hc.apache.org/httpcomponents-core-dev/httpcore-nio/apidocs/org/apache/http/impl/nio/codecs/DefaultHttpRequestParser.html

http://hc.apache.org/httpcomponents-core-dev/httpcore-nio/xref/org/apache/http/impl/nio/DefaultNHttpClientConnection.html#155

Sign up to request clarification or add additional context in comments.

Comments

1

I've never tried it with the apache stuff.

You might be better served looking at netty - http://www.jboss.org/netty

Specifically, the example they give for building an async http client: http://docs.jboss.org/netty/3.2/xref/org/jboss/netty/example/http/snoop/package-summary.html

You'll note that they have the chunking handling built in.

Or perhaps one of the HTTP client libs built on top of it found here: http://www.jboss.org/netty/related-projects

If you are locked into using apache's http client, let me know and I'll delete this post.

Edit to add: Note their main site is now found at http://netty.io but it is often slow to respond, or doesn't respond at all, as was the case when I was posting this)

Comments

0

did you take a look to async-http-client ? looks promising. I don't think it will work for you have out of the box but I see it as a good starting point.

1 Comment

Unfortunately, I looked at that eventually..they moved. They do no http parsing. They rely on netty, grizzly and providers to do parsing and then just translate the providers HttpResponse to their own :( :( so this did not work too well at all.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.