java - HttpRequest returning null entity, cannot extract body on server -


I am trying to parse an HTTP request and I want to capture the request body. It seems that the default DefaultHttpRequestParser does not parse the entity / entity from its input stream. Is there a class that will do this?

Unfortunately, I can not use the entire stack and need to pull the request directly from this input stream.

My parsing code is below, seeing some of the other answers, it appears that the body of the request should be available as a unit. However, every time I try to reach the unit, then it is zero.

Debugging I think buffer has read, but the body is not used and he reads the DefaultHttpRequestParser header only. Is there a parsing that I should use to parse the entire input?

  InputStream = socket.getInputStream (); HttpTransportMetricsImpl Metrics = New HTTPS Transport MetricsEmpl (); Session InputBuferIMPL buf = New Session InputBufferEmple (Matrix, 2048); Buf.bind (is); DefaultHttpRequestParser reqParser = New DefaultHttpRequestParser (buf); HttpRequest req = reqParser.parse (); If (req for example HttpEntityEnclosingRequest) {entity = ((HttpEntityEnclosingRequest) query) .getEntity (); // ... the unit is always zero   

If I read these input streams then I will end it:

  POST / HTTP / 1.1 User-agent: Curl / Q.XX.0 (linux-gnu) libcurl / Q.XX.0 OpenSSL / XYZ Zlib / ABCD Libidon / EFF LiberTMP / GH Host: Localhost: 8088 Approved: * / * Content-Length: 333 Material-Type: Multipart / Form-Data; Range = -------------------------- 39203c7982df ------------------- - --------- 39203c7982df Content-presentation: Form-data; Name = "fileupload"; Filename = "grun.sh" Content-Type: Application / Octet-Stream #! / Bin / bash -x java-classpath lib / anther-4.4-full.zer: build / classes org.antlr.v4.runtime.misc Tastric typegroup "AHI" ------------ ------------------ 39203c7982df-- [/ code>  

[Update] Oleg is a good answer, but should I request the body Can I add or now I need to pass two things to body and stream? I see

I get the following to work, but it's demoted in the latest release. ... httpNTninklingerai IEEE = (HTTPNT encryption request) rake; @SuppressWarnings ("Exclusion") EntityDeserializer Ed = New EntityDeserializer (New LaxContentLengthStrategy ()); @SuppressWarnings ("Conflict") // Receipt! HttpEntity ent = ed.deserialize (buff, rake); Ereq.setEntity (ENT); Return erek;

I ended up adding the solution of oleg with the above:

  HTTP://textclassingIEECK = (HTNTTninkling request) rake; Ingredients LangSwattage content Langrestraczie = strict content Langreswirti INSTANCE; Long LAN = Content Longest Deciramine lang (rake); InputStream contentStream = null; If (lane == content is lengthy. CHUNKED) {contentStream = new chunkedInputstream (buff); } And if (LAN == Content Long Division.INNNTI) {contentStream = New Identity Instream Stream (Buff); } And {contentStream = new content genderInputstream (buff, lane); } BasicHttpEntity ent = New BasicHttpEntity (); Ent.setContent (contentStream); Ereq.setEntity (ENT); Return erek;    

  is InputStream = socket.getInputStream (); HttpTransportMetricsImpl Metrics = New HTTPS Transport MetricsEmpl (); Session InputBuferIMPL buf = New Session InputBufferEmple (Matrix, 2048); Buf.bind (is); DefaultHttpRequestParser reqParser = New DefaultHttpRequestParser (buf); HttpRequest req = reqParser.parse (); InputStream contentStream = null; If (Req examples of HttpEntityEnclosingRequest) {ContentLengthStrategy contentLengthStrategy = StrictContentLengthStrategy.INSTANCE; Long LAN = Content Longest Deciramine lang (rake); If (lane == content is lengthy. CHUNKED) {contentStream = new chunkedInputstream (buff); } And if (LAN == Content Long Division.INNNTI) {contentStream = New Identity Instream Stream (Buff); } And {contentStream = new content genderInputstream (buff, lane); }} // Something useful with content stream (if non-faucet)   

Message parser is only the head in the HTTP parse message, however, any session can continue to read from input buffer And read the text message content by the end of the message (depending on the artist used)

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -