You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@wink.apache.org by srinivasan venkat <sr...@yahoo.com> on 2010/09/15 18:25:43 UTC

Request Size calculation.

Hi,
 
Is there any way in wink to calculate the request size?.
I need to record the incoming  request size.
Can we get size using MessageContext or RunTimeContext classes?
 
 
Thanks,
Srinivasan.V


Re: Request Size calculation.

Posted by Nicholas L Gallardo <nl...@us.ibm.com>.
Srinivasan,

The easiest thing to do is use what's provided in the request.   There is a
Content-Length header included in the HTTP message that will indicate the
size of the inbound request payload.

You can access either through the injection of context objects
(HttpServletRequest) or by asking for the param directly on your method
signature.  Like this:

   @POST
   @Path("foo')
   public Response foo(@HeaderParam("Content-Length") int length) {

   }


-Nick






                                                                           
             srinivasan venkat                                             
             <srins_2001@yahoo                                             
             .com>                                                      To 
                                       wink-user@incubator.apache.org      
             09/15/2010 11:25                                           cc 
             AM                                                            
                                                                   Subject 
                                       Request Size calculation.           
             Please respond to                                             
             wink-user@incubat                                             
               or.apache.org                                               
                                                                           
                                                                           
                                                                           




                                                     
 Hi,                                                 
                                                     
 Is there any way in wink to calculate the request   
 size?.                                              
 I need to record the incoming  request size.        
 Can we get size using MessageContext or             
 RunTimeContext classes?                             
                                                     
                                                     
 Thanks,                                             
 Srinivasan.V                                        
                                                     



Re: Request Size calculation.

Posted by Bryant Luk <br...@gmail.com>.
Right, I don't think that my servlet filter idea would work before you
read the entire stream.  If the transfer is chunked however, I don't
think you normally get a Content-Length header or any "in-advanced"
indicator (since I think that's the purpose of chunked AFAIK) anyway
so the final size may not be available until you actually read the
entire stream.

On Wed, Sep 15, 2010 at 4:46 PM, Davanum Srinivas <da...@gmail.com> wrote:
> Bryant
>
> That won't work if you need the size before you want to read the stream
>
> Right?
>
> -- dims
>
> On Sep 15, 2010, at 2:47 PM, Bryant Luk <br...@gmail.com> wrote:
>
>> Another way is to use a servlet filter to wrap the
>> HttpServletRequest.getInputStream() with your own
>> HttpServletRequestWrapper implementation.  Count the bytes read for
>> every read() call to your InputStream and store it as a
>> HttpServletRequest attribute.
>>
>> For chunked transfer encoding, the Content-Length may not be provided
>> so you may be forced to somehow wrap the InputStream.
>>
>> http://svn.apache.org/repos/asf/incubator/wink/branches/wink-1.1-incubating/wink-server/src/main/java/org/apache/wink/server/internal/servlet/contentencode/ContentEncodingRequestFilter.java
>> may get you started on the process of wrapping the HttpServletRequest
>> (in that filter it decompresses the stream if certain headers are set)
>>
>> On Wed, Sep 15, 2010 at 11:25 AM, srinivasan venkat
>> <sr...@yahoo.com> wrote:
>>>
>>> Hi,
>>>
>>> Is there any way in wink to calculate the request size?.
>>> I need to record the incoming  request size.
>>> Can we get size using MessageContext or RunTimeContext classes?
>>>
>>>
>>> Thanks,
>>> Srinivasan.V
>

Re: Request Size calculation.

Posted by Davanum Srinivas <da...@gmail.com>.
Bryant

That won't work if you need the size before you want to read the stream

Right?

-- dims

On Sep 15, 2010, at 2:47 PM, Bryant Luk <br...@gmail.com> wrote:

> Another way is to use a servlet filter to wrap the
> HttpServletRequest.getInputStream() with your own
> HttpServletRequestWrapper implementation.  Count the bytes read for
> every read() call to your InputStream and store it as a
> HttpServletRequest attribute.
> 
> For chunked transfer encoding, the Content-Length may not be provided
> so you may be forced to somehow wrap the InputStream.
> 
> http://svn.apache.org/repos/asf/incubator/wink/branches/wink-1.1-incubating/wink-server/src/main/java/org/apache/wink/server/internal/servlet/contentencode/ContentEncodingRequestFilter.java
> may get you started on the process of wrapping the HttpServletRequest
> (in that filter it decompresses the stream if certain headers are set)
> 
> On Wed, Sep 15, 2010 at 11:25 AM, srinivasan venkat
> <sr...@yahoo.com> wrote:
>> 
>> Hi,
>> 
>> Is there any way in wink to calculate the request size?.
>> I need to record the incoming  request size.
>> Can we get size using MessageContext or RunTimeContext classes?
>> 
>> 
>> Thanks,
>> Srinivasan.V

Re: Request Size calculation.

Posted by Bryant Luk <br...@gmail.com>.
Another way is to use a servlet filter to wrap the
HttpServletRequest.getInputStream() with your own
HttpServletRequestWrapper implementation.  Count the bytes read for
every read() call to your InputStream and store it as a
HttpServletRequest attribute.

For chunked transfer encoding, the Content-Length may not be provided
so you may be forced to somehow wrap the InputStream.

http://svn.apache.org/repos/asf/incubator/wink/branches/wink-1.1-incubating/wink-server/src/main/java/org/apache/wink/server/internal/servlet/contentencode/ContentEncodingRequestFilter.java
may get you started on the process of wrapping the HttpServletRequest
(in that filter it decompresses the stream if certain headers are set)

On Wed, Sep 15, 2010 at 11:25 AM, srinivasan venkat
<sr...@yahoo.com> wrote:
>
> Hi,
>
> Is there any way in wink to calculate the request size?.
> I need to record the incoming  request size.
> Can we get size using MessageContext or RunTimeContext classes?
>
>
> Thanks,
> Srinivasan.V