Win a copy of Java Concurrency Live Lessons this week in the Threads forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

What's the matter with the test.java  RSS feed

 
zknyy wolf
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I write a "hello world" session bean and a test client ,I depoly bean on weblogic is ok ,but the client has wrong when is working.
the code like this:
//Hello.java
package mastejbone;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface Hello extends javax.ejb.EJBObject {
public String hello(String msg) throws RemoteException;
}
//HelloBean.java
package mastejbone;
import javax.ejb.*;
public class HelloBean implements SessionBean {
SessionContext sessionContext;
public void ejbCreate() throws CreateException {
}
public void ejbRemove() {
}
public void ejbActivate() {
}
public void ejbPassivate() {
}
public void setSessionContext(SessionContext sessionContext) {
this.sessionContext = sessionContext;
}
public String hello(String msg) {
return "hello"+msg;
}
}
//HelloHome.java
package mastejbone;
import javax.ejb.*;
import java.util.*;
import java.rmi.*;
public interface HelloHome extends javax.ejb.EJBHome {
public Hello create() throws CreateException, RemoteException;
}
//test.java
//the test file
package test;
import mastejbone.*;
import javax.naming.*;
import java.util.*;
import javax.rmi.PortableRemoteObject;
public class test {
public static void main(String[] args)throws Exception {
Properties props = System.getProperties();
Context ctx = new InitialContext(props);
Object obj = ctx.lookup("Hello");
//cast to Home interface
HelloHome Home = (HelloHome)PortableRemoteObject.narrow(obj,HelloHome.class);
Hello hello = Home.create();
System.out.print(hello.hello("test "));
}
}
//exec the test.java
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
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:638)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:241)
at javax.naming.InitialContext.getURLOrDefaultInitCtx(InitialContext.java:278)
at javax.naming.InitialContext.lookup(InitialContext.java:345)
at test.test.main(test.java:18)
Exception in thread "main"
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you built the client jar file? Is it in the same directory as your client class? If you have WL installed, look at their samples to learn how to build client jar files and how to test using stand alone java clients.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will have to do something like this in order for the client test class to figure out where the Initial context is .

Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx = new InitialContext(h);
Object home = ctx.lookup(JNDI_NAME);
...
...
 
zknyy wolf
Greenhorn
Posts: 21
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ajith Kallambella:
You will have to do something like this in order for the client test class to figure out where the Initial context is .

Properties h = new Properties();
h.put(Context.INITIAL_CONTEXT_FACTORY,
"weblogic.jndi.WLInitialContextFactory");
h.put(Context.PROVIDER_URL, "t3://localhost:7001");
Context ctx = new InitialContext(h);
Object home = ctx.lookup(JNDI_NAME);
...
...

thanks Ajith,
I test it and pass.now I want test it in j2sdkee1.3.1,but the code of "weblogic.jndi.WLInitialContextFactory" do not work correct in client,and i doubt the j2sdkee do not support RIM-IIOP client.(I try the example which is a web client and success in j2ee_home/doc/example, but when i deploy my hello bean on the server,the hello bean client is not work correctly)
 
Don't get me started about those stupid light bulbs.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!