Wildfly Remote EJB Invocation

11,134

Solution 1

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());

Solution 2

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.

Solution 3

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.

Share:
11,134
Jack Ant
Author by

Jack Ant

Updated on June 13, 2022

Comments

  • Jack Ant
    Jack Ant almost 2 years

    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.

  • wibobm
    wibobm over 9 years
    The question is about invoking a EJB from a remote server.
  • Alexander Rühl
    Alexander Rühl over 9 years
    @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.
  • Peter Butkovic
    Peter Butkovic almost 8 years
    this is the first way that worked for me! I've already tried (too) many :)
  • B Medeiros
    B Medeiros over 5 years
    Link to the master branch (as 10.x is getting old): github.com/wildfly/quickstart/tree/master/ejb-remote