9 Replies Latest reply on Oct 17, 2010 1:45 PM by Manoj Dhanji

    classCastException while casting ejb Home's proxy.

    Surajit Sengupta Newbie

      Hi All,
      I'm getting a classCastException when I'm casting a ejb Proxy to a home. Please help me out, I'm stuck badly. The details are given below:

      I am using the following versions of the softwares
      JDK : j2sdk1.4.2_04
      JBOSS: jboss-4.0.2
      Eclipse: 3.0.1
      JBossIDE eclipse Plugin: 1.4.1.e30

      I was trying with the SimpleCalc Application of Getting started document of JBoss-IDE.
      I have created a .ear file of my application and deployed it to jboss server.
      I have an ejb named Calculator
      From the servlet I have found the ejb with the JNDI name.
      The code for the same is :

      Object ref = context.lookup("ejb/Calculator");

      printed the proxy class
      System.out.println("Info: Proxy Class is =====> "+ref.getClass());

      and the proxy classes name printed in console is : $Proxy50
      But when I'm trying to cast the proxy to the Calculator EJB's Home, by:
      home = (CalculatorHome) PortableRemoteObject.narrow(ref,CalculatorHome.class);

      it is giving the following error:



      12:39:36,064 INFO [STDOUT] java.lang.ClassCastException
      12:39:36,080 INFO [STDOUT] at com.sun.corba.se.internal.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:293)
      12:39:36,080 INFO [STDOUT] at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:134)
      12:39:36,080 INFO [STDOUT] at edu.coned.uah.web.CalculatorServlet.init(CalculatorServlet.java:55)
      12:39:36,080 INFO [STDOUT] at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1091)
      12:39:36,080 INFO [STDOUT] at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:750)
      12:39:36,080 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:130)
      12:39:36,080 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
      12:39:36,080 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve.invoke(CustomPrincipalValve.java:39)
      12:39:36,080 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:153)
      12:39:36,080 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:59)
      12:39:36,080 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
      12:39:36,080 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
      12:39:36,080 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
      12:39:36,080 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
      12:39:36,095 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:856)
      12:39:36,095 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.processConnection(Http11Protocol.java:744)
      12:39:36,095 INFO [STDOUT] at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
      12:39:36,095 INFO [STDOUT] at org.apache.tomcat.util.net.MasterSlaveWorkerThread.run(MasterSlaveWorkerThread.java:112)
      12:39:36,095 INFO [STDOUT] at java.lang.Thread.run(Thread.java:534)


      When I'm going through the JMX MBean JNDI View and Listing it, it shows:


      Ejb Module: CalculatorEJB.jar
      java:comp namespace of the Calculator bean:
      +- env (class: org.jnp.interfaces.NamingContext)

      java: Namespace
      +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
      +- DefaultDS (class: javax.sql.DataSource)
      +- SecurityProxyFactory (class: org.jboss.security.SubjectSecurityProxyFactory)
      +- DefaultJMSProvider (class: org.jboss.jms.jndi.JNDIProviderAdapter)
      +- comp (class: javax.naming.Context)
      +- JmsXA (class: org.jboss.resource.adapter.jms.JmsConnectionFactoryImpl)
      +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
      +- jaas (class: javax.naming.Context)
      | +- JmsXARealm (class: org.jboss.security.plugins.SecurityDomainContext)
      | +- jbossmq (class: org.jboss.security.plugins.SecurityDomainContext)
      | +- HsqlDbRealm (class: org.jboss.security.plugins.SecurityDomainContext)
      +- timedCacheFactory (class: javax.naming.Context)
      Failed to lookup: timedCacheFactory, errmsg=null
      +- TransactionPropagationContextExporter (class: org.jboss.tm.TransactionPropagationContextFactory)
      +- StdJMSPool (class: org.jboss.jms.asf.StdServerSessionPoolFactory)
      +- Mail (class: javax.mail.Session)
      +- TransactionPropagationContextImporter (class: org.jboss.tm.TransactionPropagationContextImporter)
      +- TransactionManager (class: org.jboss.tm.TxManager)

      Global JNDI Namespace
      +- XAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
      +- UIL2ConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)
      +- UserTransactionSessionFactory (proxy: $Proxy11 implements interface org.jboss.tm.usertx.interfaces.UserTransactionSessionFactory)
      +- HTTPConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
      +- console (class: org.jnp.interfaces.NamingContext)
      | +- PluginManager (proxy: $Proxy37 implements interface org.jboss.console.manager.PluginManagerMBean)
      +- UIL2XAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
      +- UUIDKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.uuid.UUIDKeyGeneratorFactory)
      +- HTTPXAConnectionFactory (class: org.jboss.mq.SpyXAConnectionFactory)
      +- topic (class: org.jnp.interfaces.NamingContext)
      | +- testDurableTopic (class: org.jboss.mq.SpyTopic)
      | +- testTopic (class: org.jboss.mq.SpyTopic)
      | +- securedTopic (class: org.jboss.mq.SpyTopic)
      +- queue (class: org.jnp.interfaces.NamingContext)
      | +- A (class: org.jboss.mq.SpyQueue)
      | +- testQueue (class: org.jboss.mq.SpyQueue)
      | +- ex (class: org.jboss.mq.SpyQueue)
      | +- DLQ (class: org.jboss.mq.SpyQueue)
      | +- D (class: org.jboss.mq.SpyQueue)
      | +- C (class: org.jboss.mq.SpyQueue)
      | +- B (class: org.jboss.mq.SpyQueue)
      +- ConnectionFactory (class: org.jboss.mq.SpyConnectionFactory)
      +- UserTransaction (class: org.jboss.tm.usertx.client.ClientUserTransaction)
      +- ejb (class: org.jnp.interfaces.NamingContext)
      | +- Calculator (proxy: $Proxy50 implements interface edu.coned.uah.interfaces.CalculatorHome,interface javax.ejb.Handle)

      +- jmx (class: org.jnp.interfaces.NamingContext)
      | +- invoker (class: org.jnp.interfaces.NamingContext)
      | | +- RMIAdaptor (proxy: $Proxy36 implements interface org.jboss.jmx.adaptor.rmi.RMIAdaptor,interface org.jboss.jmx.adaptor.rmi.RMIAdaptorExt)
      | +- rmi (class: org.jnp.interfaces.NamingContext)
      | | +- RMIAdaptor[link -> jmx/invoker/RMIAdaptor] (class: javax.naming.LinkRef)
      +- HiLoKeyGeneratorFactory (class: org.jboss.ejb.plugins.keygenerator.hilo.HiLoKeyGeneratorFactory)
      +- UILXAConnectionFactory[link -> XAConnectionFactory] (class: javax.naming.LinkRef)
      +- UILConnectionFactory[link -> ConnectionFactory] (class: javax.naming.LinkRef)