on 11-11-2005 1:07 PM
Hallo,
I have basic EJB question.
I have programmed JSP application with EJB that is using BAPI's and it is running on SAP J2EE server.
But now I would like to create simple console Java application that uses EJB from J2EE server and will located on remote computer with Java SDK.
I have no idea how to use remote EJB on simple Java application. I was looking on Google but only found source for connecting EJB with JSP application (what is in my case useless).
Does any body have any example source how can I do this?
Thank you in advance.
Regards,
Mihail
Hello Mihail,
this code is working fine remotely for me:
import javax.naming.InitialContext;
import java.util.Properties;
import com.sap.engine.examples.ejb.hello.Hello;
import com.sap.engine.examples.ejb.hello.HelloHome;
....
Properties _param = new Properties();
_param.put(Context.INITIAL_CONTEXT_FACTORY, "com.sap.engine.services.jndi.InitialContextFactoryImpl");
_param.put(Context.PROVIDER_URL, "BFDB8D29491:50004");
_param.put(Context.SECURITY_PRINCIPAL, "Administrator");
_param.put(Context.SECURITY_CREDENTIALS, "password");
Context initialContext = new InitialContext(_param);
Object obj = initialContext.lookup("sap.com/Hello/Stateless/HelloStatelessBean");
HelloHome hh = (HelloHome)obj;
Hello h = hh.create();
System.out.println(h.getMessage());
h.remove();
Best regards, Maksim Rashchynski.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Mihail,
accessing an EJB from a standalon remote Java application differs mainly in the lookup string that you use to lookup the bean's interface (i.e. you can't look it up relative to the java:comp/env context). Also, to access the bean from remote virtual machine, you must ensure the beans uses remote interfaces (as opposed to the local ones when you access it from the same VM).
A general description of the ways you can access a bean are described in <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/java/accessing%20ejb%20applications%20using%20jndi.pdf">this</a> article on SDN. You're particularly interested in the <b>Example 3: Accessing Enterprise Beans by Non-J2EE Components</b> section.
Also, keep in mind that you'll need the client classes of the bean's interfaces (the client.jar) on the client side. <a href="http://help.sap.com/saphelp_nw04/helpdata/en/5f/2dd984b5d1304b9155f161568f2f64/frameset.htm">This</a> page in the docs explains how you get that.
Hope that helps!
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 | |
9 | |
6 | |
6 | |
6 | |
5 | |
4 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.