Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

WAS CE: JNDI lookup for standalone EJB client

30 views
Skip to first unread message

devu...@rediffmail.com

unread,
Jun 22, 2008, 11:02:20 AM6/22/08
to
Server: WAS CE 2.0

I can't for the life of me do a lookup for an EJB I have deployed using a standalone EJB client. Its a simple "HelloWorld" style EJB.

I have included an openejb-jar.xml file that looks like this:

?xml version= "1.0" encoding= "UTF-8"
 
openejb-jar xmlns= "http://www.openejb.org/xml/ns/openejb-jar-2.2"
xmlns:dep= "http://geronimo.apache.org/xml/ns/deployment-1.2"
xmlns:naming= "http://geronimo.apache.org/xml/ns/naming-1.2"
xmlns:security= "http://geronimo.apache.org/xml/ns/security-1.2"
xmlns:pkgen= "http://www.openejb.org/xml/ns/pkgen-2.0"
 


LocalTest
bs
test


 

 
!-- Begin configuration for
!-- Repeat for

 
!-- End configuration for

 


Here are my classes and client code

package bs.dk.ejb;
 
import javax.ejb.Stateless;
 
@Stateless (name= "Myejb" )
public class HelloBean implements Hello {

public String hello() {
System.out.println( "hello" );
return "HELLO" ;
}
}

package bs.dk.ejb;
 
import javax.ejb.Remote;
 
@Remote
public interface Hello {
public String hello();
}

package bs.dk.client;
 
import java.util.Properties;
 
import javax.naming.Context;
import javax.naming.InitialContext;
 
import bs.dk.ejb.Hello;
 
 
public class EJBClient {

public static void main(String[] args) throws Exception {
Properties prop = new Properties();
prop.put(Context.INITIAL_CONTEXT_FACTORY,
"org.openejb.client.RemoteInitialContextFactory" );
prop.put(Context.PROVIDER_URL, "ejbd://localhost:4201" );
Context ctx = new InitialContext(prop);
System.out.println (ctx.getEnvironment());
Hello hello = (Hello) ctx.lookup( "bs/Myejb/bs.dk.ejb.Hello" );
hello.hello();

}
}

A few points I'd like to mention.

Here is how the JNDI tree looks like in the admin console after deployment.

+EJBModule
+LocalTest/bs/test/jar
+SessionBeans
+Myejb
+java:comp/HandleDelegate
+java:comp/ORB
+java:comp/TimerService
+java:comp/TransactionManager
+java:comp/TransactionSynchronizationRegistry
+java:comp/env/dummy

Here is the info the JMX viewer gives

deploymentid = bs/Myejb

As per the documentation, I ought to be able to look it up.

Link: http://publib.bo ulder.ibm.com/wasce/V2.0.0/en/jndi.html

Here is the exact trace when I run the client

{ java.naming.provider.url=ejbd: //localhost:4201, java.naming.factory.initial=org.openejb.client.RemoteInitialContextFactory}
Exception in thread "main" javax.naming.NameNotFoundException: /bs/Myejb/bs.dk.ejb.Hello does not exist in the system. Check that the app was successfully deployed.
at org.apache.openejb.client.JNDIContext.lookup(JNDIContext.java:239)
at javax.naming.InitialContext.lookup(Unknown Source)
at bs.dk.client.EJBClient.main(EJBClient.java:20)


I've spent a day on this simple thing. Any ideas what the problem is? Find attached my code in case you want to try it out.

devu...@rediffmail.com

unread,
Jun 25, 2008, 8:24:19 PM6/25/08
to
Okay here's the answer. I changed the client code to look like this

public class EJBClient {

 


public static void main(String[] args) throws Exception {
Properties prop = new Properties();

 
prop.put(Context.INITIAL_CONTEXT_FACTORY,
 
"org.openejb.client.RemoteInitialContextFactory" );
 


prop.put(Context.PROVIDER_URL, "ejbd://localhost:4201" );

 


Context ctx = new InitialContext(prop);

 
System.out.println (ctx.getEnvironment());
 
Hello hello = (Hello) ctx.lookup( "MyejbRemote" );
 
hello.hello();
 

 
}
}

The change is Hello hello = (Hello) ctx.lookup("MyejbRemote");

Apparently WAS CE exposes the bean on JNDI as Remote and Home. I don't know where this is documented though.

0 new messages