cxf-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dahanhsi <dahan...@gmail.com>
Subject Re: How to get request body with "application/x-form-urlencoded" content-header set
Date Thu, 25 Oct 2012 12:30:54 GMT
Sergey Beryozkin-5 wrote
> On 25/10/12 04:50, dahanhsi wrote:
>> hi Sergey,
>>
>> by following your advice, I added the code below in doProcess() and
>> finally
>> got the request body:
>>
>> HttpServletRequest request = context.getHttpServletRequest();
>> Enumeration pNames = request.getParameterNames();
>> while(pNames.hasMoreElements()){
>>      String name=(String)pNames.nextElement();
>>      String value=servletRequest.getParameter(name);
>>      System.out.println(name + "=" + value);
>> }
>>
>>
>> But in my another restful operation:
>> @PUT
>> @Path("/upload")
>> public void doUpload(... @Context MessageContext context ...){
>>     ...
>>     HttpServletRequest request = context.getHttpServletRequest();
>>     inputStream = servletRequest.getInputStream();
>>     ...
>> }
>>
>> I also encounter the same problem, and can not write request body from
>> inputstream.
>> Client may upload a big file, and exhaust JVM memory if I use above
>> solution.
>> How can I fix it?
>>
> Calling servletRequest.getInputStream() does not read it into memory, so 
> you can read the stream and save the chunks of the data as needed.
> Also consider consuming multipart/form-data or similar, CXF will save 
> the data to the temp storage if needed.
> 
> Sergey

I know that inputStream does not read entire body into memory.

When the request hit my servlet
===
PUT /upload HTTP/1.1 
Host: myhost.com 
Content-Length: length 
Content-Type: application/x-form-urlencoded 
Date: date 

{big file in body}
===

Because content-type is application/x-form-urlencoded, I can not read
correct body from request.getInputStream in doUpload(). I also can not read
it from request.getParameterNames(), because it means that the entire body
is wrote into memory.






--
View this message in context: http://cxf.547215.n5.nabble.com/How-to-get-request-body-with-application-x-form-urlencoded-content-header-set-tp5717220p5717403.html
Sent from the cxf-user mailing list archive at Nabble.com.

Mime
View raw message