1
votes

I know that many people asked already for this error but I still can not find a solution for my case, which I follow this tutorial to create a Remote Client, accessing to the Bean residing on a Wildfly 10 server, which running at the address: localhost:8082. And here are my code:

My Interface:

package ejb.remote.stateless;
import javax.ejb.Remote;

@Remote
public interface RemoteCalculator {
    int add(int a, int b);
    int subtract(int a, int b);
}

My Bean:

package ejb.remote.stateless;
import javax.ejb.Remote;
import javax.ejb.Stateless;

@Stateless
@Remote(RemoteCalculator.class)
public class CalculatorBean implements RemoteCalculator {

    @Override
    public int add(int a, int b) {
        return a+b;
    }

    @Override
    public int subtract(int a, int b) {
        return a-b;
    }

}

My Remote Client:

package ejb.remote.client;

import java.util.Hashtable;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;


import ejb.remote.stateful.CounterBean;
import ejb.remote.stateful.RemoteCounter;
import ejb.remote.stateless.CalculatorBean;
import ejb.remote.stateless.RemoteCalculator;

public class RemoteEJBClient {

    public static void main(String[] args) throws NamingException {

         // Invoke a stateless bean
        invokeStatelessBean();
    }

    /**
     * Looks up a stateless bean and invokes on it
     *
     * @throws NamingException
     */
    private static void invokeStatelessBean() throws NamingException {

        final RemoteCalculator statelessRemoteCalculator = lookupRemoteStatelessCalculator();
        System.out.println("Obtained a remote stateless calculator for invocation");

        int a = 204;
        int b = 340;
        System.out.println("Adding " + a + " and " + b + " via the remote stateless calculator deployed on the server");
        int sum = statelessRemoteCalculator.add(a, b);
        System.out.println("Remote calculator returned sum = " + sum);
        if (sum != a + b) {
            throw new RuntimeException(
                    "Remote stateless calculator returned an incorrect sum " + sum + " ,expected sum was " + (a + b));
        }

        int num1 = 3434;
        int num2 = 2332;
        System.out.println("Subtracting " + num2 + " from " + num1
                + " via the remote stateless calculator deployed on the server");
        int difference = statelessRemoteCalculator.subtract(num1, num2);
        System.out.println("Remote calculator returned difference = " + difference);
        if (difference != num1 - num2) {
            throw new RuntimeException("Remote stateless calculator returned an incorrect difference " + difference
                    + " ,expected difference was " + (num1 - num2));
        }
    }

    private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException {

        final Hashtable jndiProperties = new Hashtable();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        jndiProperties.put("jboss.naming.client.ejb.context", true);

        final InitialContext context = new InitialContext(jndiProperties);

        final String appName = "";

        final String moduleName = "jboss-as-ejb-remote-app";

        final String distinctName = "";

        final String beanName = CalculatorBean.class.getSimpleName();

        final String viewClassName = RemoteCalculator.class.getName();


        return (RemoteCalculator) context.lookup("ejb:" + appName + "/" + moduleName + "/" + distinctName + "/" + beanName + "!" + viewClassName);

    }

}

And then I also add a jboss-ejb-client.properties file to the src/ folder of the project, which look like:

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

remote.connections=default

remote.connection.default.host=localhost
remote.connection.default.port = 8082
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

I did quite exactly the same as the tutorial but I still get the error:

Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:jboss-as-ejb-remote-app, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@4d41cee
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:128)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
    at com.sun.proxy.$Proxy0.add(Unknown Source)
    at ejb.remote.client.RemoteEJBClient.invokeStatelessBean(RemoteEJBClient.java:36)
    at ejb.remote.client.RemoteEJBClient.main(RemoteEJBClient.java:20)

Can anyone help me to solve this problem? Thanks!

1

1 Answers

0
votes

The code is okay. As mentioned in the tutorial, you have to make sure that jboss-ejb-client.properties file is on really classpath. Then it should works! (I was even able to reproduce your issue with same stacktrace by moving jboss-ejb-client.properties out of classpath)

Tip: It's quite convention (especially for maven projects) to put these files under src/main/resources.

For more info see github.com/wildfly/quickstart/ejb-remote, which is same project as in tutorial.