on 05-06-2009 10:08 AM
Hi everybody,
i have two J2EE Enterprise Appliacation DCs each containing one EJB 2.1 EJB DC Module with both containing
Session Beans on WEB AS Java 7.0.
My challenge is that I would like to let one Session Bean from Application one lookup another Session Bean from Application
two using its local home interface as follows:
public class AppOneSessionBean implements SessionBean {
public void ejbCreate() throws CreateException {
Context context = new InitialContext();
//option a) normal localejbs lookup
Object ref = context.lookup("localejbs/my/jndi/name/of/AppTwoSessionBean");
//option b) ejb-local-ref with corresponsing ejb-jar.xml and ejb-j2ee-engine.xml configs
Object ref = context.lookup("java:comp/env/ejb/AppTwoSessionBean");
// up to here no problems. The ref.getClass().getName() gives the correct fully
// qualified class name of the desired local home interface implementation object of AppTwoSessionBean
// with both options a) and b)
// the problem is a ClassCastException caused by the next statement:
AppTwoSessionLocalHome appTwoSessionHome = (AppTwoSessionLocalHome)ref;
}
}
I read and followed example 2 of
and added a hard reference to my.provider.com/apptwoear.ear inside application my.provider.com/apponeear.ear's
application-j2ee-engine.xml, but without (positive) effect:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE application-j2ee-engine SYSTEM "application-j2ee-engine.dtd">
<application-j2ee-engine>
<reference
reference-type="hard">
<reference-target
provider-name="my.provider.com"
target-type="application">apptwo/ear</reference-target>
</reference>
<provider-name>my.provider.com</provider-name>
<fail-over-enable
mode="disable"></fail-over-enable>
</application-j2ee-engine>
Since I do not know how to get rid of the ClassCastException, which looks to me as a class loading
issue between two EJB/ear applications, I have started using the EJB lookup scheme described here:
http://help.sap.com/saphelp_nwce10/helpdata/en/45/e692b2cfaa5591e10000000a1553f7/frameset.htm
I tried several variations such as:
- String jndiName = "ejb:/interfaceName=my.package.name.of.AppTwoSessionLocalHome,interfaceType=local-home";
- String jndiName = "ejb:/appName=my.provider.com/apptwo~ear.ear,jarName=my.provider.com~apptwo~ejb.jar,
beanName=AppTwoSessionBean,interfaceName=my.package.name.of.AppTwoSessionLocalHome,
interfaceType=local-home";
- String jndiName = "ejb:/my.provider.com/apptwo~ear.ear/LOCAL/
AppTwoSessionBean/my.package.name.of.AppTwoSessionLocalHome";
Object ref = context.lookup(jndiName);
The result here is always a NameNotFoundException saying Path to object does not exist at ejb:, the whole lookup name is .
Can I do something either to fix the ClassCastException or the NameNotFoundException, or is .ear to .ear SessionBean
lookup only possbile inside an .sca archive, which is AFAIK not possible to create with SAP Dev Studio 7.0 SP18?
My prefered solution would be to use
AppTwoSessionLocalHome home = (AppTwoSessionLocalHome)context.lookup("java:comp/env/ejb/AppTwoSessionBean")
for the lookup.
Kind regrads,
Andreas
Hi bvr,
the question is, if there is a way to perform a local EJB 2.1 SessionBean lookup from a
normal Java class deployed inside an .sda archive. Trying this, I get a ClassCastException,
although i can see, that the actual looked up object's fully qualified class name is exactly the
same like the SessionBean's local home interface's implementation class.
Normally, under this circumstance, a casting operation to the desired object never fails.
But in this case it does with a ClassCastException.
Kind regards
Andreas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi,
in addition to above context you refer this link
a sample code for how to call from one session bean to another session bean with(local home)
http://www.java2s.com/Code/Java/EJB3/OneStatelessSessionBeanCallAnotherStatelessBean.htm
with remote session
http://www.codeproject.com/KB/java/EJB_remote_session.aspx
let me know am i correct or not
bvr
Edited by: bvr on May 8, 2009 1:13 PM
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Ekaterina,
Yes you are right, i was reading it to fast ;-). However, I started another try. Two new test ear apps each with one SessionBean, where SessionBean of ear1 is looking up the other SessionBean of ear2). I got it running. No more ClassCastException!
What I did not mention was, that I actually would like to let a normal class, being deployed in an sda archive and called from a SessionBean of ear1, lookup a SessionBean of ear2 via local home interface.
The local home "border" seems to be at ear <--> sda deployment unit level, concerning JNDI lookup, and not how I was hoping at machine/server level.
It seems, that an sda achive is loaded with a different class loader than a ear archive. As mentioned in my first thread post, the ClassCastException does not occur because of wrong class(es) (names), but because of the different class loaders of the to archives loading the local home interface implementation class.
When I let a class, deployed in an sda archive and called from SessionBean of ear1, lookup SessionBean of ear2, the ClassCastException rises again. If SessionBean of ear1 looks up SessionBean of ear2 directly the local lookup is successful with the localejbs prefix as well with local ejb reference using java:comp/env/.
I do not know what happens, if the two ear are deployed in a clustered Web AS Java environment, since my test machine has only one instance and one server process. Maybe the ClassCastException comes again, when ear1-SessionBean looks up ear2-SessionBean, when clustering/load balancing delegates
the local lookup calls to different server nodes/processes.
Since I did not manage to add a hard reference in the sda's provider.xml via Used DCs, like it is easily manually possible between two ear's applications-j2ee-engine.xml, I fear I have to use a remote lookup from a simple sda deployed java class to get a ear2-SessionBean instance. Although everything is deployed on the very same machine and although the initial call to the normal Java class comes from ear1- SessionBean, which has a working hard reference to ear2-SessionBean
Kind regards
Andreas
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Andreas,
The first thing that comes to mi mind is that you are trying to look up two beans residing on different application using the local home interface. In the document that you linked is written explicitly that to do that you need a remote interface and a remote home interface. The configuration is described in the same document. Try this one, while I figure out what may have caused the problem.
Best regards,
Ekaterina
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
86 | |
10 | |
10 | |
10 | |
7 | |
6 | |
6 | |
5 | |
5 | |
4 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.