Mandar Naik
Mandar Naik

Reputation: 263

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

Upvotes: 6

Views: 8675

Answers (2)

Mandar Naik
Mandar Naik

Reputation: 263

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.

Upvotes: 6

Gas
Gas

Reputation: 18020

Check this page Running the IBM Thin Client for Enterprise JavaBeans (EJB) for more details.

What are all libraries i need to include in classpath?

You will need com.ibm.ws.ejb.thinclient_8.5.0.jar (located in app_server_root\runtimes) and the endorsed_apis_8.5.0.jar (located in app_server_root\runtimes\endorsed). Copy endoresed jar to JAVA_JRE\lib\endorsed

How to construct lookup string?

Invoke your application like this:

<java_install_root>\bin\java  
-classpath com.ibm.ws.ejb.thinclient_8.5.0.jar;<list_of_your_application_jars_and_classes> 
-Djava.naming.provider.url=iiop://<your_application_server_machine_name>:<orbPort>
<fully_qualified_class_name_to_run>

If you have security enabled on your server and SSL required, you will need add following:

-Dcom.ibm.SSL.ConfigURL=file:///home/user1/ssl.client.props
-Dcom.ibm.CORBA.ConfigURL=file:///home/user1/sas.client.props

you can find these files in your WebSphere installation files, in PROFILE_ROOT\properties

Upvotes: 5

Related Questions