Question

We have a business functionality which is exposed as a Remote EJB. We shared the remote interface with the client. Below is the Remote interface that we shared.

public interface EmployeeRemoteEJB {
    public Output saveEmployee(Input input);
}

public Output extends BaseObj{
    private static final long serialVersionUID = -7096731222829800554L;
    //some fields are there
}

public Input extends BaseObj{
    private static final long serialVersionUID = -70967312228423800554L;
    //some fields
}

public BaseObj implements Serializable{

}

Now Input class and Output class has some fields, which also extends from BaseObj and has a generated SerialVersion UID.

Now we have deployed this EJB on WebSphere Application Server 7.0. The Remote invocation of EJB works fine. It breaks when we do a deployment of the Client web app which calls the EJB or the web application which has the EJB. We get the ClassCastException that the

com.test.ejb._EmployeeRemoteEJB_Stub incompatible with com.test.ejb.EmployeeRemoteEJB

When we restart the applications, it starts working again.

This is how we invoke the Remote EJB

//This JNDI name is configured for the remote EJB. String REMOTE_LOOKUP_KEY = "empremotesvc"; String JNDI_PROVIDER_URL = "iiop://10.222.232.111:2809";

        Properties props = new Properties();
        props.put( Context.INITIAL_CONTEXT_FACTORY,"com.ibm.websphere.naming.WsnInitialContextFactory");
        props.put( Context.PROVIDER_URL, JNDI_PROVIDER_URL );
        Object lobj;
        InitialContext ctx;
        try{
            ctx = new InitialContext( props );

            lobj = ctx.lookup( REMOTE_LOOKUP_KEY );
            EmployeeRemoteEJB empObjRemote = (EmployeeRemoteEJB) lobj;
            return empObjRemote ;
        }
        catch( NamingException e ){
            e.printStackTrace();
        }

Can someone please let me know what is causing this issue? Please let me know if you need any further details.

Était-ce utile?

La solution

You need to call PortableRemoteObject.narrow:

lobj = ctx.lookup( REMOTE_LOOKUP_KEY );
EmployeeRemoteEJB empObjRemote = (EmployeeRemoteEJB)
    PortableRemoteObject.narrow(lobj, EmployeeRemoteEJB.class);

The problem does not always occur because JNDI caches resolved IOR-to-stub using the class loader of first client app to look up the EJB, so the first application to use the target EJB will work, but the second and subsequent will not unless they use PortableRemoteObject.narrow.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top