• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

pls help! Error with client in j2ee server

 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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);}
}
}
 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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]
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 just had the craziest dream. This tiny ad was in it.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic