Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to write EJB 3.1 client for WebSphere 8.5?

I'm facing problem while doing lookup for EJB 3.1 deployed on WebSphere 8.5.

Please suggest me :

  1. What are all libraries i need to include in classpath?
  2. How to construct lookup string?
  3. Is there any settings needs to be changed at Server side?

Note : I'm using Eclipse IDE

like image 372
Mandar Naik Avatar asked Jul 22 '14 07:07

Mandar Naik


1 Answers

Try This :

  1. Add com.ibm.ws.ejb.thinclient_8.5.0.jar and com.ibm.ws.orb_8.5.0.jar jars to classpath of client application.
  2. Generate client stub by running createEJBStubs.sh script.
    createEJBStubs.sh script found under <WAS_HOME>/bin directory.
    Syntax : ./createEJBStubs.sh <ejbJarName>.jar
  3. Add generated jar to the client application's classpath.
  4. Provide custom JNDI name to your EJB as follows :
    Open WebSphere console, on the left side panel click on Applications>All applications.
    Click on your deployed application.
    Click on Bind EJB Business under Enterprise Java Bean Properties.
    Set custom JNDI name for your EJB under JNDI name column. e.g. customLookupString

Sample Client Code :

public class WebSphereClient {
    public static void main(String[] args) {
        Properties props = new Properties();
        props.put(Context.INITIAL_CONTEXT_FACTORY,
                "com.ibm.websphere.naming.WsnInitialContextFactory");
        props.put(javax.naming.Context.PROVIDER_URL, "iiop://localhost:2818");
        TestBeanRemote bean = null;
        Object obj;
        try {
            InitialContext ctx = new InitialContext(props);
            obj= ctx.lookup("customLookupString");
            if (obj instanceof TestBeanRemote) {
                bean = (TestBeanRemote) obj;
            }
            System.out.println("Name : "+bean.getName());
        } catch (NamingException e) {
            e.printStackTrace();
        }
    }
}

Above code and process worked for me.

like image 104
Mandar Naik Avatar answered Sep 21 '22 22:09

Mandar Naik