aspose file tools*
The moose likes EJB and other Java EE Technologies and the fly likes pls help! Error with client in j2ee server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » EJB and other Java EE Technologies
Bookmark "pls help! Error with client in j2ee server" Watch "pls help! Error with client in j2ee server" New topic
Author

pls help! Error with client in j2ee server

archana vishwanath
Ranch Hand

Joined: Mar 09, 2004
Posts: 39
Hi friends!
Im trying to run my first session bean in j2ee server.And after deploying the bean while tying to execute my client,im getting this error.Pls help me with this.
D:\ssitemp>java TemperatureClient
javax.naming.NoInitialContextException: Need to specify class name in environmen
t or system property, or as an applet parameter, or in an application resource f
ile: java.naming.factory.initial

>>>>>And this is the code.Pls tell me if I need to make any changes in my code.

import javax.naming.Context;
import java.io.*;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.*;
public class TemperatureClient{
public static void main(String args[]){
TemperatureHome home;

try{
Properties env=new Properties();
Context initial=new InitialContext(env);
Object objref=initial.lookup("TemperatureEJB");
home=(TemperatureHome)PortableRemoteObject.narrow(objref,TemperatureHome.class);
Temperature degreeConvertor=home.create();
System.out.println("Sucess");

}
catch(Exception e){System.out.println(e);}
}
}
Anna Madhusudhanan Natanagopalan
Greenhorn

Joined: Apr 05, 2004
Posts: 25
Hi ,
you have to set the environment settings.
.....<sample code>........
public class Client{
public static void main(String[] args){
new Client().doAction();
}
public void doAction() throws Exception{
InitialContext ctx=getInitialContext();
Object obj= ctx.lookup(jndiName);
home=(YOURHOME)PortableRemoteObject.narrow(obj,YOURHOME.class);
remote=home.create();
}
public InitialContext getInitialContext() throws NamingException{
Hashtable hs= new Hashtable();
hs.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
hs.put("java.naming.provider.url","iiop://127.0.0.1");
hs.put(Context.SECURITY_PRINCIPAL,"j2ee");
hs.put(Context.SECURITY_CREDENTIALS,"j2ee");
return new InitialContext(hs);
}
}
i am working in sun one application server. it is working in sun one appli server. try to execute this one, hope j2ee also support this one.
If any one find any problem or any error/ wrong in this approach , your suggestions are most welcome.
Thanks and regards
Anna Madhusudnanan
Bhupesh Kokate
Greenhorn

Joined: Jul 18, 2003
Posts: 22
I dont think there is as such need to provide info to initial context because server itself provide it specially websphere I have experienced. Only thing I would say is try changing ur way of instantiating initial context to new InitialContext();
hope that helps
Thanks
Bhupesh
archana vishwanath
Ranch Hand

Joined: Mar 09, 2004
Posts: 39
Thanks friends!
As Bhupesh said,new Initial Context() gives the same error as before.
This is the error im getting when I changed my code code according to Anna Madhu
javax.naming.CommunicationException: Cannot connect to ORB [Root exception is or
g.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No]
and here is my new code.Pls help me troube shooting with this.[Im a new bee
breaking my head for this simple client code]

import javax.naming.Context;
import java.io.*;
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.util.*;
import javax.naming.*;
public class TemperatureClient{
TemperatureHome home;
public static void main(String args[]){
try{
new TemperatureClient().doAction();
}
catch(Exception e){System.out.println(e);}
}

public void doAction() throws Exception{
InitialContext ctx=getInitialContext();
Object obj= ctx.lookup("TemperatureEJB");
home=(TemperatureHome)PortableRemoteObject.narrow(obj,TemperatureHome.class);
Temperature remote=home.create();
}
public InitialContext getInitialContext() throws NamingException{
Hashtable hs= new Hashtable();
hs.put("java.naming.factory.initial","com.sun.jndi.cosnaming.CNCtxFactory");
hs.put("java.naming.provider.url","iiop://127.0.0.1");
return new InitialContext(hs);
}
}
archana vishwanath
Ranch Hand

Joined: Mar 09, 2004
Posts: 39
Urgent!!!Pls help me with this error
javax.naming.CommunicationException: Cannot connect to ORB [Root exception is or
g.omg.CORBA.COMM_FAILURE: vmcid: SUN minor code: 201 completed: No]
Kalyan Mudumbai
Greenhorn

Joined: Apr 30, 2004
Posts: 12
What's the application server which you are using? Minimum things which you need to know before calling a client are:
1. The JNDI name of the ejb/home
2. The hostname/port of the server
These things are not seen in your code. The hostname/port depends on server to server.
For example:
for weblogic, following code would work:
public class Client
{
private static final String JNDI_NAME = "ejb20-greetingsBean-GreetingsHome";
private String url;
private GreetingsHome home;
public Client(String url) throws NamingException {
this.url = url;
home = lookupHome();
}
public static void main(String[] args) throws Exception {
log("\nBeginning greetingsBean.Client...\n");
String url = "t3://localhost:7001";
Client client = null;
// Parse the argument list
if (args.length != 1) {
log("Usage: java examples.ejb20.basic.greetingsBean.Client t3://hostname ort");
return;
} else {
url = args[0];
}
try {
client = new Client(url);
client.example();
} catch (NamingException ne) {
log("Unable to look up the beans home: " + ne.getMessage());
throw ne;
} catch (Exception e) {
log("There was an exception while creating and using the Greetings.");
log("This indicates that there was a problem communicating with the server: "+e);
throw e;
}
log("\nEnd greetingsBean.Client...\n");
}
public void example()
throws CreateException, RemoteException, RemoveException
{
log("Creating the Greetings");
Greetings greetings = (Greetings) narrow(home.create(), Greetings.class);
System.out.println(greetings.getMessage());

log("Removing the greetings");
greetings.remove();
}
private Object narrow(Object ref, Class c) {
return PortableRemoteObject.narrow(ref, c);
}
private GreetingsHome lookupHome() throws NamingException {
// Lookup the beans home using JNDI
Context ctx = getInitialContext();
try {
Object home = ctx.lookup(JNDI_NAME);
return (GreetingsHome) narrow(home, GreetingsHome.class);
} catch (NamingException ne) {
log("The client was unable to lookup the EJBHome. Please make sure ");
log("that you have deployed the ejb with the JNDI name "+
JNDI_NAME+" on the WebLogic server at "+url);
throw ne;
}
}
private Context getInitialContext() throws NamingException {

try {
// Get an InitialContext
Hashtable h = new Hashtable();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, url);
return new InitialContext(h);
} catch (NamingException ne) {
log("We were unable to get a connection to the WebLogic server at "+url);
log("Please make sure that the server is running.");
throw ne;
}
}
private static void log(String s) { System.out.println(s); }

}
HTH,
Kalyan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: pls help! Error with client in j2ee server
 
Similar Threads
Problem of running an ejb client on Solaris
I have deployed my ejb with Weblogic and I have a problem with my client
Jsp and EJB
Naming Exception at runtime when running client.
JNDI not creating for EJB Local interfaces example