users@jersey.java.net

Re: [Jersey] jersey client and large file uploads

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 14 Aug 2009 10:47:26 +0200

On Aug 13, 2009, at 9:04 PM, Igor Minar wrote:

>
> On Aug 12, 2009, at 11:45 PM, Paul Sandoz wrote:
>
>> Hi Igor,
>>
>> If Jersey knows the size in advance the size then it will do:
>>
>> if (size != -1 && size < Integer.MAX_VALUE) {
>> // HttpURLConnection uses the int type for
>> content length
>> uc.setFixedLengthStreamingMode((int)size);
>>
>> Note the restriction in size. So if you POST or PUT an instance of
>> File whose size is less than Integer.MAX_VALUE this should work. Is
>> it not working for you?
>
> and where does "size" come from?

The MessageBodyWriter selected to write an instance of a Java type to
the output stream.

What Java type are you using? One solution is to support a message
body writer for your type.

The only other solution i can think is to check if a Content-Length
header is set and obtain the size from that which will override that
from the MessageBodyWriter. Could you log an issue?


> I think this is the issue, since we set the content length header
> manually and it probably doesn't get registered in the web resource
> builder.
>

Right.


> the code above also means that we won't be able to send files larger
> than ~2GB due to int overflow.
>

I know, not much i can do about that as it is a restriction in
HttpURLConnection. The Apache HTTP client does not have those
restrictions. Note that for this client non-buffering is enabled when
chunked encoding is set. However, the code does report the size if
know, but i do not know if the client uses the size (if > 0) instead
of chunked encoding.

Paul.

> thanks,
> Igor
>
>>
>> In fact there is an issue with setting this because retry will not
>> work for authentication. So i think we require a property to ensure
>> that this is enabled or not.
>>
>> Paul.
>>
>> On Aug 13, 2009, at 7:41 AM, Igor Minar wrote:
>>
>>> hi there,
>>>
>>> we noticed that if I try to upload large files via jersey client
>>> (by passing a input stream to the client), the jvm will run out
>>> memory unless we use chunked encoding.
>>>
>>> Isn't there a way to avoid chunked encoding (which just adds
>>> overhead in case of static content)?
>>>
>>> thanks,
>>> Igor
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>