4 Replies Latest reply on Aug 11, 2010 2:53 PM by Felipe Jaekel

    Problem with Javassist + ClassCastException

    Felipe Jaekel Newbie

      I have recently ported a Seam application form JBoss AS 5.1 to Tomcat 6.0.29.


      After that I started to get a ClassCastException in a HttpSessionListener that I have. I'm not able to simulate it locally. Tomcat session persistence is disabled. I'm using the same Javassist version as JBoss.


      Code:





      @Override
      public void sessionDestroyed(HttpSessionEvent arg0)
      {
           try
           {
                TBTecnico tecnico = (TBTecnico) arg0.getSession().getAttribute("tecnicoLogado");
                if(tecnico != null && tecnico.getAtendente() != null)
                {
                     Lifecycle.beginCall();
      
                     StAtendimentoService stAtendimentoService = (StAtendimentoService) Component
                          .getInstance("stAtendimentoService");
                     stAtendimentoService.finalizarAtendimenosAtendente(tecnico.getAtendente());
                     
                     StAtendenteDisponivelService stAtendenteDisponivelService = 
                          (StAtendenteDisponivelService) Component.getInstance("stAtendenteDisponivelService");
                     stAtendenteDisponivelService.logout(tecnico.getAtendente());
      
                     Lifecycle.endCall();
                }
           }
           catch(Exception e)
           {
                e.printStackTrace();
                new ExceptionMail("SessionListener AreaTecnico", e);
           }
      }






      Sometimes the exception has one stack trace and sometimes another


      Stack trace 1:





      java.lang.ClassCastException: .persistence.mysql.service.chat.StAtendimentoService_$$_javassist_seam_69 cannot be cast to .persistence.mysql.service.chat.StAtendimentoService
           at .tecnico.SessionListener.sessionDestroyed(SessionListener.java:32)
           at org.apache.catalina.session.StandardSession.expire(StandardSession.java:708)
           at org.apache.catalina.session.StandardSession.isValid(StandardSession.java:575)
           at org.apache.catalina.session.ManagerBase.processExpires(ManagerBase.java:700)
           at org.apache.catalina.session.ManagerBase.backgroundProcess(ManagerBase.java:685)
           at org.apache.catalina.core.ContainerBase.backgroundProcess(ContainerBase.java:1316)
           at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1601)
           at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
           at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.processChildren(ContainerBase.java:1610)
           at org.apache.catalina.core.ContainerBase$ContainerBackgroundProcessor.run(ContainerBase.java:1590)
           at java.lang.Thread.run(Thread.java:619)
      







      Stack trace 2:



      java.lang.ClassCastException: .persistence.mysql.service.chat.StAtendimentoService_$$_javassist_seam_69 cannot be cast to .persistence.mysql.service.chat.StAtendimentoService
           at .tecnico.SessionListener.sessionDestroyed(SessionListener.java:32)
           at org.apache.catalina.session.StandardSession.expire(StandardSession.java:708)
           at org.apache.catalina.session.StandardSession.expire(StandardSession.java:643)
           at org.apache.catalina.session.StandardSession.invalidate(StandardSession.java:1148)
           at org.apache.catalina.session.StandardSessionFacade.invalidate(StandardSessionFacade.java:150)
           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:597)
           at org.jboss.seam.contexts.FacesLifecycle.invalidateSession(FacesLifecycle.java:158)
           at org.jboss.seam.contexts.FacesLifecycle.endRequest(FacesLifecycle.java:135)
           at org.jboss.seam.jsf.SeamPhaseListener.afterResponseComplete(SeamPhaseListener.java:525)
           at org.jboss.seam.jsf.SeamPhaseListener.afterServletPhase(SeamPhaseListener.java:253)
           at org.jboss.seam.jsf.SeamPhaseListener.afterPhase(SeamPhaseListener.java:196)
           at com.sun.faces.lifecycle.Phase.handleAfterPhase(Phase.java:175)
           at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:114)
           at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
           at javax.faces.webapp.FacesServlet.service(FacesServlet.java:265)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:83)
           at org.jboss.seam.web.IdentityFilter.doFilter(IdentityFilter.java:40)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.MultipartFilter.doFilter(MultipartFilter.java:90)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.ExceptionFilter.doFilter(ExceptionFilter.java:64)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.RedirectFilter.doFilter(RedirectFilter.java:45)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.ajax4jsf.webapp.BaseXMLFilter.doXmlFilter(BaseXMLFilter.java:178)
           at org.ajax4jsf.webapp.BaseFilter.handleRequest(BaseFilter.java:290)
           at org.ajax4jsf.webapp.BaseFilter.processUploadsAndHandleRequest(BaseFilter.java:388)
           at org.ajax4jsf.webapp.BaseFilter.doFilter(BaseFilter.java:515)
           at org.jboss.seam.web.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:56)
           at .jsf.filter.Ajax4jsfFilter.doFilter(Ajax4jsfFilter.java:41)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.web.HotDeployFilter.doFilter(HotDeployFilter.java:53)
           at org.jboss.seam.servlet.SeamFilter$FilterChainImpl.doFilter(SeamFilter.java:69)
           at org.jboss.seam.servlet.SeamFilter.doFilter(SeamFilter.java:158)
           at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
           at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
           at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
           at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
           at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470)
           at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
           at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
           at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
           at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
           at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:857)
           at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
           at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
           at java.lang.Thread.run(Thread.java:619)







      Thanks for any help,
      Felipe

        • 2. Re: Problem with Javassist + ClassCastException
          Stuart Douglas Master

          can you post some detail about how your app is deployed, and where the seam jars are? It seems to be a classloader problem of some kind, but I don't really know that much about tomcat classloading.

          • 3. Re: Problem with Javassist + ClassCastException
            Stuart Douglas Master

            also can you post the code for StAtendimentoService ?

            • 4. Re: Problem with Javassist + ClassCastException
              Felipe Jaekel Newbie

              Interesting point, when I was using JBoss AS I had to pack Seam jar inside the application(WEB-INF/lib) to avoid problems with the admin console. In Tomcat Seam jar is inside server's global lib folder.


              Deployment is made through a shell script, where the war file is moved to the webapps folder then the server is restarted.


              I'll try to move Seam jar to the application to see if it works.


              Here is the code StAtendenteDisponivelService and of it's base class (MySqlDao).




              package br.com.spdata.persistence.mysql.service.chat;
              
              import java.util.List;
              
              import org.jboss.seam.annotations.AutoCreate;
              import org.jboss.seam.annotations.Name;
              import org.jboss.seam.annotations.Transactional;
              
              import br.com.spdata.persistence.dao.MySqlDao;
              import br.com.spdata.persistence.mysql.entity.chat.StAtendente;
              import br.com.spdata.persistence.mysql.entity.chat.StAtendenteDisponivel;
              
              @AutoCreate
              @Name("stAtendenteDisponivelService")
              public class StAtendenteDisponivelService extends MySqlDao<StAtendenteDisponivel, Integer>
              {
                   @Override
                   @Transactional
                   public void persist(StAtendenteDisponivel t)
                   {
                        if(t.getId() == null)
                        {
                             em.persist(t);
                             em.flush();
                             em.refresh(t);
                        }
                        else
                        {
                             em.merge(t);
                        }          
                   }
                   
                   @SuppressWarnings("unchecked")
                   public List<StAtendenteDisponivel> findAtendentesDisponiveis()
                   {
                        return em.createNamedQuery("StAtendenteDisponivel.findAtendentesDisponiveis")
                             .getResultList();
                   }
              
                   @Transactional
                   public void logout(StAtendente atendente)
                   {
                        em.createNamedQuery("StAtendenteDisponivel.logout")
                             .setParameter("atendente", atendente)
                             .executeUpdate();          
                   }     
              }





              package br.com.spdata.persistence.dao;
              
              
              
              import java.io.Serializable;
              
              import java.lang.reflect.ParameterizedType;
              
              import java.util.List;
              
              
              
              import javax.persistence.EntityManager;
              
              
              
              import org.hibernate.Session;
              
              import org.jboss.seam.ScopeType;
              
              import org.jboss.seam.annotations.In;
              
              import org.jboss.seam.annotations.Scope;
              
              import org.jboss.seam.annotations.Transactional;
              
              
              
              @Scope(ScopeType.STATELESS)
              
              public abstract class MySqlDao<T, ID> implements Serializable
              
              {
              
                   private static final long                    serialVersionUID     = 1L;
              
              
              
                   @In("#{entityManager}")
              
                   protected transient EntityManager     em;
              
              
              
                   public MySqlDao()
              
                   {
              
                   }
              
              
              
                   @SuppressWarnings("unchecked")
              
                   public Class<T> getPersistentClass()
              
                   {
              
                        return (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass())
              
                             .getActualTypeArguments()[0];
              
                   }
              
              
              
                   @Transactional
              
                   public void persist(T t)
              
                   {
              
                        em.merge(t);
              
                   }
              
              
              
                   @Transactional
              
                   public void remove(T entity)
              
                   {
              
                        if(!em.contains(entity))
              
                        {
              
                             entity = em.merge(entity);
              
                        }
              
                        em.remove(entity);
              
                   }
              
              
              
                   public T findById(ID id)
              
                   {
              
                        return em.find(getPersistentClass(), id);
              
                   }
              
                   
              
                   public void refresh(T entity)
              
                   {
              
                        em.refresh(em.merge(entity));
              
                   }
              
              
              
                   @SuppressWarnings("unchecked")
              
                   public List<T> findAll()
              
                   {
              
                        return em.createNamedQuery(getPersistentClass().getSimpleName() + ".findAll")
              
                             .getResultList();
              
                   }
              
              
              
                   public Session getSession()
              
                   {
              
                        return (Session) em.getDelegate();
              
                   }
              
              
              
                   public String getEntityExistsMessage()
              
                   {
              
                        return "Já existe um registro com os dados informados";
              
                   }
              
              }
              
              



              Thanks,
              Felipe