Migrating files with multiple files does not work.

I am trying to do a file upload to grids with PF 5.1 and OmniFaces version 1.7.

My .xhtml code:

<h:form id="fileImportForm" styleClass="prepend-top"
    prependId="false">

    <div style='margin-bottom:10px'>
        <h:outputLabel value="#{msg.file_import_msg}"/>
    </div>
    <p:fileUpload id="fileImport" fileUploadListener="#{fileImport.handleFileUpload}"   
        mode="advanced"  
        update="messages"   
        multiple="true"
        label="#{msg.file_import_choose_label}" 
        uploadLabel="#{msg.file_import_upload_label}" 
        cancelLabel="#{msg.file_import_cancel_label}"       
    />  
    <p:growl id="messages" showDetail="true"/>  

</h:form>

      

My bean support:

package test.boundary;

import javax.inject.Named;
import org.primefaces.event.FileUploadEvent;
import com.haslerrail.aura.common.exception.SystemException;

/**
 * BackingBean for <code>fileImport.xhtml</code> page.
 *
 */
@Named
public class FileImport implements java.io.Serializable {

    private static final long serialVersionUID = 1L;

    public void handleFileUpload(final FileUploadEvent event) throws SystemException, InterruptedException {

        if (event == null || event.getFile() == null || event.getFile().getSize() == 0) {
            System.out.println("No file");

        }
        System.out.println(event.getFile().getFileName());
        Thread.sleep(500); // wait a little to force the exception!
    }
}

      

The problem is that when my handleFileUpload function takes a little longer to parse the uploaded file (Thread.sleep (500), it throws an exception! The exception is thrown only when more than one file is uploaded at the same time.

An exception:

09:47:33,171 WARN  [org.jboss.weld.Conversation] WELD-000315 Failed to acquire conversation lock in 1,000 for Conversation with id: 1
09:47:33,180 SEVERE [org.omnifaces.exceptionhandler.FullAjaxExceptionHandler] FullAjaxExceptionHandler: An exception occurred during processing JSF ajax request. Error page '/pages/error/error.xhtml' will be shown.: org.jboss.weld.context.BusyConversationException: WELD-000322 Conversation lock timed out: 1
    at org.jboss.weld.context.AbstractConversationContext.activate(AbstractConversationContext.java:215) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.jboss.weld.jsf.WeldPhaseListener.activateConversations(WeldPhaseListener.java:108) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.jboss.weld.jsf.WeldPhaseListener.beforePhase(WeldPhaseListener.java:85) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at com.sun.faces.lifecycle.Phase.handleBeforePhase(Phase.java:228) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:99) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:116) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:593) [jboss-jsf-api_2.1_spec-2.0.1.Final.jar:2.0.1.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:102) [primefaces-5.1.jar:5.1]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.5.AS71.Final.jar:2012-02-10 15:31]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.omnifaces.filter.CacheControlFilter.doFilter(CacheControlFilter.java:226) [omnifaces-1.7.jar:1.7]
    at org.omnifaces.filter.HttpFilter.doFilter(HttpFilter.java:77) [omnifaces-1.7.jar:1.7]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:489) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.jpa.interceptor.WebNonTxEmCloserValve.invoke(WebNonTxEmCloserValve.java:50) [jboss-as-jpa-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.13.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:671) [jbossweb-7.0.13.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:930) [jbossweb-7.0.13.Final.jar:]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_75]  

      

It looks like a bug in PF 5.1 to me! Any other ideas?

+3


source to share


1 answer


p:fileUpload multiple="true"

downloads each file at its own request. The problem is the requests are running concurrently, which in your case causes the conversation blocking timeout as each request tries to access the same chain. Another problem is that JSF actually requires client code to send requests sequentially, and its server code is not thread safe.

I advise that download requests are executed sequentially. There are several ways to achieve this.



  • PrimeFaces 5.2.6 and up: you should just use the attribute sequential

    :

    <p:fileUpload sequential="true" ...
    
          

    (The attribute was implemented in PF Issue # 403. )

  • This answer offers a way through Javascript, customizing the jQuery file upload module that PrimeFaces uses.

  • Add the Weld dependency. Then you can change the default lock timeout (not in a portable CDI fashion) so requests queue up on the server. The default lock timeout is 1 second. The following code changes the world lock timeout for all chains.

    import javax.enterprise.context.ConversationScoped;
    import javax.enterprise.context.Initialized;
    import javax.enterprise.event.Observes;
    import javax.inject.Inject;
    import javax.servlet.ServletRequest;
    import org.jboss.weld.context.http.HttpConversationContext;
    
    public class ConversationTimeoutDefaultSetter {
    
        @Inject
        private HttpConversationContext ctx;
    
        public void conversationInitialized(
                @Observes @Initialized(ConversationScoped.class)
                ServletRequest payload) {
            ctx.setConcurrentAccessTimeout(10000L); // 10 seconds
        }
    
    }
    
          

Update: I forgot what Initialized

CDI 1.1 requires and you seem to be using 1.0. You can set a timeout when you are begin

on a call.

+7


source







All Articles