wood burning stoves*
The moose likes Websphere and the fly likes Running EJB Client Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Products » Websphere
Bookmark "Running EJB Client" Watch "Running EJB Client" New topic
Author

Running EJB Client

Ram Pra
Ranch Hand

Joined: Feb 06, 2001
Posts: 37
Hello,
I have written a simple EJB and succesfully deployed the same on the WebSphere AppServer 3.4 edition.My client is a JSP ,when i try to run the the client I get the following message,can anybody help me on this.

javax.naming.CommunicationException. Root exception is org.omg.CORBA.COMM_FAILURE: minor code: 1 completed: Maybe
at org.omg.CORBA.SystemException.<init>(SystemException.java:51)
at org.omg.CORBA.COMM_FAILURE.<init>(COMM_FAILURE.java:79)
at org.omg.CORBA.COMM_FAILURE.<init>(COMM_FAILURE.java:65)
at com.ibm.CORBA.iiop.IIOPConnection.purge_calls(Unknown Source)
at com.ibm.CORBA.iiop.StandardReaderThread.run(Unknown Source)
Scratch dir for the JSP engine is: D:\WebSphere\AppServer\temp\default_host\dev
IMPORTANT: Do not modify the generated servlets
Note: D:\WebSphere\AppServer\temp\default_host\dev\user20_XMLExample_jsp_34.java uses or overrides a deprecated API. Recompile with "-deprecation" for details.
1 warning
My client code goes this way...
< !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<%@ page import="com.gdii.helloworld.*, javax.ejb.*, javax.naming.* , java.rmi.*, java.util.* " %>
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>
<BODY>


running ejb

<%try { <br /> Properties props = System.getProperties() ;<br /> props.put(javax.naming.Context.PROVIDER_URL, "iiop://192.168.3.134:80") ;<br /> props.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory") ;<br /> Context ctx = new InitialContext(props) ;<br /> <br /> //HelloHome home = (HelloHome) ctx.lookup("RITA") ;<br /> <br /> Object obj = ctx.lookup("RITA") ;<br /> HelloHome home = (HelloHome) javax.rmi.PortableRemoteObject.narrow(obj, HelloHome.class) ;<br /> <br /> //Context ctx = new InitialContext(props) ;<br /> //HelloHome home = (HelloHome)ctx.lookup("RITA") ;<br /> Hello hello = home.create() ;<br /> %>
This is the output


<%=hello.hello()%>


<%<br /> //out.println(hello.hello()) ;<br /> hello.remove() ;<br /> }catch(Exception excp) {<br /> excp.printStackTrace() ;<br /> }<br /> %>


ejb run successfully


</BODY>
</HTML>
Konda Balabbigari
Ranch Hand

Joined: Jan 02, 2001
Posts: 35
Hi Prashanth
Try importing org.omg.CORBA package, and the type casting the home object.
InitialContext ctx = new InitialContext(env);
Object homeObject = ctx.lookup("regis");
regHome = (RegHome)javax.rmi.PortableRemoteObject.narrow((org.omg.CORBA.Object) homeObject, RegHome.class);
Here is the sample code.
Thanks
Konda.
[This message has been edited by Konda Balabbigari (edited February 06, 2001).]
Ram Pra
Ranch Hand

Joined: Feb 06, 2001
Posts: 37
Hi,
Now I have a problem running the client.The client stops running with an exception NameNotFoundException.
While genrating deployment descriptor using the jetace tool I have specified the JNDI name and using the same in my client programme too.And I delpoy it successfully using the admin console.
I don't exactly why i getting this problem..have i missed out something while installing or should I take care of something else which I haven't done.Please help me out.
My client code goes this way...
import com.gdii.helloworld.* ;
import java.util.*;
import java.rmi.*;
import javax.naming.*;
import javax.ejb.*;
import javax.rmi.PortableRemoteObject;
public class HelloClient{
public static void main(String [] args) {
try {
// Properties props = System.getProperties() ;
// Context ctx = new InitialContext(props) ;
System.out.println("1");
Properties properties = new Properties();
System.out.println("2");
properties.put(javax.naming.Context.PROVIDER_URL,"iiop://192.168.3.134");
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");

System.out.println("3");
System.out.println(properties.get(javax.naming.Context.PROVIDER_URL));
System.out.println(properties.get(javax.naming.Context.INITIAL_CONTEXT_FACTORY));
InitialContext initial= new InitialContext(properties);
System.out.println("4");
Object homeObject=initial.lookup("rita");
System.out.println("5");
HelloHome home =(HelloHome) PortableRemoteObject.narrow(homeObject,HelloHome.class);
System.out.println("6");

//Context ctx = new InitialContext() ;
//HelloHome home = (HelloHome) ctx.lookup("HelloHome") ;
Hello hello = home.create() ;
System.out.println(hello.hello()) ;
hello.remove() ;
}catch(Exception excp) {
excp.printStackTrace() ;
}
}
}

Prashanth
Konda Balabbigari
Ranch Hand

Joined: Jan 02, 2001
Posts: 35
Hi Prashanth
I tried your code it is executing fine. Only if you give wrong jndi name then only it is giving NameNotFoundException. Can you post the error output you got.
Thanks
Konda
Ram Pra
Ranch Hand

Joined: Feb 06, 2001
Posts: 37
Thank you very much Konda,
I got my EJB running,Actually I was not running the EJb after deploying the same.Once I got it running,the client program ran succesfully.
Thanks again
Prashanth
sravan mandala
Greenhorn

Joined: Mar 13, 2001
Posts: 7
Hi Prashanth
I have deployed the bean one which is there in the examples of Websphere 3.5 Application server using the Admin Console and it says the Hello Bean is deployed but when i am running the Client program i am getting the following error
N
[Root Exception is java.lang.ClassNotFoundException:com.ibm.ejs.ns.jndi.CNInitialContextFactory]javax.Naming.NoInitialContextException:cannot Instantiate class:com.ibm.ejs.ns.jndi.CNInitialContextFactory
at java.naming.spi.NamingManager.getDefaultInitialContextFactory(NamingManager.java:720)
at java.naming.spi.NamingManager.getInitialContext(NamingManager.java:768)
at java.naming.InitialContext.getDefaultInitialContextFactory(InitialContext.java:169)
at java.naming.InitialContext.<init><InitialContext.java:148)>
at HelloClient.main(HelloClient.java:25)
Please can you help me out i am providing the following client code

import com.ibm.ejb.cb.samples.hello.tier2.Hello; // Hello EJB
import com.ibm.ejb.cb.samples.hello.tier2.HelloHome; // Hello EJB's Home
import java.util.*;
import java.rmi.*;
import javax.naming.*;
import javax.ejb.*;
import javax.rmi.PortableRemoteObject;
public class HelloClient{
public static void main(String [] args) {
try {
// Properties props = System.getProperties() ;
// Context ctx = new InitialContext(props) ;
System.out.println("1");
Properties properties = new Properties();
System.out.println("2");
properties.put(javax.naming.Context.PROVIDER_URL,"iiop://192.168.3.134");
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
System.out.println("3");
System.out.println(properties.get(javax.naming.Context.PROVIDER_URL));
System.out.println(properties.get(javax.naming.Context.INITIAL_CONTEXT_FACTORY));
InitialContext initial= new InitialContext(properties);
System.out.println("4");
Object homeObject=initial.lookup("HelloHome");
System.out.println("5");
HelloHome home =(HelloHome) PortableRemoteObject.narrow(homeObject,HelloHome.class);
System.out.println("6");

//Context ctx = new InitialContext() ;
//HelloHome home = (HelloHome) ctx.lookup("HelloHome") ;
Hello hello = home.create() ;
System.out.println(hello.getMessage()) ;
hello.remove() ;
}catch(Exception excp) {
excp.printStackTrace() ;
}
}
Can you tell me what the problem could be
Regards
shravan

[This message has been edited by sravan mandala (edited March 13, 2001).]
Ram Pra
Ranch Hand

Joined: Feb 06, 2001
Posts: 37
Hey Shrava,
Right_Click on the Hello Bean from the admin console and say run.Try running the client then....you should be succesfull

Prashanth
Ram Pra
Ranch Hand

Joined: Feb 06, 2001
Posts: 37
Hello Sravan,
I saw in your client program: You are using my ipaddress instead of urs.
**********wrong*********************************************
properties.put(javax.naming.Context.PROVIDER_URL,"iiop://192.168.3.134");
*************************************************************
you should be using the follwing..
roperties.put(javax.naming.Context.PROVIDER_URL,"iiop://your ipaddress");
***************************************************************
If you don't know the ip address just go to the dos prompt and type ipconfig
You'll get the ip address of ur m/c
Prashanth
sravan mandala
Greenhorn

Joined: Mar 13, 2001
Posts: 7
Hi Prashanth,
Can you help please i have deployed a bean using jetace tool and then when i am running the client program its giving the following error
E:\WebSphere\samples>java HelloClient
1
2
3
iiop://192.168.0.11
com.ibm.ejs.ns.jndi.CNInitialContextFactory
Exception in thread "main" java.lang.NoClassDefFoundError: com/ibm/rmi/iiop/ORB
at java.lang.ClassLoader.defineClass0(Native Method)
at java.lang.ClassLoader.defineClass(ClassLoader.java:477)
at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:109)
at java.net.URLClassLoader.defineClass(URLClassLoader.java:248)
at java.net.URLClassLoader.access$1(URLClassLoader.java:216)
at java.net.URLClassLoader$1.run(URLClassLoader.java:197)
at java.security.AccessController.doPrivileged(Native Method)
at java.net.URLClassLoader.findClass(URLClassLoader.java:191)
at java.lang.ClassLoader.loadClass(ClassLoader.java, Compiled Code)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:285)
at java.lang.ClassLoader.loadClass(ClassLoader.java:255)
at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:314)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:199)
at org.omg.CORBA.ORB.create_impl(ORB.java:303)
at org.omg.CORBA.ORB.init(ORB.java:352)
at com.ibm.CORBA.iiop.GlobalORBFactory.init(GlobalORBFactory.java:42)
at com.ibm.ejs.oa.EJSORBImpl.initializeORB(EJSORBImpl.java:196)
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java, Compiled Code)
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java:65)
at com.ibm.ejs.oa.EJSClientORBImpl.<init>(EJSClientORBImpl.java:47)
at com.ibm.ejs.oa.EJSORB.init(EJSORB.java:343)
at com.ibm.ejs.ns.jndi.CNInitialContextFactory.initORB(CNInitialContextFactory.java:355)
at com.ibm.ejs.ns.jndi.CNInitialContextFactory.getInitialContext(CNInitialContextFactory.java:196)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:672)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:250)
at javax.naming.InitialContext.init(InitialContext.java:226)
at javax.naming.InitialContext.<init>(InitialContext.java:202)
at HelloClient.main(HelloClient.java:25)
and my client program is
HelloClient.java

import com.ibm.ejb.cb.samples.hello.tier2.Hello; // Hello EJB
import com.ibm.ejb.cb.samples.hello.tier2.HelloHome; // Hello EJB's Home
import java.util.*;
import java.rmi.*;
import javax.naming.*;
import javax.ejb.*;
import javax.rmi.PortableRemoteObject;
public class HelloClient{
public static void main(String [] args) {
try {
// Properties props = System.getProperties() ;
// Context ctx = new InitialContext(props) ;
System.out.println("1");
Properties properties = new Properties();
System.out.println("2");
properties.put(javax.naming.Context.PROVIDER_URL,"iiop://192.168.0.11");
properties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
System.out.println("3");
System.out.println(properties.get(javax.naming.Context.PROVIDER_URL));
System.out.println(properties.get(javax.naming.Context.INITIAL_CONTEXT_FACTORY));
InitialContext initial= new InitialContext(properties);
System.out.println("4");
Object homeObject=initial.lookup("HelloHome");
System.out.println("5");
HelloHome home =(HelloHome) PortableRemoteObject.narrow(homeObject,HelloHome.class);
System.out.println("6");

//Context ctx = new InitialContext() ;
//HelloHome home = (HelloHome) ctx.lookup("HelloHome") ;
Hello hello = home.create() ;
System.out.println(hello.getMessage()) ;
hello.remove() ;
}catch(Exception excp) {
System.out.println("the message is:"+excp.getMessage());
}
}
}
waiting for your reply
REgards
shravan
Sheetal Kelkar
Greenhorn

Joined: Jul 27, 2001
Posts: 4
Dear Prashant
I have deployed an EJB successfully on WebSphere4.0.
I have a client written as a java application. In that I have provided my machine's IP address as PROVIDER_URL and the rest of the code is same as of yours. Still It is giving me ClassNotFoundException for com.ibm.ejs.ns.jndi.CNInitialContextFactory. and you suggested to run the EJB from admin console but that option is also not available in WebSphere Advance Single Server Edition 4.0.
Please help
Thanks
-Sheetal
richard marais
Ranch Hand

Joined: Aug 20, 2001
Posts: 30
I'm getting the same error as sravan mandala, does anyone know? or have you fixed it, how?
srilatha kodati
Greenhorn

Joined: Sep 01, 2001
Posts: 2
Hi prashanth,
I have deployed my ejb in websphere3.5 but while running the client application i am getting error
javax.naming.CommunicationException: can't find serialcontextprovider
here is my client program.
import ejb.*;
import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.Properties;

public class HelloClient {
public static void main(String[] args) {
try {
Properties props = System.getProperties();
Context ctx = new InitialContext(props);
HelloHome home = (HelloHome)ctx.lookup("HelloHome");
Hello hello = home.create();
System.out.println(hello.getMessage());
hello.remove();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Gerald Luckenbill
Greenhorn

Joined: Nov 05, 2003
Posts: 15
This is really helpful but not all the way there - now I need to figure out what is proprietary to IBM MQSeries - from my research I believe I need to pass a properties object when I create the initial context - something like:
Properties env = new Properties();
env.put(Context.PROVIDER_URL, "?");
env.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,"com.ibm.ejs.ns.jndi.CNInitialContextFactory");
InitialContext jndi = new InitialContext(env);
When I add this, which seems to be critical or I get(javax.naming.NoInitialContextException: Need to specify class name in environment or system property, or as an applet parameter, or in an application resource file: java.naming.factory.initial) to the sample in the above link I get this error:
Could not create JNDI API context: javax.naming.NoInitialContextException: Cannot instantiate class: com.ibm.ejs.ns.jndi.CNInitialContextFactory [Root exception is java.lang.ClassNotFoundException: com.ibm.ejs.ns.jndi.CNInitialContextFactory]
So, what are the property values I need for IBM MQ - or what am I missing?
Thanks a lot!!!
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
Hello Sheetal and Richard
Exception clearly says "ClassNotFoundException".
Please make sure ibmwebas.jar (Im not sure as I left 3.5 long back, but check it out. If my memory is correct, it is the one containing that ConectFactroyImpl class) is in your classpath where the client program is running.
Srilatha your problem is , there is no properties specified by you for the InitialContext. Give PROVIDER_URL and INITIAL_CONTEXTFACTORY parameters in the property file or hashmap
Mahesh Chalil
Ranch Hand

Joined: Jan 24, 2002
Posts: 147
or it should be under ns.jar or namingclient.jar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Running EJB Client