0
votes

I created following EJB-Module:
1) My Remote interface

package calculator.beans;
import javax.ejb.Remote;

@Remote
public interface CalculatorRemote {
    public int addNum(int num1, int num2);
}


2) A bean which implements the interface

package calculator.beans;
import javax.ejb.Stateless;

@Stateless
public class CalculatorBean implements CalculatorRemote {

    @Override
    public int addNum(int num1, int num2) {
        return num1 + num2;
    }
}


3) Next I created a property-file '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=127.0.0.1
remote.connection.default.port = 8080
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false

remote.connection.default.username=appuser
remote.connection.default.password=apppassword


After the deployment to wildfly everything was fine. I get following Information:

INFO  [org.jboss.as.ejb3.deployment] (MSC service thread 1-4) WFLYEJB0473: JNDI bindings for session bean named 'CalculatorBean' in deployment unit 'deployment "CalculatorEJB.jar"' are as follows:

    java:global/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
    java:app/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
    java:module/CalculatorBean!calculator.beans.CalculatorRemote
    java:jboss/exported/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote
    java:global/CalculatorEJB/CalculatorBean
    java:app/CalculatorEJB/CalculatorBean
    java:module/CalculatorBean

4) Then I created my Java Client

package calculator.client;

import java.util.Hashtable;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import calculator.beans.CalculatorRemote;

public class RemoteRechnerClient {

    public static void main(String[] args) {
        try {
            final Hashtable<String, String> jndiProperties = new Hashtable<>();
            jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
            final Context ctx = new InitialContext(jndiProperties);
            String crName = CalculatorRemote.class.getName();
            CalculatorRemote cr = (CalculatorRemote) ctx.lookup("ejb:CalculatorEJB/beans/CalculatorBean!" + crName);

            System.out.println("Result: " + cr.addNum(5, 4));

        } catch (NamingException ex) {
            ex.printStackTrace();
        }
    }
}

The code is simple enough. But if I run the Client I get following Error-Message:

Apr 06, 2017 3:30:26 PM org.jboss.ejb.client.EJBClient <clinit>
INFO: JBoss EJB Client version 2.0.1.Final
Apr 06, 2017 3:30:26 PM org.xnio.Xnio <clinit>
INFO: XNIO version 3.3.0.Final
Apr 06, 2017 3:30:26 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.3.0.Final
Apr 06, 2017 3:30:26 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.6.Final
Apr 06, 2017 3:30:27 PM org.jboss.ejb.client.remoting.VersionReceiver handleMessage
INFO: EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
Apr 06, 2017 3:30:27 PM org.jboss.ejb.client.remoting.RemotingConnectionEJBReceiver associate
INFO: EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3c0f93f1, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@31dc339b,channel=jboss.ejb,nodename=john-waynes-macbook-pro]} on channel Channel ID b98547a5 (outbound) of Remoting connection 0c84e8ba to /127.0.0.1:8080
Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:CalculatorEJB, moduleName:beans, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@2758fe70
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:749)
    at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
    at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
    at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:253)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:198)
    at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:181)
    at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:144)
    at com.sun.proxy.$Proxy0.addNum(Unknown Source)
    at calculator.client.RemoteRechnerClient.main(RemoteRechnerClient.java:27)
/Users/manhthangd/Library/Caches/NetBeans/8.2/executor-snippets/run.xml:53: Java returned: 1
BUILD FAILED (total time: 3 seconds)

I am using Netbeans 8.2, Java EE 7 and Wildfly 10.1.0-Final. What can I do to solve the problem?

1

1 Answers

0
votes

Your JNDI lookup name is incorrect.

You need to use the highlighted portion of:

java:jboss/exported/CalculatorEJB/CalculatorBean!calculator.beans.CalculatorRemote

ie.

CalculatorRemote cr = (CalculatorRemote) ctx.lookup("ejb:CalculatorEJB/CalculatorBean!" + crName);

Where did you get "ejb:CalculatorEJB/beans/CalculatorBean!" from?