users@glassfish.java.net

RE: Forcing chunked encoding while downloading a large file?

From: Kevin Regan <k.regan_at_f5.com>
Date: Tue, 8 May 2012 21:24:28 +0000

Looking at the application, the logging filters were configured:

<init-param>
         <param-name>com.sun.jersey.spi.container.ContainerRequestFilters</param-name>
         <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
     </init-param>
     <init-param>
         <param-name>com.sun.jersey.spi.container.ContainerResponseFilters</param-name>
         <param-value>com.sun.jersey.api.container.filter.LoggingFilter</param-value>
     </init-param>
Would adding the following cause the large downloaded file to be streamed rather than buffered?

     <init-param>
         <param-name>com.sun.jersey.config.feature.logging.DisableEntitylogging</param-name>
         <param-value>true</param-value>
     </init-param>

Thanks,
Kevin

From: Martin Matula [mailto:martin.matula_at_oracle.com]
Sent: Tuesday, May 08, 2012 2:10 AM
To: users_at_glassfish.java.net
Subject: Re: Forcing chunked encoding while downloading a large file?

Hi Kevin,
That should not be happening. For InputStream Jersey returns -1 as the content length - i.e. does not try to buffer the entity. For the File it reads it using File.length() method.
Are you using any filters in your application? E.g. the logging filter would cause that the entity would get buffered.
Martin

On May 4, 2012, at 11:24 PM, Kevin Regan wrote:


I'm downloading a large file with Jersey/Glassfish and I'm seeing a java.lang.OutOfMemoryError.

I'm returning a FileInputStream (also tried File) from the Jersey handler and it looks to be attempting to write the file to a ByteArrayOutputStream before returning it.

Is there any way to force Jersey/Glassfish to stream this large binary file to the client through either chunked encoding or by not setting CONTENT-LENGTH?

Sincerely,
Kevin Regan