I have a simple stand alone
Java client, the code for which is:-
package www.client.com;
import java.util.Properties;
import javax.naming.Context;
import javax.naming.InitialContext;
import www.async.com.AsyncBean;
public class Client {
public static void main(
String[] args) {
try {
Properties jndiProps = new Properties();
jndiProps.put("java.naming.factory.initial", "com.sun.enterprise.naming.impl.SerialInitContextFactory");
jndiProps.put("java.naming.factory.url.pkgs", "com.sun.enterprise.naming");
jndiProps.put("java.naming.factory.state", "com.sun.corba.ee.impl.presentation.rmi.JNDIStateFactoryImpl");
jndiProps.setProperty("org.omg.CORBA.ORBInitialHost", "127.0.0.1");
jndiProps.setProperty("org.omg.CORBA.ORBInitialPort", "3700");
Context ctx = new InitialContext(jndiProps);
@SuppressWarnings("unused")
AsyncBean mySessionBean = (AsyncBean)ctx.lookup("AsyncEJB");
} catch (Exception e) {
e.printStackTrace();
}
}
}
This invokes the following stateless bean:-
package www.async.com;
import javax.ejb.Stateless;
/**
* Session Bean implementation class AsyncBean
*/
@Stateless(mappedName="AsyncEJB")
public class AsyncBean implements AsyncBeanRemote, AsyncBeanLocal {
/**
* Default constructor.
*/
public AsyncBean() {
// TODO Auto-generated constructor stub
}
public void doSomething(String message) {
System.out.println(message);
}
}
The remote interface for this is:-
package www.async.com;
import javax.ejb.Remote;
@Remote
public interface AsyncBeanRemote {
public void doSomething(String message);
}
My understaning with JEE6 is that the mapping information provided with the @Stateless annotation should create a JNDI reference of AsyncBean for me, although I should not need any deployment descriptors, this is my sun-ejb-jar.xml file:-
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE sun-ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Application Server 9.0
EJB 3.0//EN" "http://www.sun.com/software/appserver/dtds/sun-ejb-jar_3_0-0.dtd">
<sun-ejb-jar>
<enterprise-beans>
<ejb>
<ejb-name>AsyncBean</ejb-name>
<jndi-name>AsyncEJB</jndi-name>
</ejb>
</enterprise-beans>
</sun-ejb-jar>
When I run the client I get:-
ava.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at www.client.com.Client.main(Client.java:19)
javax.naming.NamingException: Lookup failed for 'AsyncEJB' in SerialContext targetHost=127.0.0.1,targetPort=3700 [Root exception is javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=127.0.0.1,targetPort=3700 [Root exception is java.lang.NullPointerException]]
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:442)
at javax.naming.InitialContext.lookup(InitialContext.java:392)
at www.client.com.Client.main(Client.java:19)
Caused by: javax.naming.NamingException: Unable to acquire SerialContextProvider for SerialContext targetHost=127.0.0.1,targetPort=3700 [Root exception is java.lang.NullPointerException]
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:276)
at com.sun.enterprise.naming.impl.SerialContext.lookup(SerialContext.java:430)
... 2 more
Caused by: java.lang.NullPointerException
at com.sun.enterprise.naming.impl.SerialContext.getRemoteProvider(SerialContext.java:297)
at com.sun.enterprise.naming.impl.SerialContext.getProvider(SerialContext.java:271)
... 3 more
My initial thoughts are that the lookup is not finding the JNDI reference for my bean, or the reference I'm providing is incorrect. I would have posted this on a Sun forum, if it were not for the fact that some moron appears to have completely spammed it. Can someone advise as to why my client is not working.