You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@myfaces.apache.org by fischman_98 <mf...@powerconsultantsinc.com> on 2009/10/05 19:21:44 UTC

Re: File download and out of memory

To All:

So far I've found that using the old fashioned servlet is the only (&
Quickest as far as download speed) way to go.

I would love to see a managedBean solution if someone comes up with one.

I am going to attempt the phaseListener approach (
http://cagataycivici.wordpress.com/2006/02/16/phaselistener_renders_an_image_no/
Phase Listener Approach ) and we'll see.

But servlet works for me.

Matt



Shane Petroff wrote:
> 
> Hello,
> 
> I'm having a problem with a link used to download a "large" file. I say 
> large in quotation because by modern standards, the 5MB file I'm talking 
> about is tiny; I need to be able to handle at least 20MB. The same code 
> works for small files (<25K), but dies on larger ones. Hopefully it is a 
> configuration issue. On the jsp, there is a commandLink bound to the 
> "onDownload" action pasted below. The only config I can imagine that 
> might come into play is configuring the extensions filter itself. I've 
> specified UTF-8 encodings by default since several pages must support 
> extended characters. I'm currently using MyFaces core 1.1.5, Tomahawk 
> 1.1.6 and Tomcat 5.5.23
> 
> The stack trace is:
> java.lang.OutOfMemoryError: Java heap space
>     at java.util.Arrays.copyOf(Arrays.java:2882)
>     at 
> java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
>     at 
> java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
>     at java.lang.StringBuffer.append(StringBuffer.java:320)
>     at 
> org.apache.myfaces.shared_tomahawk.renderkit.html.util.UnicodeEncoder.encode(UnicodeEncoder.java:54)
> (full stack trace below)
> 
> Extension Filter config:
>     <filter>
>         <filter-name>MyFacesExtensionsFilter</filter-name>
>         
> <filter-class>org.apache.myfaces.webapp.filter.ExtensionsFilter</filter-class>
>         <init-param>
>             <param-name>maxFileSize</param-name>
>             <param-value>90m</param-value>
>         </init-param>
>         <init-param>
>             <param-name>uploadMaxFileSize</param-name>
>             <param-value>90m</param-value>
>         </init-param>
>     </filter>
> 
> Action code:
>     public String onDownload()
>     {
>         String rtn = Constants.ERROR_OUTCOME;
>         FileInputStream fis = null;
>         OutputStream os = null;
>         try
>         {
>             File file = buildFile(); // creates a 5MB file. If I hack 
> this to return a 25K file, it all works well
> 
>             FacesContext fc = FacesContext.getCurrentInstance();
>             HttpServletResponse response = (HttpServletResponse) 
> fc.getExternalContext().getResponse();
>             response.setHeader("Content-disposition", "attachment; 
> filename=" + file.getName());
>             response.setContentType("application/xml");
> 
>             fis = new FileInputStream(file);
>             os = new BufferedOutputStream(response.getOutputStream());
> 
>             int read;
>             while( (read = fis.read()) != -1 )
>                 os.write(read);
> 
>             os.flush();
>             fc.responseComplete();
>             rtn = Constants.SUCCESS_OUTCOME;
>         }
>         catch ( Exception e )
>         {
>             logException( MessageConstants.LOADING_ERROR_PREFIX + "XML", 
> e );
>         }
>         finally
>         {
>             try
>             {
>                 os.close();
>                 fis.close();
>             }
>             catch(Exception ignored) { /* we don't care about NPE's 
> either */ }
>         }
> 
>         return rtn;
>     }
> 
> Full Stack Trace:
> java.lang.OutOfMemoryError: Java heap space
>     at java.util.Arrays.copyOf(Arrays.java:2882)
>     at 
> java.lang.AbstractStringBuilder.expandCapacity(AbstractStringBuilder.java:100)
>     at 
> java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:572)
>     at java.lang.StringBuffer.append(StringBuffer.java:320)
>     at 
> org.apache.myfaces.shared_tomahawk.renderkit.html.util.UnicodeEncoder.encode(UnicodeEncoder.java:54)
>     at 
> org.apache.myfaces.shared_tomahawk.renderkit.html.HtmlResponseWriterImpl.write(HtmlResponseWriterImpl.java:567)
>     at 
> org.apache.myfaces.renderkit.html.util.DefaultAddResource.writeResponse(DefaultAddResource.java:847)
>     at 
> org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:162)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>     at 
> org.springframework.orm.hibernate3.support.OpenSessionInViewFilter.doFilterInternal(OpenSessionInViewFilter.java:173)
>     at 
> org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:77)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>     at 
> ca.mayet.SessionTimeoutRedirectFilter.doFilter(SessionTimeoutRedirectFilter.java:78)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:215)
>     at 
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:188)
>     at 
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:210)
>     at 
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:174)
>     at 
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
>     at 
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:117)
>     at 
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:108)
>     at 
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:151)
>     at 
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:870)
>     at 
> org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:665)
>     at 
> org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:528)
>     at 
> org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:81)
>     at 
> org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:685)
>     at java.lang.Thread.run(Thread.java:619)
> 
> -- 
> Shane
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/File-download-and-out-of-memory-tp14163021p25754734.html
Sent from the MyFaces - Users mailing list archive at Nabble.com.