ClassCastException during ContextInitialization using Statel
wcydaip Jun 3, 2005 3:44 PMI 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