0 Replies Latest reply: Apr 25, 2012 3:13 PM by Steve Chernyak RSS

    PortableRemoteObject.narrow throws ClassCastException

    Steve Chernyak Newbie

      I have 2 deployment units:

           An ear file the deploys a session bean:

                ejb-jar xml:

           <enterprise-beans>
                          <session>
                                    <display-name>UserManager</display-name>
                                    <ejb-name>UserManager</ejb-name>
                                    <home>com.package.UserManagerHome</home>
                                    <remote>com.package.UserManager</remote>
                                    <ejb-class>com.package.UserManagerBean</ejb-class>
                                    <session-type>Stateless</session-type>
                                    <transaction-type>Container</transaction-type>
                                    <resource-ref>
                                              <res-ref-name>SSO-DB</res-ref-name>
                                              <res-type>javax.sql.DataSource</res-type>
                                              <res-auth>Container</res-auth>
                                    </resource-ref>
                          </session>
                </enterprise-beans>
      
      

                jboss.xml:

       

           <jboss>
                     <enterprise-beans>
                               <session>
                                 <ejb-name>UserManager</ejb-name>
                                         <jndi-name>SingleSignOn/UserManager</jndi-name>
                                    <resource-ref>
                                              <res-ref-name>SSO-DB</res-ref-name>
                                              <jndi-name>java:/oraclePool</jndi-name>
                                    </resource-ref>
                          </session>
                     </enterprise-beans>
           </jboss>
      
      

           A war file:

                web.xml:

       

      <web-app>
            
          ....     
      
             <ejb-ref>
                          <ejb-ref-name>ejb/UserManager</ejb-ref-name>
                          <ejb-ref-type>Session</ejb-ref-type>
                          <home>com.package.UserManagerHome</home>
                          <remote>com.package.UserManager</remote>
                </ejb-ref>
      
      
      </web-app>
      
      

                jboss-web.xml:

       

      <jboss-web>
          <ejb-ref>
              <ejb-ref-name>ejb/UserManager</ejb-ref-name>
              <jndi-name>SingleSignOn/UserManager</jndi-name>
          </ejb-ref>
      </jboss-web>
      
      

                jboss-classloading.xml

       

      <classloading xmlns="urn:jboss:classloading:1.0"
                    parent-first="false"
                    domain="DefaultDomain"
                    top-level-classloader="true"
                    parent-domain="Ignored"
                    export-all="NON_EMPTY" 
                    import-all="true">
      </classloading>
      
      

      The ear deployer is set to isolate ear classloaders:

       

       <bean name="EARClassLoaderDeployer" class="org.jboss.deployment.EarClassLoaderDeployer">
            <!-- A flag indicating if ear deployments should have their own scoped
               class loader to isolate their classes from other deployments.
            -->
            <property name="isolated">true</property>
       </bean>
      
      
      

       

      The ejb client jar (built with maven) and all of the *.xml configurations excluded is package with the war.

       

      The home object is loaded by the war classloader in the war and the ear classloader in the ear (according to jmx-console).

       

      When I attempt to do a lookup:

       

      Object obj = new InitialContext().lookup("java:comp/env/ejb/UserManager");
      UserManagerHome home = (UserManagerHome) PortableRemoteObject.narrow(obj, UserManagerHome.class);
      
      

       

      I get an exception:

       

      java.lang.ClassCastException: $Proxy140 cannot be cast to org.omg.CORBA.Object
                com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:228)
                javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:153)
                com.package.SingleSignOnBaseServlet.getUserManager(SingleSignOnBaseServlet.java:107)
                com.package.PasswordCheckServlet.loginUser(PasswordCheckServlet.java:83)
                com.package.PasswordCheckServlet.doPost(PasswordCheckServlet.java:44)
                javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
                javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1063)
                org.apache.struts.tiles.TilesRequestProcessor.doForward(TilesRequestProcessor.java:263)
                org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:386)
                org.apache.struts.tiles.TilesRequestProcessor.processForwardConfig(TilesRequestProcessor.java:318)
                org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:229)
                org.apache.struts.action.ActionServlet.process(ActionServlet.java:1194)
                org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:432)
                com.ams.identicaterd.action.IdenticateRulesDesignerActionServlet.doPost(IdenticateRulesDesignerActionServlet.java:92)
                javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
                javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
                org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
      
      

       

       

      I would like to have the ability to share the session bean between a bunch of web applications that are developed and deployed indipendantly. I'm willing to take the performance hit of treating the call as remote. Is it possible to deploy a single EAR with a session bean jar and multiple wars indipendantly with isolated classloaders and avoid getting this error? I'm assuming the issue is having multiple class instances in the same jvm.

       

      Thanks