4 Replies Latest reply on Jun 15, 2005 2:59 PM by wcydaip

    ClassCastException during ContextInitialization using Statel

    wcydaip

      I recently upgraded to jboss-4.0.2 unsucessfully. The problem appears to be during the context initialization.

      =DEBUG [main] (com.systemadmin.util.ContextListener:51) - contextInitialized(ServletContextEvent() called!)
      =DEBUG [main] (com.systemadmin.util.ContextListener:58) - entering setApplicationsAndRoles(ApplicationRoleModel)
      =ERROR [main] (org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/systemadmin]:3673) - Exception sending context initialized event to listener instance of class com.systemadmin.util.ContextListener
      java.lang.ClassCastException
       at com.systemadmin.ejb.AdministrationUtil.getLocalHome(AdministrationUtil.java:55)
       at com.systemadmin.delegate.AdministrationDelegate.getAdministrationLocalEJB(AdministrationDelegate.java:215)
       at com.systemadmin.delegate.AdministrationDelegate.findApplicationsAndRoles(AdministrationDelegate.java:68)
       at com.systemadmin.util.ContextListener.setApplications(ContextListener.java:66)
       at com.systemadmin.util.ContextListener.contextInitialized(ContextListener.java:54)
       at org.apache.catalina.core.StandardContext.listenerStart(StandardContext.java:3669)
       at org.apache.catalina.core.StandardContext.start(StandardContext.java:4104)
       at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:759)
       at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:739)
       at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:524)
       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:324)
      


      Here's the code:
       /* (non-Javadoc)
       * @see javax.servlet.ServletContextListener#contextInitialized(javax.servlet.ServletContextEvent)
       */
       public void contextInitialized(ServletContextEvent servletContextEvent) {
       logger.debug("contextInitialized(ServletContextEvent() called!)");
       context = (ServletContext)servletContextEvent.getServletContext();
       ApplicationRoleModel model = new ApplicationRoleModel();
       setApplications(model);
       context.setAttribute(Constants.MODEL_APPLICATION_ROLE,model);
       }
       private void setApplications(ApplicationRoleModel model){
       logger.debug("entering setApplicationsAndRoles(ApplicationRoleModel)");
       /*
       *
       * Gets the available applications from session bean administration
       */
       AdministrationDelegate delegate = new AdministrationDelegate();
       ArrayList appsRoles;
       try{
       appsRoles = delegate.findApplicationsAndRoles();
       //logger.debug("appsandroles -- > "+appsRoles.size());
       model.setApplications(appsRoles);
       }catch(ApplicationException ex){
       logger.debug("Failed initializing application roles data: "+ex);
       }
       logger.debug("leaving setApplicationsAndRoles(ApplicationRoleModel)");
       }
      

       public ArrayList findApplicationsAndRoles() throws ApplicationException{
       try{
       AdministrationLocal local = getAdministrationLocalEJB();
       return local.findApplicationsAndRoles();
       }catch(SystemException ex){
       if(ex.isRecoverable()){
       throw new ApplicationException(ApplicationException.RECOVERABLE_SYSTEM_EXCEPTION,ex.getMessage());
       }else{
       throw new ApplicationException(ApplicationException.UNRECOVERABLE_SYSTEM_EXCEPTION,ex.getMessage());
       }
       }
       }
       /**
       * getAdministrationLocalEJB
       * @return
       * @throws ApplicationException
       */
       private AdministrationLocal getAdministrationLocalEJB() throws ApplicationException{
       AdministrationLocal local;
       try {
       // create local reference
       AdministrationLocalHome home = AdministrationUtil.getLocalHome();
       local = home.create();
      
       } catch (CreateException ce) {
       logger.debug("ce "+ce.getMessage());
       throw new ApplicationException(ce.getMessage());
       } catch (NamingException ex){
       logger.debug("ex "+ex.getMessage());
       throw new ApplicationException(ex.getMessage());
       }
       return local;
       }
      


      The same code runs fine on 4.0.1sp1. I'm not so familiar with the
      classloading techniques and stumbled through the documentation online,
      but, if that's where the problem lies then i'll go back through it. Just need
      some pointers and maybe a little luck.


      Thanks,

      Graham

        • 1. Re: ClassCastException during ContextInitialization using St
          wcydaip

          There's additional information in the server log after startup about MBeans being the root cause:

          =ERROR [main] (org.jboss.deployment.scanner.URLDeploymentScanner:527) - Incomplete Deployment listing:
          
          --- Incompletely deployed packages ---
          org.jboss.deployment.DeploymentInfo@841d5be3 { url=file:/C:/jboss-4.0.2/server/default/deploy/administration.ear }
           deployer: org.jboss.deployment.EARDeployer@3a9d95
           status: Deployment FAILED reason: URL file:/C:/jboss-4.0.2/server/default/tmp/deploy/tmp56868administration.ear-contents/system_web-exp.war/ deployment failed
           state: FAILED
           watch: file:/C:/jboss-4.0.2/server/default/deploy/administration.ear
           altDD: null
           lastDeployed: 1117826809387
           lastModified: 1117826796000
           mbeans:
          
          --- MBeans waiting for other MBeans ---
          ObjectName: jboss.web.deployment:id=324750195,war=system_web.war
           State: FAILED
           Reason: org.jboss.deployment.DeploymentException: URL file:/C:/jboss-4.0.2/server/default/tmp/deploy/tmp56868administration.ear-contents/system_web-exp.war/ deployment failed
          
          --- MBEANS THAT ARE THE ROOT CAUSE OF THE PROBLEM ---
          ObjectName: jboss.web.deployment:id=324750195,war=system_web.war
           State: FAILED
           Reason: org.jboss.deployment.DeploymentException: URL file:/C:/jboss-4.0.2/server/default/tmp/deploy/tmp56868administration.ear-contents/system_web-exp.war/ deployment failed
          
          
          =DEBUG [main] (org.jboss.deployment.scanner.AbstractDeploymentScanner$ScannerThread:151) - Notified that enabled: true
          =DEBUG [main] (org.jboss.deployment.scanner.URLDeploymentScanner:300) - Started jboss.deployment:flavor=URL,type=DeploymentScanner
          =DEBUG [main] (org.jboss.system.ServiceController:433) - Starting dependent components for: jboss.deployment:flavor=URL,type=DeploymentScanner dependent components: []
          =DEBUG [main] (org.jboss.deployment.MainDeployer:971) - End deployment start on package: jboss-service.xml
          =DEBUG [main] (org.jboss.deployment.MainDeployer:776) - Deployed package: file:/C:/jboss-4.0.2/server/default/conf/jboss-service.xml
          =DEBUG [main] (org.jboss.web.tomcat.tc5.Tomcat5:518) - Saw org.jboss.system.server.started notification, starting connectors
          = INFO [main] (org.apache.coyote.http11.Http11Protocol:188) - Starting Coyote HTTP/1.1 on http-0.0.0.0-8080
          = INFO [main] (org.apache.jk.common.ChannelSocket:366) - JK: ajp13 listening on /0.0.0.0:8009
          = INFO [main] (org.apache.jk.server.JkMain:342) - Jk running ID=0 time=0/250 config=null
          = INFO [main] (org.jboss.system.server.Server:456) - JBoss (MX MicroKernel) [4.0.2 (build: CVSTag=JBoss_4_0_2 date=200505022023)] Started in 2m:1s:635ms


          Also, I forgot to say, I'm using j2sdk1.4.2_06.

          • 2. Re: ClassCastException during ContextInitialization using St
            wcydaip

            I hope this doesn't come back to haunt me later, but, this article explains how to get the classloading back to what it was doing in 4.0.1sp1:
            http://jira.jboss.com/jira/browse/JBAS-1691

            Could someone help me understand the difference between the two classloaders? Why would one be favored over the other?

            Thanks,

            Graham

            • 3. Re: ClassCastException during ContextInitialization using St
              starksm64
              • 4. Re: ClassCastException during ContextInitialization using St
                wcydaip

                So, I've been patiently working through this and am getting closer to solving the class loading issues, but, still have a few quirks to work out.

                I have read the JBossClassLoadingUseCases and found http://wiki.jboss.org/wiki/Wiki.jsp?page=ClassLoadingConfiguration to be very useful.

                Based on the article ClassLoadingConfiguration I have been able to Isolate my classes and deploy my application, however, in doing so I have lost the ability to interact with another .ear.

                My application depends on a security.ear which holds common classes in a .jar file and its own ejb classes.

                When I deploy my app with the security.jar file embedded in the web-inf/lib I get a ClassCastException.

                When I deploy without the security.jar file I get a ClassNotFoundException.

                I'm at a loss for what to do next...

                Any suggestions appreciated.