cancel
Showing results for 
Search instead for 
Did you mean: 

EJB call from other EJB

Former Member
0 Kudos

Hi,

I have some trouble calling one ejb from another ejb.

Our goal is to deploy two (or more) different EARs on different Netweaver server instances.

Those EARs shall communicate via RMI-call on the ejb-fassade. To test this, I wrote a simple interface:


public interface ITestService {
	String sayHelloWorld();
}

and the implementation of this interface as EJB:


@Stateless
@Remote
public class TestServiceEJB implements ITestService {
	public String sayHelloWorld() {
		return "Hello World!";
	}
}

After deploying the ear which contains this EJB I can make a call to the EJB from a simple java class:

public static void main(String[] args) throws Exception {
	Properties p = new Properties();
	p.put(Context.INITIAL_CONTEXT_FACTORY,
		"com.sap.engine.services.jndi.InitialContextFactoryImpl");
	p.put(Context.URL_PKG_PREFIXES, "com.sap.engine.services");
	p.put(Context.PROVIDER_URL, "localhost:50004");

	InitialContext ctx = new InitialContext(p);
	Object o =
		ctx.lookup("ejb:/appName=xyz.com/test-ear, "
				+ "beanName=TestServiceEJB, "
				+ "interfaceName=com.xyz.test.server.service.ITestService");

        ITestService e = (ITestService) o;

	System.out.println(e.sayHelloWorld());
}

No problems here, "Hello World!" is printed to console, everything works fine.

But if I make this call from within another ejb which will be deployed in another ear an exception occurs at the following line:

ITestService e = (ITestService) o;

The exception message is:

java.lang.ClassCastException: class $Proxy140:xyz.com/test-ear_AT_com.sap.engine.boot.loader.ResourceMultiParentClassLoader_AT_1f0dba8_AT_alive incompatible with interface com.xyz.test.server.service.ITestService:xyz.com/testcaller-server-ear_AT_com.sap.engine.boot.loader.ResourceMultiParentClassLoader_AT_15f120_AT_alive

So as the exception tells me, the problem is at casting o to ITestService.

The versions of the interface in both EARs are the same, so the problem seesms to be somewhere else, maybe in the ClassLoader?!?

BTW: It also makes no difference if the call comes from a local ear (which is on the same application server) or from a remote ear (deployed on another server).

Searching in the expert forum brought me to this link:

But unfortunatelly there is also no solution for the problem.

I hope somebody can show me, how to make a call from one ejb to an other...

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

I'm having exactly the same problem. Can nobody help us, or should we make a SAP call.

Greets,

Fabian

Former Member
0 Kudos

Note: In the exception message I had to remove some @ chars with "_AT_"...