I'm a little new to the whole
EJB thing and I'm just trying to get a helloworld session bean to work and have hit a wall.
I'm using the 1.4 Beta J2EE SDK from Sun. I ran the asadmin server and the server starts up ok. I point my browser to localhost:4848 and I get the display page. Check. I also deployed their sample
jsp page and that worked too so I'm assuming the server is running and working the way it should.
Now for the part that doesn't work. I made the helloworld session bean and then made my TestClient program. Now, in the documentation it says that when you use the deploytool on your .ear file (which I made with the delpoytool) you need to get it to return a client jar. There is a little check on the deploytool for this operation and I check the box when its deploying my .ear file. Now, shouldn't I get a .jar file in return? NO matter what I type in that stupid field I can't get it to produce a jar file. From what I read, I need to include this .jar file in the classpath when I run the client or it won't be able to connect to the sessionbean.
Now, after about 9 hours of playing with the stupid thing, I finally get it to produce a .jar file for me. But, I called it helloClient.jar and it gives me helloworldClient.jar? I'm totally confused. But anyway, I include the stupid .jar file in my classpath for my TestClient program anyway, just to see what happens.
I run my TestClient and it throws an InitialContext error. Says I need to pass it an initialcontxt. Alright. I create a hashtable and pass it 3 different values in 3 different tests to see what happens.
I pass the following,
com.sun.jndi.rmi.registry.RegistryConextFactory
com.sun.jndi.cosnaming.CNCtxFactory
com.sun.jndi.ldap.LdapCtxFactory
they all throw a different exception but what its saying is it can't connect on port 389 I believe it is. Firewall is disabled so this shouldn't be a problem.
Now, reading through some books and things, they tell me you have to supply your own InitialContext which is dependent on what server you're running.
Well, I can't find this anywhere in any documentation for Sun's J2EE asadmin server. When you run that asadmin server tool, what is the default InitialConext? Is it running an LDAP by default? I can't find it.
Or is there no naming service included at all and I have to download something else yet on top of it? You'd think they'd have a naming service included.
Here's the TestHello Program. NOthing earth shattering
***********************************************************
import java.util.*;
import javax.naming.*;
import javax.rmi.*;
public class TestHello
{
public static void main(
String[] args)
{
try
{
/** Creates a JNDI naming context for location objects */
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "com.sun.jndi.ldap.LdapCtxFactory");
//com.sun.jndi.rmi.registry.RegistryContextFactory
//com.sun.jndi.cosnaming.CNCtxFactory
//com.sun.jndi.ldap.LdapCtxFactory
Context context = new InitialContext(env);
/** Asks the context to locate an object named "HelloWorld" and expects the
object to implement the HelloWorldSessionHome interface */
HelloWorldSessionHome home = (HelloWorldSessionHome)
PortableRemoteObject.narrow(
context.lookup("HelloWorld"),
HelloWorldSessionHome.class);
/** Asks the Home interface to create a new session bean */
HelloWorldSession session = (HelloWorldSession) home.create();
System.out.println("The default greeting is: "+
session.getGreeting());
session.setGreeting("Howdy!");
System.out.println("The greeting is now: "+session.getGreeting());
/** Destroy this session */
session.remove();
/** Now create a session with a different greeting */
session = (HelloWorldSession) home.create("Guten Tag!");
System.out.println("Created a new session with a greeting of: "+
session.getGreeting());
/** Destroy this session */
session.remove();
}
catch (Exception exc)
{
exc.printStackTrace();
}
}
}
***********************************************
Here is the stacktrace once the client is provided with an InitialContext.
I'm running this from Eclipse 2.0 and 1.4.1 JDK.
javax.naming.CommunicationException: localhost:389. Root exception is java.net.ConnectException: Connection refused: connect
at java.net.PlainSocketImpl.socketConnect(Native Method)
at java.net.PlainSocketImpl.doConnect(PlainSocketImpl.java:305)
at java.net.PlainSocketImpl.connectToAddress(PlainSocketImpl.java:171)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:158)
at java.net.Socket.connect(Socket.java:434)
at java.net.Socket.connect(Socket.java:384)
at java.net.Socket.<init>(Socket.java:291)
at java.net.Socket.<init>(Socket.java:119)
at com.sun.jndi.ldap.Connection.createSocket(Connection.java:346)
at com.sun.jndi.ldap.Connection.<init>(Connection.java:181)
at com.sun.jndi.ldap.LdapClient.<init>(LdapClient.java:119)
at com.sun.jndi.ldap.LdapClient.getInstance(LdapClient.java:1668)
at com.sun.jndi.ldap.LdapCtx.connect(LdapCtx.java:2556)
at com.sun.jndi.ldap.LdapCtx.<init>(LdapCtx.java:275)
at com.sun.jndi.ldap.LdapCtxFactory.getInitialContext(LdapCtxFactory.java:53)
at javax.naming.spi.NamingManager.getInitialContext(NamingManager.java:662)
at javax.naming.InitialContext.getDefaultInitCtx(InitialContext.java:243)
at javax.naming.InitialContext.init(InitialContext.java:219)
at javax.naming.InitialContext.<init>(InitialContext.java:195)
at TestHello.main(TestHello.java:23)
Help a noob please.
Thanks.