8

I am trying to invoke a stateless EJB, deployed on a remote server. I can invoke the bean from my local JBoss environment but when I change the remote.connection.default.host to the remote machine's host, my client code does not work.

This is my jboss-ejb-client.properties:

endpoint.name=client-endpoint

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false

remote.connections=default

remote.connection.default.host=SERVERIP/HOSTNAME
remote.connection.default.port=8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.username=username
remote.connection.default.password=Password

And my client code looks like this:

Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
String jndi = "jndi_name";
Context context = new InitialContext(properties);
obj = context.lookup(jndi);

Please help.

Thanks all. Jack.

Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
Jack Ant
  • 201
  • 2
  • 4
  • 7
  • 1
    What exactly "does not work"? And what exactly are you using for lookup? Because this might probably be wrong and your simplified "jndi_name" is maybe the important part about it. – Alexander Rühl Jun 27 '14 at 13:04
  • I could not invoke the remote EJB. I am able to invoke the local EJBs. I have localhost in my jboss-ejb-client.properties file and it works fine. But when I change it to the remote server's IP or Host name it does not work. Please advise. – Jack Ant Jun 30 '14 at 05:45
  • I get the below error when trying to connect. "Could not register a EJB receiver for connection to hostname:8080. java.lang.RuntimeException:Operation failed with status WAITING". – Jack Ant Jun 30 '14 at 06:44
  • The remote port for calling the EJB is probably 4447. – Alexander Rühl Jun 30 '14 at 06:59
  • @Geziefer WildFly uses 8080, 4447 is for JBoss AS 7. What exactly is your JNDI lookup string? – gcvt Sep 04 '14 at 15:46
  • Check this: https://docs.jboss.org/author/display/AS71/EJB+invocations+from+a+remote+client+using+JNDI – Jason Holmberg Aug 18 '15 at 01:55

5 Answers5

3

This answer may be late but I faced the same problem, none of the above answers helped me, to solve this problem, refer the following : http://blog.jonasbandi.net/2013/08/jboss-remote-ejb-invocation-unexpected.html

The code that works for me is as below:

Properties jndiProperties=new Properties();
    jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
    jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
    jndiProperties.put(Context.PROVIDER_URL, "http-remoting://127.0.0.1:8080/");
    //This property is important for remote resolving
    jndiProperties.put("jboss.naming.client.ejb.context", true);
    //This propert is not important for remote resolving
    jndiProperties.put("org.jboss.ejb.client.scoped.context", "true");

    Context context=new InitialContext(jndiProperties);


    /*
    java:global/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
    java:app/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
    java:module/GenericStateless!test.stateless.GenericStateless
    java:jboss/exported/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless
    java:global/JEETest_Project/EJBTest_Project/GenericStateless
    java:app/EJBTest_Project/GenericStateless
    java:module/GenericStateless
     */

    //None of the above names work for remote EJb resolution ONLY THIS WORKS - 
    //"/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless"

    GenericStateless bean=(GenericStateless)context.lookup("/JEETest_Project/EJBTest_Project/GenericStateless!test.stateless.GenericStateless");

    //GenericStateless bean=(GenericStateless)c.lookup("GenericStateless!test.stateless.GenericStateless");
    System.out.println(bean.getInt());
Ironluca
  • 3,402
  • 4
  • 25
  • 32
1

Foolishly believing that I understood EJB deployment on Wildfly, I struggled with remote invocation of my stateless EJBs from a Servlet for several days, trying various configurations from snippets of code that I found on the net. No luck.

I finally came across the following guide from JBOSS which had my problems resolved in about 10 minutes. I had incorrectly configured my remote outbound connection. The Wildfly developers have written an awesome Java EE application server, but they are terrible with explanatory error messages.

The guide is for AS7.2 but it was relevant for my Wildfly 8.2.0 platform.

Hopefully this will save someone the grief that I suffered.

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Steven
  • 1,564
  • 1
  • 22
  • 34
1

What worked for me:

My client was in a standalone maven project. All I needed to do was to add this dependency:

<dependency>
    <groupId>org.wildfly</groupId>
    <artifactId>wildfly-ejb-client-bom</artifactId>
    <version>10.1.0.Final</version>
    <type>pom</type>
    <scope>runtime</scope>
</dependency>

I've come to this solution by looking at the ejb-remote example.

Janez Kuhar
  • 3,705
  • 4
  • 22
  • 45
0

Your client code has to use EJB 3 standardized JNDI name to access your beans

Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
// Not needed but I like to see it when debugging
properties.put(Context.PROVIDER_URL, "http-remoting://localhost:8080/");
// EJB 3 bean naming convention
String jndi = "ejb:/myapp/mymodule/myEjbName!my.own.package.EjbInterface";
Context context = new InitialContext(properties);
obj = context.lookup(jndi);

And check WildFly server.log for the exported JNDI binding of your bean: java:jboss/exported/myapp/mymodule/myEjbName!my.own.package.EjbInterface

To pass security checks, username must be defined in ApplicationRealm.

Yves Martin
  • 10,217
  • 2
  • 38
  • 77
-1

Usually in Java EE, you let the container do the lookup instead of doing it yourself. From the Java EE 6 tutorial:

To obtain a reference to the remote business interface of an enterprise bean through dependency injection, use the javax.ejb.EJB annotation and specify the enterprise bean’s remote business interface name:

@EJB Example example;

If it has to be JNDI lookup, check out this JBoss tutorial - it's for version 7 though, but maybe it is of help for your case.

Alexander Rühl
  • 6,769
  • 9
  • 53
  • 96
  • The question is about invoking a EJB from a remote server. – wibobm Aug 08 '14 at 20:32
  • @wibobm: Did you downvote my answer due to the reason in your comment? Then you might want to read the chapter of the Java EE Tutorial I referred to, specifically the sub chapter "Remote Clients". If you have a `@Remote` interface EJB on one machine, you can access it from another machine by injecting it via `@EJB`. – Alexander Rühl Aug 14 '14 at 16:03