0 Replies Latest reply on Feb 24, 2011 11:57 AM by Val Sw

    Suggestion on Rich fileupload Multipart Filter, uploading large files and createTempFiles property

    Val Sw Expert

      Hi,

      I am using rich file upload component and need to allow user to upload 50 MB+(approximately) files and able to persist small files.

      Environment : jboss-4.2.3, jboss-seam-2.0.2.SP1, Rich Faces - version 3.3.1.GA


      Issue/ Suggestion:

      1) Please suggest best approach to define multipart filter. (web and components.xml are below)

      2) Error : I am getting following error on this method when I try to upload large files....

      3) createTempFiles property : While uploading files are uploaded "C:\WINNT\Temp", even if I set it to false...

       

      a) Web.xml : I have added Ajax4jsf Filter in web.xml

      b) Components.xml

      Added :

      xmlns:web="http://jboss.com/products/seam/web"

      xsi:schemaLocation=...

                http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd"

      and 

      <web:multipart-filter create-temp-files="false" max-request-size="2147483647" url-pattern="*.seam" />

       

      2) Error : I am getting following error on this method when I try to upload large files....

       

      public void paint(OutputStream stream, Object object) throws IOException {
                stream.write((byte [])(fileWrapper.getFileList().get((Integer) object)).getFileData());
             }
      This error is not during persist event (i.e. not during Save click) but it is from upload component, when I click "Upload" after adding files.
      
      javax.el.ELException: /FileUploadEdit.xhtml @79,90 createContent="#{fileUploadManager.paint}": ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
                at com.sun.facelets.el.TagMethodExpression.invoke(TagMethodExpression.java:74)
                at org.ajax4jsf.resource.UserResource.send(UserResource.java:110)
      .....
      Caused by: ClientAbortException:  java.net.SocketException: Connection reset by peer: socket write error
                at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:358)
                at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:354)
                at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:381)
                at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:370)
                at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:89)
                at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:83)
                at com.test.session.FileUploadManagerBean.paint(FileUploadManagerBean.java:45)
      
      

       

      3) createTempFiles property : While uploading files are uploaded "C:\WINNT\Temp", even if I set it to false...

      i.e. web:multipart-filter create-temp-files="false"...

      How can I avoid creating files under temp directory due to space issue.... OR is there any event/attribute which I can use to clear Temp after upload or final persist.

       

      Here is XHMTL, web.xml and components.xml.

       

      XTML code :

      <h:form id="fileUpload" styleClass="edit" enctype="multipart/form-data">
      <s:decorate id="fileDataDecoration" template="layout/edit.xhtml">
                <h:panelGrid columns="2" columnClasses="top,top">                     
                          <rich:fileUpload fileUploadListener="#{fileUploadManager.listener}"
                                    maxFilesQuantity="#{fileUploadManager.uploadsAvailable}" id="upload" noDuplicate="true" immediateUpload="false" acceptedTypes="*">                
                                    <a4j:support event="onuploadcomplete" reRender="info" />
                          </rich:fileUpload> 
                          <h:panelGroup id="info">
                                    <rich:panel bodyClass="info">
                                              <f:facet name="header">
                                                        <h:outputText value="Uploaded Files Info" />
                                              </f:facet>
                                              <h:outputText value="No files currently uploaded"
                                                        rendered="#{fileUploadManager.fileWrapper.fileList.size==0}" />
                                              <rich:dataGrid columns="1" value="#{fileUploadManager.fileWrapper.fileList}"
                                                        var="file" rowKeyVar="row">
                                                        <rich:panel>
                                                                  <h:panelGrid columns="2">
                                                                            <a4j:mediaOutput element="img" mimeType="#{file.fileType}"
                                                                                      createContent="#{fileUploadManager.paint}" value="#{row}"
                                                                                      style="width:50px; height:50px;" cacheable="false">
                                                                                      <f:param value="#{fileUploadManager.timeStamp}" name="time"/> 
                                                                                       <s:conversationId />
                                                                            </a4j:mediaOutput>
                                                                            <h:panelGrid columns="2">
                                                                                      <h:outputText value="File Name:" />
                                                                                      <h:outputText value="#{file.fileName}" />
                                                                                      <s:link value="#{file.fileName}">Download</s:link>
                                                                                      <h:outputText value="File Length(bytes):" />
                                                                                      <h:outputText value="#{file.fileLength}" />
                                                                            </h:panelGrid>
                                                                  </h:panelGrid>
                                                        </rich:panel>
                                              </rich:dataGrid>
                                    </rich:panel>
                                    <rich:spacer height="3"/>
                                    <br />
                                    <a4j:commandButton action="#{fileUploadManager.clearUploadData}"
                                              reRender="info, upload" value="Clear Uploaded Data"
                                              rendered="#{fileUploadManager.size>0}" />
                          </h:panelGroup>
      
      
       </h:panelGrid> 
      </s:decorate>
      </h:form>
      

       

      Components.xml

      <components xmlns="http://jboss.com/products/seam/components"
                  xmlns:core="http://jboss.com/products/seam/core"
                  xmlns:persistence="http://jboss.com/products/seam/persistence"
                  xmlns:drools="http://jboss.com/products/seam/drools"
                  xmlns:bpm="http://jboss.com/products/seam/bpm"
                  xmlns:security="http://jboss.com/products/seam/security"
                  xmlns:mail="http://jboss.com/products/seam/mail"
                  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                  xmlns:web="http://jboss.com/products/seam/web"
                  xsi:schemaLocation=
                      "http://jboss.com/products/seam/core http://jboss.com/products/seam/core-2.0.xsd 
                       http://jboss.com/products/seam/persistence http://jboss.com/products/seam/persistence-2.0.xsd 
                       http://jboss.com/products/seam/drools http://jboss.com/products/seam/drools-2.0.xsd
                       http://jboss.com/products/seam/bpm http://jboss.com/products/seam/bpm-2.0.xsd
                       http://jboss.com/products/seam/security http://jboss.com/products/seam/security-2.0.xsd
                       http://jboss.com/products/seam/mail http://jboss.com/products/seam/mail-2.0.xsd
                       http://jboss.com/products/seam/components http://jboss.com/products/seam/components-2.0.xsd
                                                              http://jboss.com/products/seam/web http://jboss.com/products/seam/web-2.0.xsd">
      ...
      <web:multipart-filter create-temp-files="false" max-request-size="2147483647" url-pattern="*.seam" />
         
      
         <core:manager concurrent-request-timeout="5000" 
                       conversation-timeout="180000" 
                       conversation-id-parameter="cid"
                       parent-conversation-id-parameter="pid"/>
      

       

      Web.xml

      <?xml version="1.0" ?>
      <web-app xmlns="http://java.sun.com/xml/ns/javaee"
               xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" 
               version="2.5">
         <!-- Ajax4jsf -->
         <filter>
                          <display-name>Ajax4jsf Filter</display-name>
                          <filter-name>ajax4jsf</filter-name>
                          <filter-class>org.ajax4jsf.Filter</filter-class>
                          <init-param>
                                    <param-name>forceparser</param-name>
                                    <param-value>false</param-value>
                          </init-param>
                </filter>
                <filter-mapping>
                          <filter-name>ajax4jsf</filter-name>
                          <servlet-name>Faces Servlet</servlet-name>
                          <dispatcher>REQUEST</dispatcher>
                          <dispatcher>FORWARD</dispatcher>
                          <dispatcher>INCLUDE</dispatcher>
                </filter-mapping>
      
          <context-param>
              <param-name>org.richfaces.SKIN</param-name>
              <param-value>blueSky</param-value>
          </context-param>
      
         <!-- Seam -->    
         <listener>
            <listener-class>org.jboss.seam.servlet.SeamListener</listener-class>
         </listener>
      
          <filter>
              <filter-name>Seam Filter</filter-name>
              <filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
          </filter>
      
      
          <filter-mapping>
              <filter-name>Seam Filter</filter-name>
              <url-pattern>/*</url-pattern>
          </filter-mapping>
      
         <servlet>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <servlet-class>org.jboss.seam.servlet.SeamResourceServlet</servlet-class>
         </servlet>
      
         <servlet-mapping>
            <servlet-name>Seam Resource Servlet</servlet-name>
            <url-pattern>/seam/resource/*</url-pattern>
         </servlet-mapping>
      
         <!-- Facelets development mode (disable in production) -->   
         <context-param>
            <param-name>facelets.DEVELOPMENT</param-name>
            <param-value>true</param-value>
         </context-param>
      
         <!-- JSF -->   
         <context-param>
            <param-name>javax.faces.DEFAULT_SUFFIX</param-name>
            <param-value>.xhtml</param-value>
         </context-param>
      
      
         <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
         </servlet>
      
         <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>*.seam</url-pattern>
         </servlet-mapping>
      
         <security-constraint> 
             <display-name>Restrict raw XHTML Documents</display-name>
             <web-resource-collection>
                 <web-resource-name>XHTML</web-resource-name>
                 <url-pattern>*.xhtml</url-pattern>
             </web-resource-collection>
             <auth-constraint/>
         </security-constraint>
      </web-app>