on 06-06-2007 3:59 PM
hey all,
I m new to java programming. My client requires me to call EJB beans from a application or from a EJB bean and want me to deploy onto a server. How do I do that? Is it that I can achieve this with RMI?? Or else can someone tell me how? And can someone send me the code? It will be really helpful to me if you send me the code in this short time I have.
Help me out..
Regards
Pavan..
Hi There
A Complete Example of Creating and Calling the EJBs is
within the Help System of the NWDS Itself.Check That.
Also Check this url on your server for More Examples,
Click on J2ee Exapmles..
These are Running Examples with Source Code !
Regards
Rajendra
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
hi
good
Q->Call an ejb bean from another ejb bean
To refer a Ejb from another Ejb include <ejb-ref> element in ejb-jar.xml
<session>
<ejb-name>EjbA</ejb-name>
<ejb-ref>
<ejb-ref-name>EjbB</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.ejb.EjbBHome</home>
<remote>com.ejb.EjbB</remote>
</ejb-ref>
</session>
Include a <reference-descriptor> in weblogic-ejb-jar.xml
<weblogic-enterprise-bean>
<ejb-name>EjbA</ejb-name>
<reference-descriptor>
<ejb-reference-description>
<ejb-ref-name>EjbB</ejb-ref-name>
<jndi-name>com.ejb.EjbBHome</jndi-name>
</ejb-reference-description>
</reference-descriptor>
</weblogic-enterprise-bean>
In EjbA Bean class refer to EjbB with
a remote reference to EjbB.
InitialContext initialContext=new InitialContext();
EjbBHome EjbBHome=(EjbBHome)
initialContext.lookup("com.ejb.EjbBHome");
EjbB ejbB=EjbBHome.findByPrimaryKey(primarykey);
2->Achieve it with RMI
Remember that your beans are running inside the container and that you can access them using the Home and Remote interfaces. This is in fact using RMI (Remote Method Invocation)... communication between the web-container and the EJB-container for example.
This means that when accessing an EJB from a POJO, use the Home interface to retrieve an instance of that EJB.
If you are communicating between two EJB's however (running in the same EJB container), you should use the LocalHome object to retrieve an instandce of that EJB. At that moment no RMI is used but just plain old class loading. This will result in quite an increase of speed.
thanks
mrutyun^
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi PavanKrishna,
You need to first deploy this EJB to the server use NWDS for it.
After successful deployment, u need to use the JNDI name to look up the EJB and call it
Properties prop = new Properties();
try {
prop.setProperty(Context.INITIAL_CONTEXT_FACTORY,"com.sap.engine.services.jndi.InitialContextFactoryImpl");
prop.put(Context.PROVIDER_URL,"suncss1.sicemadrid.com:50104");
context = new InitialContext(prop);
object = context.lookup("sap.com/SocketProxy/MICGOSendCancellationOB_PortTypeBean");// JNDI Name
mICGOSendCancellationOB_PortTypeHome = (MICGOSendCancellationOB_PortTypeHome)javax.rmi.PortableRemoteObject.narrow(object,MICGOSendCancellationOB_PortTypeHome.class);
mICGOSendCancellationOB_PortType = mICGOSendCancellationOB_PortTypeHome.create();
/// on this object call the method.
} catch (ClassCastException e) {
e.printStackTrace();
return null;
} catch (RemoteException e) {
e.printStackTrace();
return null;
} catch (NamingException e) {
e.printStackTrace();
return null;
} catch (CreateException e) {
e.printStackTrace();
return null;
}
Also see some tutorials here.
<a href="http://www.roseindia.net/software-tutorials/detail/6467">url</a>
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
93 | |
10 | |
10 | |
9 | |
9 | |
7 | |
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.