on 01-29-2014 4:05 PM
Hello,
i am trying to look up a EJB in my REST Service. Both deployed on the same server. The problem is that i am getting a Object of Type Proxy from the lookup method and can't cast it to the needed Bean Class. Any ideas?
Here the code:
//This returns the Proxy Object?!
Object obj = new
InitialContext().lookup("ejb:/mycompany.de/reboard~report~cs/REMOTE/com.sap.bpem.facade.api._simplified.adapted.BPMFacadeBeanSimplifiedEjb/com.sap.bpem.facade.api._simplified.adapted.BPMFacadeBeanSimplifiedRemote");
//Class cast excpetion here!
BPMFacadeBeanSimplifiedRemote myBean = (BPMFacadeBeanSimplifiedRemote) PortableRemoteObject.narrow(obj, BPMFacadeBeanSimplifiedRemote.class);
Thanks for help!
Hello Dimitri,
probably your EJB and your REST Service are deployed on the same SAP NetWeaver Java, but in different EAR files.
Due to somewhat strance classloading and "narrow()" implementation in SAP NetWeaver Java, you have to define a dependency from one EAR file to the other in the META-INF/application-j2ee-engine.xml of one of the two EAR files.
The content should look like this in the referencing enterprise application
<?xml version="1.0" encoding="UTF-8"?>
<application-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="application-j2ee-engine.xsd">
<reference reference-type="hard">
<reference-target provider-name="sap.com" target-type="application">the-referenced-enterprise-application</reference-target>
</reference>
</application-j2ee-engine>
(replace "the-referenced-enterprise-application" and probably "sap.com").
(If you are using EAR DCs, this is done automatically if you define a Runtime Dependeny in Component Properties)
The result is that the referencing enterprise applicationis sharing class loader with the referenced enterprise application.
Without this deployment descriptor, both enterprise applicatoin have class BPMFacadeBeanSimplifiedRemote in different, isolated class loaders, and narrow is implemented as a noop
In real remote clients outside the JVM of NetWeaver Java, this is cured by PortableRemoteObject.narrow() which instantiates a real proxy object. Inside SAP NW Java, narrow() does never return a Remote proxy, even if you look up the remote object.
Regards
Rolf
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
84 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
4 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.