on 06-05-2008 11:27 AM
I am having 2 session beans in 2 different dcs. I want to to look up session bean in one DC into another DC to access its methods.
i hv written following code
@Stateless(mappedName="PositionHandler")
public class PositionHandlerBean implements PositionHandlerLocal {............................................
.............................................
............................................
public testMethod()
{
try {
Context ctx = new InitialContext();
KeyGeneratorLocal keyGeneratorLocal = (KeyGeneratorLocal)ctx.lookup("KeyGenerator");
newPrimaryKey = keyGeneratorLocal.generateKeyFor(entityBeanName);
}catch(NamingException ex){
ex.printStackTrace();
System.err.println("\n\nInside catch");
return null;
}
}
}
@Stateless(mappedName="KeyGenerator")
@Local(KeyGeneratorLocal.class)
public class KeyGeneratorBean implements KeyGeneratorLocal {
........................................
......................................
......................................
public String generateKeyFor(String entityBeanName)(String s){
// Do Something
}
and ejb-j2ee-engine.jar in side KeyGenerator DC as follows
<?xml version="1.0" encoding="UTF-8"?>
<ejb-j2ee-engine xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="ejb-j2ee-engine_3_0.xsd">
<enterprise-beans>
<enterprise-bean>
<ejb-name>com.apl.session.keygenerator.KeyGeneratorBean</ejb-name>
<server-component-ref>
<name>KeyGenerator</name>
<jndi-name>KeyGenerator</jndi-name>
</server-component-ref>
</enterprise-bean>
</enterprise-beans>
</ejb-j2ee-engine>
Still i m not able to lookup session bean KeyGenerator .
You can put the two beans in one DC and then use @EJB and the EJB Container's DI will automaticlly do the trick for you.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I cnt keep 2 session beans in different DCs as i hv to use same session bean in other DCs.So for reusability purpose i have to keep both session beans in different Dcs i m new to dependency injection. I have deleted code in j2ee-engine.xml file and written code in session bean as follows
@Stateless(mappedName="PositionHandler")
@EJB(name="ejb/KeyGeneratorLocal" , beanInterface = KeyGeneratorLocal.class)
public class PositionHandlerBean implements PositionHandlerLocal {............................................
.............................................
............................................
public testMethod()
{
try {
Context ctx = new InitialContext();
KeyGeneratorLocal keyGeneratorLocal = (KeyGeneratorLocal)context.lookup("java:comp/env/ejb/KeyGeneratorLocal");
}catch(NamingException ex){
ex.printStackTrace();
System.err.println("\n\nInside catch");
return null;
}
}
}
Still not able to look up. Could u please tell me where i went wrong???
Edited by: kavita chavan on Jun 6, 2008 8:43 AM
Edited by: kavita chavan on Jun 6, 2008 9:02 AM
What's the stack trace of the NamingException that you get?
This way you've done it should work. Or even simpler:
@Stateless
public class PositionHandlerBean implements PositionHandlerLocal {
@EJB
KeyGeneratorLocal keyGeneratorLocal;
.............................................
............................................
public testMethod() {
keyGeneratorLocal.doSomething();
}
}
HTH!
\-- Vladimir
Yup, it reads: The EJB lookup schemes are a new format of the lookup strings for non-standard Java EE components.
For Java EE components the recommended way to go is the standard @EJB references and then either injection or component-local lookup (i.e. EJBContext.lookup() or "java:comp/env/")
\-- Vladimir
I also want to know how to look up session bean in Java class ??
I want to create java model in Web dYnpro . I am having Session Bean with local and remote interfaces. I have added one Java class in same DC , and now want to lookup session bean in this java class.
I know in EJB 2.0 we used to look up using remote interfaces , but no idea in EJB 3.0. Can i use annotations like i used in session bean to session bean look up ??? But i m not able to access local or remote interface object of session bean in Java class. I able to get object of SessionBean class in Java class.
You don't need a separate Java model, you can use the EJB as a model directly. Check it out:
[Importing Enterprise JavaBean (EJB) Models|http://help.sap.com/saphelp_nwce10/helpdata/en/45/dd45e4bc295595e10000000a1553f7/frameset.htm]
[Integrating EJB 3.0 into Web Dynpro Using the EJB Model Importer|http://help.sap.com/saphelp_nwce10/helpdata/en/45/f7f744aea471fae10000000a1553f6/frameset.htm]
HTH!
\-- Vladimir
HI Kavita,
in lookup dont use "KeyGenerator"..instead use "localejbs/JNDIname of your session bean"
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
10 | |
9 | |
7 | |
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.