Why PortableRemoteObject.narrow causes ClassCastException ?

Solution Verified - Updated -

Issue

  • While doing migration from Websphere to JBoss EAP 6.3 we get ClassCastException. Below is the code snippet regarding EJB (stateless bean) class to invoking initialize() Which is purely from WAS environment. So I have migrate to JBOSS compatible.
    import javax.naming.InitialContext;
        import javax.rmi.PortableRemoteObject;
    //Sample code for TestCaller.java
    BusinessServerHome BusinessServerHome =   (BusinessServerHome)PortableRemoteObject.narrow(getJNDIContext().lookup(BusinessServerHomeName), BusinessServerHome.class);  
    BusinessServer BusinessServer = BusinessServerHome.create();
    BusinessServer.initialize();
  • In brief explanation below are the description of the interfaces and classes used in the above code snippet. Please let me know if you need more information from me.
    BusinessServerHomeName -> This is the JNDI EJB JNDI name string
    BusinessServerHome -> This is the home interface
    initialize() -> This is the bean class method, here we have some business logic.

  • The following exception is received while execution of the above code:

    java.lang.ClassCastException
    at org.jboss.com.sun.corba.se.impl.javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:246)
    at javax.rmi.PortableRemoteObject.narrow(PortableRemoteObject.java:158)
    at com.example.TestCaller.getSessionManager(TestCaller.java:290)

Environment

  • Red Hat JBoss Enterprise Application Platform (EAP)
    • 6.x

Subscriber exclusive content

A Red Hat subscription provides unlimited access to our knowledgebase, tools, and much more.

Current Customers and Partners

Log in for full access

Log In

New to Red Hat?

Learn more about Red Hat subscriptions

Using a Red Hat product through a public cloud?

How to access this content