1 2 3 Previous Next 34 Replies Latest reply on Mar 17, 2011 1:29 PM by rshan.bob.shanahan.alascorp.com Go to original post
      • 15. Re: Large file download
        fkj
        • 16. Re: Large file download
          gardellajuan
          Hi,

          If you want download a very large file (>100Mb) you must not use the request buffer.

          To fix the problem, I create the file in the server and then generate a hard link to it.

          Hope it help.

          Sorry my English

          • 17. Re: Large file download
            fkj

            Stephen Friedrich wrote on Jan 10, 2009 01:44:


            I think it should be enough to add this line to components.xml to exclude the ajax4jsf filter for any URL that contains /file/:


            <web:ajax4jsf-filter regex-url-pattern="^(?:[^/]|/(?!file/))*$"/>






            I have three different servlets for file download. They are mapped to the following patterns:
            /fileDownload
            /multipleFileDownload
            /byteArrayDownload


            Can anyone help me with the regex to exclude these three patterns from ajax4jsf filter?


            Thanks a lot,
            Felipe

            • 18. Re: Large file download
              swd847

              You could try this:


              (?!(/fileDownload)(/multipleFileDownload)(/byteArrayDownload))


              No idea if it will work though.

              • 19. Re: Large file download
                swd847

                I think the best general solution to this problem is to do your downloads in a custom filter that runs outside the seam/a4j filters.

                • 20. Re: Large file download
                  fkj

                  Stuart Douglas wrote on Oct 22, 2009 23:59:


                  You could try this:

                  (?!(/fileDownload)(/multipleFileDownload)(/byteArrayDownload))

                  No idea if it will work though.


                  Thanks, but it didn't worked, so I ended up extending the Ajax4jsfFilter, as mentioned by Gena Batalski above.



                  Stuart Douglas wrote on Oct 23, 2009 02:16:


                  I think the best general solution to this problem is to do your downloads in a custom filter that runs outside the seam/a4j filters.


                  Since the Seam Filter is mapped to


                  /*



                  , could you give a clue on how to do this?


                  Thanks,
                  Felipe

                  • 21. Re: Large file download
                    cash1981



                    Stuart Douglas wrote on Oct 23, 2009 02:16:


                    I think the best general solution to this problem is to do your downloads in a custom filter that runs outside the seam/a4j filters.


                    Since the Seam Filter is mapped to

                    /*



                    , could you give a clue on how to do this?

                    Thanks,
                    Felipe


                    +1
                    . This would be useful information to know.

                    • 22. Re: Large file download
                      swd847

                      Here is a copy and paste of my filter. Basically to download a file you pass the parameter 'download_file_filter_request_parameter' to any view. The appropriate file is then retrieved from the conversation and then downloaded from the filestore.


                      @Name("downloadFilter")
                      @Filter(around = { "org.jboss.seam.web.ajax4jsfFilter" })
                      @Scope(ScopeType.APPLICATION)
                      @Startup
                      @BypassInterceptors
                      public class DownloadFilter extends AbstractFilter
                      {
                      
                          public void doFilter(ServletRequest request, ServletResponse resp, FilterChain arg2)
                               throws IOException, ServletException
                          {
                           if (HttpServletRequest.class.isAssignableFrom(request.getClass()))
                           {
                               HttpServletRequest req = (HttpServletRequest) request;
                               HttpServletResponse response = (HttpServletResponse) resp;
                               String val = req.getParameter("download_file_filter_request_parameter");
                      
                               if (val != null)
                               {
                                Integer fileId = Integer.valueOf(val);
                                try
                                {
                                    Lifecycle.beginCall();
                      
                                    if (fileId != null)
                                    {
                                     HttpSession session = req.getSession();
                                     Map<Integer, Integer> fileMap = (Map) session
                                          .getAttribute("downloadFileMap");
                                     fileId = fileMap.get(fileId);
                                     FileStoreManagerLocal fileStoreManager = (FileStoreManagerLocal) Component
                                          .getInstance("fileStoreManager");
                                     EntityManager entityManager = (EntityManager) Component
                                          .getInstance("entityManager");
                                     FileRecord r = entityManager.find(FileRecord.class, fileId);
                      
                                     InputStream stream = fileStoreManager.getFileStream(r);
                      
                                     FacesContext facesContext = FacesContext.getCurrentInstance();
                      
                                     response.setContentType(r.getMimetype());
                                     response.setContentLength(stream.available());
                                     response.setHeader("Content-disposition", "attachment;filename="
                                          + r.getFilename());
                                     OutputStream out = response.getOutputStream();
                                     byte[] buf = new byte[response.getBufferSize()];
                                     int len;
                                     while ((len = stream.read(buf)) > 0)
                                     {
                                         out.write(buf, 0, len);
                                         out.flush();
                                     }
                                     out.flush();
                                     out.close();
                      
                                     facesContext.responseComplete();
                                    }
                                } catch (Exception e)
                                {
                                    resp.getOutputStream().write("Error Downloading File".getBytes());
                                }
                      
                                finally
                                {
                                    Lifecycle.endCall();
                                }
                               } else
                               {
                                arg2.doFilter(req, response);
                               }
                           }
                          }
                      }
                      
                      


                      • 23. Re: Large file download
                        cash1981
                        Thanks Stuart.

                        So you put the fileId in session and request? Why?
                        Why is your session map <Integer,Integer>, and not just an integer (fileId)? Is it incase you have multiple files you want to download?
                        • 24. Re: Large file download
                          swd847

                          If I didn't use the map then anyone could download any file, which is not acceptable. Security checks happen when the file ids are inserted into the map.



                          There are other ways to do this, such as putting the file id into the conversation.


                          • 25. Re: Large file download
                            cash1981

                            Aah now I see.

                            • 26. Re: Large file download
                              amit.u.purohit
                              Hi Stuart,
                              My application is integrated with an external Document Management Repository where we upload and download our documents. Download works fine for small sized documents However for large documents(of size > 8MB), I get an Out of Memory error. I tried all the above steps mentioned in the post but I still am not able to get my issue resolved.
                              I looked at the custom filter written by you and I need to integrate that in my application. However, I am not sure what are the changes I need to make in my web.xml and components.xml file in order for the filter to work.
                              • 27. Re: Large file download
                                cash1981

                                If you get problems for files over 8mb then clearly your server is configured with too little ram. You should configure your application server to use more ram.


                                That filter does not need any configuration. It will work as is. You just need to understand how to use it. It will intercept a download if the request matches 'downloadfilefilterrequestparameter'

                                • 28. Re: Large file download
                                  amit.u.purohit
                                  Hi Shervin,

                                  I have written a custom servlet, DownloadFile to download the files. I did add a new filter as described by Stuart. I look for all request which has DownloadFile as the URI content. But my filter never gets called. However, if I update the web.xml as showed below :
                                     <filter>
                                    <filter-name>CustomFilter</filter-name>
                                    <filter-class>com.sony.spe.mp.servlets.MPAjax4jsfFilter</filter-class>
                                  </filter>
                                  <filter-mapping>
                                    <filter-name>CustomFilter</filter-name>
                                    <url-pattern>/servlet/DownloadFile/*</url-pattern>
                                  </filter-mapping>

                                  Only then the customFilter is called. However, the issue still exists. I get a OutOfMemory exception if I try to continuosly upload and download files.
                                  The only different thing I do here is, I call Seam components from DownloadFile class.

                                  I would highly appreciate if someone can help me on this, as I have spent a lot of time on the issue without any results .. :(
                                  • 29. Re: Large file download
                                    swd847

                                    Are you sure you put all the annotations that are on my filter on your filter?


                                    When you define filters in web.xml there is no way to specify the ordering, so your filter is probably running inside the seam filter. You need to use a filter that is managed by seam, you should have a look in the section on the reference manual on filters.