cancel
Showing results for 
Search instead for 
Did you mean: 

Connecting to EJB

Former Member
0 Kudos

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

Accepted Solutions (1)

Accepted Solutions (1)

former_member182372
Active Contributor
0 Kudos

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.

Former Member
0 Kudos

Ivaylo and Maksim!

Thank you very much for your help.

My Problem is now solved!

Best regards Mihail

Answers (1)

Answers (1)

Former Member
0 Kudos

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!