0 Replies Latest reply on Aug 3, 2012 2:46 AM by lit0908

    large size file with <s:resource> and <s:download>, 403 error

    lit0908

      Hi,

           What I am trying to do is a file download page. It works fine for small size file(probably less than 100MB), but when I try to download a large size file, it give me a page with "HTTP Status 403 - Access to the requested resource has been denied"。

           Don't know why is this happening and really new to this area. I have searched the forum, but nothing helped.

           Here is my code.

           web.xml

         <!-- Document Store Servlet -->
         <servlet>
                  <servlet-name>Document Store Servlet</servlet-name>
                  <servlet-class>org.jboss.seam.document.DocumentStoreServlet</servlet-class>
         </servlet>
         
         <servlet-mapping>
                     <servlet-name>Document Store Servlet</servlet-name>
                     <url-pattern>/seam/docstore/*</url-pattern>
         </servlet-mapping>
      
      

           fileDownloadTest.xhtml

       

      <rich:panel>
                        <f:facet name="header">Files Uploaded</f:facet>
                        
                        <div class="results">
                            <h:outputText value="No files exists" rendered="#{empty attachmentList}"/>
                            <rich:dataTable id="attachmentList" 
                                                           var="entry"
                                                 value="#{attachmentList}" 
                                                        rendered="#{not empty attachmentList}">
                                <rich:column>
                                    <f:facet name="header">File Name</f:facet>
                                    <s:link value="#{entry.name}"/>
                                </rich:column>
                                <rich:column>
                                    <f:facet name="header">Content Type</f:facet>
                                    #{entry.type}
                                </rich:column>
                                <rich:column>
                                    <f:facet name="header">Size(bytes)</f:facet>
                                    #{entry.size}
                                </rich:column>
                                <rich:column>
                                    <f:facet name="header">Action</f:facet>
                                    <s:download src="/resources.xhtml">
                                              Download
                                              <f:param name="attachmentId" value="#{entry.id}"></f:param>
                                    </s:download>
                                </rich:column>
                            </rich:dataTable>
                        </div>
                    </rich:panel>
      
      

           resources.xhtml

       

      <s:resource xmlns="http://www.w3.org/1999/xhtml"
      
      
          xmlns:s="http://jboss.com/products/seam/taglib"
      
      
          data="#{attachmentDownloadManager.file}"
      
      
          contentType="#{attachmentDownloadManager.contentType}"
      
      
          fileName="#{attachmentDownloadManager.fileName}" />
      
      

           resources.page.xml

       

      <page xmlns="http://jboss.com/products/seam/pages"
            xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
            xsi:schemaLocation="http://jboss.com/products/seam/pages http://jboss.com/products/seam/pages-2.2.xsd"
            action="#{attachmentDownloadManager.prepareDoc()}">
      </page>
      
      

           AttachmentDownloadManagerAction.java

       

      @Stateful
      @Name("attachmentDownloadManager")
      @Scope(ScopeType.EVENT)
      public class AttachmentDownloadManagerAction implements AttachmentDownloadManager{
      
      
                @Logger
                private Log log;
        
                @PersistenceContext(type = PersistenceContextType.EXTENDED)
                private EntityManager em;
        
                @RequestParameter
                private Long attachmentId;
        
                private File file;
                private String fileName;
                private String contentType;
        
        
                @Factory("attachmentList")
                public List<Attachment> getAttachmentList(){
                          List<Attachment> list = new ArrayList<Attachment>();
                          list = em.createQuery("select a from Attachment a").getResultList();
                          return list;
                }
        
                public void prepareDoc(){
                          log.info("prepareDoc() Id-" + attachmentId);
                          Attachment attachment = em.find(Attachment.class, attachmentId);
                          this.fileName = attachment.getName();
                          this.contentType = attachment.getType();
                          file = new File(attachment.getLocation() + attachment.getName());
        
                          log.info("prepareDoc() File ready");
                }
        
                public File getFile() {return file;}
                public void setFile(File file) {this.file = file;}
        
                public String getFileName() {return fileName;}
                public void setFileName(String fileName) {this.fileName = fileName;}
        
                public String getContentType() {return contentType;}
                public void setContentType(String contentType) {this.contentType = contentType;}
        
                @Remove
                public void destroy(){
        
                }
      }
      
      

       

      Thanks for your time and help in advance.