9 Replies Latest reply on Jul 27, 2006 8:42 AM by bfo81

    Stateless Converter: First works, then ClassNotFoundExceptio

    bfo81

      I have an entity Person that has a ManyToMany relation to other Persons ("friends" ;)). When editing one person there's a SelectManyMenu showing all Persons and you can select or deselect friends.

      The SelectManyMenu has a Converter (... converter="#{personConverter}"), of course. This one is implemented as a Stateless Session Bean with @Name("personConverter") and the two methods getAsString(...) and getAsObject(...).

      The persons are filled into that List by <f:selectItems value="#{personListe.selectItems}" />. You guess it, the selectItems() method returns a List, which's items are all added like this: ...add(new SelectItem(aPerson.getId(), aPerson.getName()));

      So far so good. Should be nothing special here ;).

      When going to the edit page everything works fine, and the Log shows me that the getAsString-method is called for every Person in the list.

      BUT: As soon as a safe the edited person (and it doesn't play a role whether I select friends or not) there's an Exception:

      FATAL [org.apache.myfaces.renderkit.html.HtmlRepsonseStateManager] Cannot decode Object from Base64 String
      java.lang.ClassNotFoundException: No ClassLoaders found for: de.beffo.test.converter.PersonConverter
       at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
       at ...


      Well... how can it be that the Converter is found when the page is displayed, and not found right after submitting? Anyone having experience with such a behaviour?


        • 1. Re: Stateless Converter: First works, then ClassNotFoundExce
          bfo81

          Errrrr.....


          what confuses me:

          It seems like the Exception is thrown in the decode64()-method of org.apache.myfaces.renderkit.html.HtmlResponseStateManager. I had a look in the MyFaces-Impl-Jar that came with Seam.... and guess what? This method doesn't exist there. And I found out that Seam has MyFaces 1.1.3, but it seems that JBoss-4.0.4.GA uses MyFaces 1.1.1 which is in $JBOSS_HOME/server/default/deploy/jbossweb-tomcat55.sar/jsf-libs. And the 1.1.1 version has that decode64() method, so the old version is being used.

          ...HOWEVER...

          I overwrote the old MyFaces Jars with the new ones, but the error persists... with a slightly different Exception (but still ClassNotFound):

          2006-07-26 14:45:21,890 ERROR [org.apache.myfaces.lifecycle.PhaseListenerManager] Exception in PhaseListener RESTORE_VIEW(1) afterPhase
          java.lang.NullPointerException
           at org.jboss.seam.contexts.PageContext.getAttributeMap(PageContext.java:103)
           at org.jboss.seam.contexts.PageContext.<init>(PageContext.java:40)
           at org.jboss.seam.contexts.Lifecycle.resumePage(Lifecycle.java:323)
           at org.jboss.seam.jsf.AbstractSeamPhaseListener.restoreAnyConversationContext(AbstractSeamPhaseListener.java:39)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:63)
           at org.jboss.seam.jsf.SeamExtendedManagedPersistencePhaseListener.afterPhase(SeamExtendedManagedPersistencePhaseListener.java:55)
           at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:89)
           at org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:181)
           at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:30)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
           at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
           at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
           at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
           at java.lang.Thread.run(Thread.java:595)
          2006-07-26 14:45:21,890 ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/test].[Faces Servlet]] Servlet.service() for servlet Faces Servlet threw exception
          javax.faces.FacesException: java.lang.ClassNotFoundException: No ClassLoaders found for: de.beffo.test.converter.PersonConverter
           at org.apache.myfaces.shared_impl.util.StateUtils.getAsObject(StateUtils.java:283)
           at org.apache.myfaces.shared_impl.util.StateUtils.reconstruct(StateUtils.java:217)
           at org.apache.myfaces.renderkit.html.HtmlResponseStateManager.getComponentStateToRestore(HtmlResponseStateManager.java:221)
           at org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreComponentState(JspStateManagerImpl.java:186)
           at org.apache.myfaces.application.jsp.JspStateManagerImpl.restoreView(JspStateManagerImpl.java:287)
           at org.jboss.seam.jsf.SeamStateManager.restoreView(SeamStateManager.java:41)
           at org.apache.myfaces.application.jsp.JspViewHandlerImpl.restoreView(JspViewHandlerImpl.java:255)
           at org.jboss.seam.jsf.SeamViewHandler.restoreView(SeamViewHandler.java:64)
           at com.sun.facelets.FaceletViewHandler.restoreView(FaceletViewHandler.java:353)
           at org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:141)
           at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:30)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
           at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:175)
           at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:74)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:869)
           at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:664)
           at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
           at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
           at java.lang.Thread.run(Thread.java:595)
          Caused by: java.lang.ClassNotFoundException: No ClassLoaders found for: de.beffo.test.converter.PersonConverter
           at org.jboss.mx.loading.LoadMgr3.beginLoadTask(LoadMgr3.java:212)
           at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:511)
           at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:405)
           at java.lang.ClassLoader.loadClass(ClassLoader.java:251)
           at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:319)
           at java.lang.Class.forName0(Native Method)
           at java.lang.Class.forName(Class.java:242)
           at java.io.ObjectInputStream.resolveProxyClass(ObjectInputStream.java:656)
           at java.io.ObjectInputStream.readProxyDesc(ObjectInputStream.java:1499)
           at java.io.ObjectInputStream.readClassDesc(ObjectInputStream.java:1462)
           at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1698)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
           at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1633)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1298)
           at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1633)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1298)
           at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1633)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1298)
           at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1633)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1298)
           at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
           at java.util.ArrayList.readObject(ArrayList.java:591)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:946)
           at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1818)
           at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1718)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
           at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1633)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1298)
           at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
           at java.util.ArrayList.readObject(ArrayList.java:591)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:946)
           at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1818)
           at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1718)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
           at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1633)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1298)
           at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
           at java.util.ArrayList.readObject(ArrayList.java:591)
           at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
           at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
           at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
           at java.lang.reflect.Method.invoke(Method.java:585)
           at java.io.ObjectStreamClass.invokeReadObject(ObjectStreamClass.java:946)
           at java.io.ObjectInputStream.readSerialData(ObjectInputStream.java:1818)
           at java.io.ObjectInputStream.readOrdinaryObject(ObjectInputStream.java:1718)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1304)
           at java.io.ObjectInputStream.readArray(ObjectInputStream.java:1633)
           at java.io.ObjectInputStream.readObject0(ObjectInputStream.java:1298)
           at java.io.ObjectInputStream.readObject(ObjectInputStream.java:349)
           at org.apache.myfaces.shared_impl.util.StateUtils.getAsObject(StateUtils.java:274)
           ... 32 more


          • 2. Re: Stateless Converter: First works, then ClassNotFoundExce
            bfo81

            Ok...

            I removed @Stateless and the Local interface and turned the converter into a pure JavaBean. Now there are no more errors (except it doesn't work the way I want but that's something different ;)). BUT: Injections don't work. Neither @PersitenceContext nor @Logger are there, they're all null.

            So I have the choice: Stateless Session Bean that can't be found after submitting... or normal JavaBean where Injection doesn't work.

            PS: Yes, I know. I could do it the old-fashioned way using the faces-config.xml and Converter-Ids. But hey, since I use Seam I want my Converters to be Seam Components, too ^^.

            PPS: In case I'll jump out off the window the next hours all my assets should go to the Foundation Of Crazy-Driven J2EE Users ;).

            • 3. Re: Stateless Converter: First works, then ClassNotFoundExce
              pmuir

              You could use a JavaBean and lookup the EntityManager using JNDI. It should still be a Container Manged Persistence context (but it won't be Seam Managed).

              • 4. Re: Stateless Converter: First works, then ClassNotFoundExce
                theute

                You forgot to add the SeamInterceptor to your JavaBean

                • 5. Re: Stateless Converter: First works, then ClassNotFoundExce
                  bfo81

                  @petemuir:
                  I thought about that, too. But it's somehow unaesthetic. In this respect I'm like a little child: If there is Dependency Injection I want to have it ;).

                  @thomas:
                  Ooops. That's something I overread in the manual. Since working with EJBs all the time this was the first time I encountered problems with leaving out the Interceptor. So thanks for the hint, the Bean works now :).

                  But a few questions to understand everything better:

                  - All beans need a SeamInterceptor, otherwise Injection doesn't work, right?

                  - With ejb-jar.xml it's possible to put that Interceptor around every EJB automatically without needing to add it to every single EJB explicitly (very nice), correct?

                  - But: Why aren't there any Interceptors in the Hibernate example? I mean the action beans have a LoginInterceptor that calls BijectionInterceptor etc., but what about the entity beans?

                  Plus: I'm still wondering very much why the EJB converter first worked and then not.

                  • 6. Re: Stateless Converter: First works, then ClassNotFoundExce
                    bfo81

                    Hm... my cheers were to early. It's really funny, but the debug log goes like this:

                    Calling the edit page

                    em=org.hibernate.ejb.EntityManagerImpl@d8f5e8

                    Submitting the edit page plus redisplay afterwards (validation fault)

                    em=null

                    Cancelling, going back to list and editing something else

                    em=org.hibernate.ejb.EntityManagerImpl@3eed51

                    The EntityManager never stays the same. Sometimes it's null, and when not it's always newly instantiated (see the code at the end of org.hibernate...@).

                    Maybe it's the right time to finally post some code ;)

                    package de.beffo.test.converter;
                    
                    import javax.faces.component.UIComponent;
                    import javax.faces.context.FacesContext;
                    import javax.faces.convert.Converter;
                    import javax.faces.convert.ConverterException;
                    import javax.interceptor.Interceptors;
                    import javax.persistence.EntityManager;
                    
                    import org.apache.commons.logging.LogFactory;
                    import org.jboss.seam.ScopeType;
                    import org.jboss.seam.annotations.In;
                    import org.jboss.seam.annotations.Name;
                    import org.jboss.seam.annotations.Scope;
                    import org.jboss.seam.ejb.SeamInterceptor;
                    
                    import de.beffo.test.model.Person;
                    
                    //@Stateless
                    @Scope(ScopeType.SESSION)
                    @Name("personConverter")
                    @Interceptors(SeamInterceptor.class)
                    public class PersonConverterBean implements Converter {
                    
                     @In(create=true)
                     private EntityManager em;
                    
                     public Object getAsObject(FacesContext facesContext, UIComponent uiComponent, String string) throws ConverterException {
                     LogFactory.getLog(this.getClass()).info("getAsObject: string=" + string + " em="+em);
                     return new Person();//em.find(Person.class, Long.parseLong(string));
                     }
                    
                     public String getAsString(FacesContext facesContext, UIComponent uiComponent, Object object) throws ConverterException {
                     LogFactory.getLog(this.getClass()).info("getAsString: object=" + object + " em=" +em);
                    
                     return object.toString();
                     }
                    
                    }
                    


                    • 7. Re: Stateless Converter: First works, then ClassNotFoundExce
                      theute

                      - Yes, if you want Seam annotations to work you need the SeamInterceptor
                      - Yes
                      - Mmm i think that there is no Seam annotations in those entity beans. In which specific file are you wondering about the lack of Interceptor ?

                      • 8. Re: Stateless Converter: First works, then ClassNotFoundExce
                        bfo81

                         

                        "thomas.heute@jboss.com" wrote:
                        - Mmm i think that there is no Seam annotations in those entity beans. In which specific file are you wondering about the lack of Interceptor ?

                        Ok, silly question by me, since there are only persistence annotations. Thanks for the answers.

                        • 9. Re: Stateless Converter: First works, then ClassNotFoundExce
                          bfo81

                          Well, after trying out a lot I'd say that Stateless and Stateful Session Beans just don't work as Converters. Don't ask me why...

                          But I made the JavaBean (posted above) work by adding Serializable... DOH!!!

                          In fact, what makes me wonder: JSF ALWAYS recreates the Converter (I found this out by logging the converter's hashcode, and it's always a new one). Maybe that's why EJBs didn't work, because JSf wanted to invoke the constructor of the interface (PersonConverter), not of the class (PersonConverterBean). But then it'd be very weird that the Converters need to be Serializable. Why serializing when omitting deserialization and constructing instead?

                          After all this I'm 20 years older, very confused, but happy that it finally works ;).