cancel
Showing results for 
Search instead for 
Did you mean: 

Canu00B4t call an EJB from other EJB

Former Member
0 Kudos

Hi developers,

I need do the next task :

I have a EJB in an EAR and i need call some functionality from other EJB in diferent EAR , when execute the code show the next message error:

java.rmi.RemoteException: com.sap.engine.services.ejb.exceptions.BaseRemoteException: Exception in method generaMDMOutput.

at com.sapconsulting.customer.inc.CustomerIncObjectImpl0.generaMDMOutput(CustomerIncObjectImpl0.java:135)

at com.sapconsulting.customer.inc.CustomerIncObjectImpl0p4_Skel.dispatch(CustomerIncObjectImpl0p4_Skel.java:127)

at com.sap.engine.services.rmi_p4.DispatchImpl._runInternal(DispatchImpl.java(Compiled Code))

at com.sap.engine.services.rmi_p4.DispatchImpl._run(DispatchImpl.java(Inlined Compiled Code))

at com.sap.engine.services.rmi_p4.server.P4SessionProcessor.request(P4SessionProcessor.java(Compiled Code))

at com.sap.engine.core.service630.context.cluster.session.ApplicationSessionMessageListener.process(ApplicationSessionMessageListener.java(Compiled Code))

at com.sap.engine.core.cluster.impl6.session.MessageRunner.run(MessageRunner.java(Compiled Code))

at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java(Compiled Code))

at java.security.AccessController.doPrivileged1(Native Method)

at java.security.AccessController.doPrivileged(AccessController.java(Compiled Code))

at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java(Compiled Code))

at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java(Compiled Code))

Caused by: java.lang.ClassCastException: com.sap.engine.interfaces.cross.ObjectReferenceImpl

at com.sapconsulting.customer.inc.CustomerIncBean.generaMDMOutput(CustomerIncBean.java:141)

at com.sapconsulting.customer.inc.CustomerIncObjectImpl0.generaMDMOutput(CustomerIncObjectImpl0.java:119)

... 11 more

the code to invoke the EJB is the next:

ctx = new InitialContext();

TestEJBLocalHome home = (TestEJBLocalHome) ctx.lookup("sap.com/TestEJB_ear/TestEJBBean");

TestEJB servicio=(TestEJB)home.create();

the EJB are in the same server , please help,

regards

Accepted Solutions (1)

Accepted Solutions (1)

agasthuri_doss
Active Contributor
0 Kudos

Hi,

It is Possible to call EJB from other EJB.

Regards

Agasthuri Doss

Answers (3)

Answers (3)

Former Member
0 Kudos

Hi Siarhei,

thank's for your answers , i'll explain the scenario , i think i copied wrong the code that i have ,

i have two EAR's applications , i want to call one EJB from the other EJB in other EAR , the call have to be remote , my code is the next :

ctx = new InitialContext();

Object obj = ctx.lookup("sap.com/TestEJB_ear/TestEJBBean");

TestEJBHome home = (TestEJBHome) PortableRemoteObject.narrow(obj,TestEJBHome.class);

TestEJB servicio= home.create();

i've confugured the ejb-xml.jar adding

<ejb-ref>

<ejb-ref-name>ejb/TestEJBBean</ejb-ref-name>

<ejb-ref-type>Session</ejb-ref-type>

<home>com.innovativesystems.onl.TestEJBHome</home>

<remote>com.innovativesystems.onl.TestEJB</remote>

</ejb-ref>

I've configured the ejb-j2ee-jar.xml adding

<ejb-ref>

<ejb-ref-name>ejb/TestEJBBean</ejb-ref-name>

<jndi-name>sap.com/TestEJB_ear/TestEJBBean</jndi-name>

</ejb-ref>

I've configured the application-j2ee-engine.xml adding a hard reference

<reference

reference-type="hard">

<reference-target

provider-name="sap.com"

target-type="application">TestEJB_ear</reference-target>

</reference>

with all this configuration still send me the message java.lang.classcast ,

something is missing???? ,

regards

siarhei_pisarenka3
Active Contributor
0 Kudos

I guess that for remote EJB such classes as TestEJBHome and TestEJB should be available in the first application which makes the call too. The EAR with remote EJB must have two public parts 'client' & 'ejbjar'. So my idea is to add Jar for 'client' from EAR2 into EAR1.

If so EAR1 does not need to have a reference to EAR2 at all. Method TestEJBHome home = (TestEJBHome) PortableRemoteObject.narrow(obj,TestEJBHome.class);

will convert 'obj' to TestEJBHome from EAR1.

BR

Sergei

siarhei_pisarenka3
Active Contributor
0 Kudos

In addition name in lookup "sap.com/TestEJB_ear/TestEJBBean"... Is it correct JNDI name? As I know for not remote EJB the name should be like this "localejbs/sap.com/TestEJB_ear/TestEJBBean".

BR

Sergei

Former Member
0 Kudos

But what is happening??? why send a class cast error????,

regards

siarhei_pisarenka3
Active Contributor
0 Kudos

Hi Francisco

What is the method 'generaMDMOutput'. Is it business method of the EJB you are trying to call? If so check the implementation of the method. It contains the error. There is nothing wrong with a calling EJB as a process.

BR

Sergei