Skip to Content
avatar image
Former Member

Connecting to EJB

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Nov 11, 2005 at 03:23 PM

    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.

    Add comment
    10|10000 characters needed characters exceeded

    • Former Member

      Ivaylo and Maksim!

      Thank you very much for your help.

      My Problem is now solved!

      Best regards Mihail

  • avatar image
    Former Member
    Nov 11, 2005 at 03:07 PM

    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 thiswww.sdn.sap.com/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/library/webas/java/accessing%20ejb%20applications%20using%20jndi.pdf">this> article on SDN. You're particularly interested in the Example 3: Accessing Enterprise Beans by Non-J2EE Components section.

    Also, keep in mind that you'll need the client classes of the bean's interfaces (the client.jar) on the client side. Thishttp://help.sap.com/saphelp_nw04/helpdata/en/5f/2dd984b5d1304b9155f161568f2f64/frameset.htm">This> page in the docs explains how you get that.

    Hope that helps!

    Add comment
    10|10000 characters needed characters exceeded