cancel
Showing results for 
Search instead for 
Did you mean: 

ClassCastException on EJB call

Former Member
0 Kudos

Hi, I know there are a number of threads on this topic, but I have not been able to discern the answer to my query from these (this [one|; seems to come closest).

We are trying to integrate Axis2 web services with NetWeaver CE 7.1 SP8 using EJB invocation. This is working for us with other application servers, but we're seeing a class loading issue with NetWeaver.

The issue is with this code:

Object o = initialContext.lookup(((String) jndiName.getValue()).trim());  // JNDI name from Axis2 deployment descriptor
        final Class<?> cls = Class.forName((String) remoteHomeName.getValue());   // Remote home from Axis2 deployment descriptor
        final Object ehome = javax.rmi.PortableRemoteObject.narrow(o, cls);

Depending on how we try to set this up the narrow gives a ClassCastException or the Class.forName() gives a NoClassDefFoundError.

The llr -all telnet command shows us that the class is found in the web services war file and in the application ear file. These entries:

[http://help.sap.com/saphelp_nwce711/helpdata/en/4d/993441c73cef23e10000000a155106/content.htm]

[http://help.sap.com/saphelp_tm70/helpdata/de/be/2e2c4142aef623e10000000a155106/content.htm]

would suggest that the issue is that the class is being loaded from different class loaders, causing the exception, and that the basic solution is to either: 1) remove the class from the client; or 2) provide a reference to the class loader.

If we do number 1 we then see the java.lang.ClassNotFoundException from the Class.forName() call because it's trying to load it from the local application.

If we do number 2 using application-j2ee-engine.xml to create a [hard reference|http://www.sdn.sap.com/irj/scn/go/portal/prtroot/docs/library/uuid/60642a88-95fe-2b10-d387-a245d48fc257?quicklink=index&overridelayout=true] we then have issues elsewhere because the Axis2 web application needs different property settings from the linked to application and we get NoClassDefFoundErrors elsewhere, for instance when listing the services in Axis it apparently can't resolve the class hierarchy for the service in the wsdl even though the referenced class is in all deployed applications.

Is there any way around this? Especially to avoid using hard references as I don't think we'll be able to function that way.

Thanks,

William

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Hello, William.

Perharps Wiki publication can help you.

http://wiki.sdn.sap.com/wiki/display/XI/SapNetweaverProcessIntegration.CallEjb3.0methodfromJavaclassmappingPI7.1

Best Regards

Answers (1)

Answers (1)

Former Member
0 Kudos

Hello José,

Many thanks for your post as that seems to have solved my problem!

The statement in that wiki is very simple and summarized it well: "The idea is to get the ejb local interface class loaded by the Application EAR classloader, and invoke the business method through this class using the result of the JNDI lookup."

I find the documentation in this area to be somewhat fractured and I wouldn't have thought of looking in the NetWeaver PI area on my own.

All the best,

William