0
votes

I have got a problem with ejb remote method invocation.
For testing I created a ejb project with a statless bean and a simple method, declared in a remote interface. I deployed this project in a JBoss 7.1.

Now I want to call the business method hello in my bean from another class, which is not part of the project and not deployed in that jboss server. So if I understand it correct, this is a normal remote method call from a client.

I wrote my HelloWorldClient, declared the properties for the InitialContext(). But when I run this client, I got a NameNotFoundException. For me it seems like the exception is because of a false jndi-name, but I tried a lot to get the correct one.

On the console I got jndi names from my server for the project, but it doesn't work. Could someone help me solve this problem?

Client with context:

Properties jndiProps = new Properties();
         jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
         jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
         jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
         jndiProps.put(Context.SECURITY_PRINCIPAL, "testuser");
         jndiProps.put(Context.SECURITY_CREDENTIALS, "testpasswort");
         Context ctx = new InitialContext(jndiProps);
         HelloWorldRemote hello = (HelloWorldRemote) ctx.lookup("java:global[/ejbproject1]/ejbproject1/HelloWorldBean[/HelloWorldRemote]");

My Bean:

@Stateless(name="hello")
public class HelloWorldBean implements HelloWorldRemote{

@Override
public String hello(String value) {
    System.out.println("Say hello to "+value);
    return "Hello " + value;
}


the jndi names from the jboss

18:19:07,464 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-6) JNDI bindings for session bean named hello in deployment unit deployment "ejbproject1.jar" are as follows:

java:global/ejbproject1/hello!interfaces.HelloWorldRemote
java:app/ejbproject1/hello!interfaces.HelloWorldRemote
java:module/hello!interfaces.HelloWorldRemote
java:jboss/exported/ejbproject1/hello!interfaces.HelloWorldRemote
java:global/ejbproject1/hello
java:app/ejbproject1/hello
java:module/hello


and the exception:

javax.naming.NameNotFoundException: global[/ejbproject1]/ejbproject1/HelloWorldBean[/HelloWorldRemote] -- service jboss.naming.context.java.jboss.exported.global[.ejbproject1].ejbproject1.HelloWorldBean[.HelloWorldRemote]
1

1 Answers

0
votes

Change from

java:global/ejbproject1/hello!interfaces.HelloWorldRemote

to

java:/ejbproject1/hello!interfaces.HelloWorldRemote

That will work.