2 Replies Latest reply on Oct 28, 2008 8:02 AM by Marvin Monroe

    rich:fileUpload causes NotSerializableException (sometimes)

    Marvin Monroe Newbie


      I'm trying to include RichFaces' fileUpload component in my page. The environment is Seam 2.0.2, RichFaces 3.2.2 and JBoss 4.2.3. The bean that cares for the uploaded data is in the Seam-scope 'Page'.

      Sometimes there is a NotSerializableException during uploading something:

      [JBossCacheService] externalizeSession(): exception occurred externalizing session SessionBasedClusteredSession[id: oJhsKHwLozp4EMAOaslBTg** lastAccessedTime: 1225138071826 version: 75 lastOutdated: 0]
      java.io.NotSerializableException: org.ajax4jsf.request.MultipartRequest
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1156)
       at java.io.ObjectOutputStream.writeObject(ObjectOutputStream.java:326)
       at java.util.HashMap.writeObject(HashMap.java:1001)
       at sun.reflect.GeneratedMethodAccessor166.invoke(Unknown Source)
       at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
       at java.lang.reflect.Method.invoke(Method.java:597)
       at java.io.ObjectStreamClass.invokeWriteObject(ObjectStreamClass.java:945)
       at java.io.ObjectOutputStream.writeSerialData(ObjectOutputStream.java:1461)
       at java.io.ObjectOutputStream.writeOrdinaryObject(ObjectOutputStream.java:1392)
       at java.io.ObjectOutputStream.writeObject0(ObjectOutputStream.java:1150)
       at java.io.ObjectOutputStream.defaultWriteFields(ObjectOutputStream.java:1509)
       at java.io.ObjectOutputStream.defaultWriteObject(ObjectOutputStream.java:416)
       at java.util.Collections$SynchronizedMap.writeObject(Collections.java:2029)
      ... and a bit more...

      As far as I am with the development of the page, it seems that it does not affect the uploaded file, so the server receives everything. But I'm not happy with getting those strange exceptions :/
      I see that org.ajax4jsf.request.MultipartRequest is definitely not serializable - but why does this serialization happen at all?

      I looked at the source code of org.ajax4jsf.request.MultipartRequest and org.ajax4jsf.webapp.BaseFilter.
      When I start the upload the method processUploadsAndHandleRequest(line 294, BaseFilter) is called.
      Soon it starts to create an instance of MultipartRequest and puts it later into a map.

      [line 337, BaseFilter] sessionsMap.put(uid, multipartRequest);

      When I debug and stop at this line, the exception above is thrown over and over again. I used a PhaseListener to print the current phase on the command line. It seems that the fileUpload component is polling each second the state (or whatever) of the current upload. And in the same time the JBossCacheService seems to try to serialize the current session (for clustering, if I read that message right). It's clear that it doesnt work, but I think this code was supposed to work and I missed something?

      Well now I need some help in understanding what happens here in the background. What am I doing wrong to get this error? It does not occure if the upload is faster than the polling, only if the polling happens when the BaseFilter is around line 337.

      So did I find a bug or is it all my fault?