再次从远程客户端调用 EJB

EJB invocation from a remote client again

几天以来我一直在尝试通过客户端访问远程 Wildfly 10.x 服务器上的 EJB,但我无法让它工作。

我看过 , this, , this 和许多其他帖子,但仍然不起作用。

根据上述帖子中的建议,我有两个 Java 代码版本抛出 "could not register EJB" 或 "Fail to connect to server"。

也许问题出在服务器配置上,但我不是这方面的专家。

非常感谢任何帮助。

我在 WildFly 10.1 远程服务器上部署了 EJB:

java:global/Remote/EJB-Remote-Demo-ejb-1.0/CalculatorBean!com.maggioni.Stateless2.RemoteCalculator
java:app/EJB-Remote-Demo-ejb-1.0/CalculatorBean!com.maggioni.Stateless2.RemoteCalculator
java:module/CalculatorBean!com.maggioni.Stateless2.RemoteCalculator
java:jboss/exported/Remote/EJB-Remote-Demo-ejb-1.0/CalculatorBean!com.maggioni.Stateless2.RemoteCalculator
java:global/Remote/EJB-Remote-Demo-ejb-1.0/CalculatorBean
java:app/EJB-Remote-Demo-ejb-1.0/CalculatorBean
java:module/CalculatorBean

服务器配置:

<subsystem xmlns="urn:jboss:domain:remoting:3.0">
         <endpoint/>
         <http-connector name="http-remoting-connector" connector-ref="default" security-realm="ApplicationRealm"/>
 </subsystem>

pom 配置:

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

         </dependency>

我现在有两个版本的代码。

版本 1:

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 Context context = new InitialContext(jndiProperties);            
        String appName = "Remote/"
        String moduleName = "EJB-Remote-Demo-ejb-1.0/";
        String beanName = CalculatorBean.class.getSimpleName();
        String viewClassName = RemoteCalculator.class.getName();
        final String jndiname = "ejb:" + appName + moduleName + "/" + beanName + "!" + viewClassName;
        System.out.println("jndiname is : " + jndiname);
        return (RemoteCalculator) context.lookup(jndiname);
    }

此版本抛出错误 "Could not register a EJB receiver":

Apr 21, 2017 10:44:47 AM org.jboss.ejb.client.remoting.ConfigBasedEJBClientContextSelector setupEJBReceivers
WARN: Could not register a EJB receiver for connection to <myEnvironmentNumber>.jelastic.dogado.eu:4447
java.net.ConnectException: Connection refused: no further information
    ........
Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:Remote, moduleName:EJB-Remote-Demo-ejb-1.0, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@6ebc05a6
    at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:798)

版本 2:

private static RemoteCalculator lookupRemoteStatelessCalculator() throws NamingException {
        Properties jndiProperties = new Properties();
        jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
        jndiProperties.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
        jndiProperties.put(javax.naming.Context.PROVIDER_URL, "http-remoting://<myEnvironmentNumber>.jelastic.dogado.eu:4447");
        jndiProperties.put(javax.naming.Context.SECURITY_PRINCIPAL, "app");
        jndiProperties.put(javax.naming.Context.SECURITY_CREDENTIALS, "app");
        jndiProperties.put("jboss.naming.client.ejb.context", true);
        final Context context = new InitialContext(jndiProperties);
        String appName = "Remote/";
        String moduleName = "EJB-Remote-Demo-ejb-1.0/";
        String beanName = CalculatorBean.class.getSimpleName();
        String viewClassName = RemoteCalculator.class.getName();
        final String jndiname = appName + moduleName + beanName + "!" + viewClassName;
        System.out.println("jndiname is : " + jndiname);
        return (RemoteCalculator) context.lookup(jndiname);
    }

此版本抛出错误 "Fail to connect to any server":

Apr 21, 2017 9:42:10 AM org.xnio.Xnio <clinit>
INFO: XNIO version 3.4.0.Final
Apr 21, 2017 9:42:10 AM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.4.0.Final
Apr 21, 2017 9:42:11 AM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 4.0.21.Final
jndiname is : Remote/EJB-Remote-Demo-ejb-1.0/CalculatorBean!com.maggioni.Stateless2.RemoteCalculator
Exception in thread "main" javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [http-remoting://<myEnvironmentNumber>.jelastic.dogado.eu:4447 (java.net.ConnectException: Connection refused: no further information)]

对于两个版本,jboss-ejb-client.properties 看起来像:

remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED=false
remote.connections=default
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS=false
remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT=false

remote.connection.default.host=<myEnvironmentNumber>.jelastic.dogado.eu
remote.connection.default.port = 4447
remote.connection.default.username=app
remote.connection.default.password=app

编辑:

我猜想问题可能与 WildFly 上的用户配置有关。不幸的是,我无法使用脚本来设置用户,所以我必须将其直接输入到应用程序中-users.properties.

假设我想设置一个 Username=MyUser 和 Password=MyUser 条目应该看起来像 username=HEX( MD5( MyUser ':' realm ':' MyUser))?

好的,感谢@Federico Sierra 的评论我可以解决问题

第一个问题是远程端口,需要使用 8080 而不是 4447

第二个问题是应用程序用户没有在服务器端正确设置。

我的服务器是远程的,我无法运行 add-user.sh脚本,所以我选择直接在application-user.properties文件中添加用户。 格式必须是:username=HEX(MD5(username':'ApplicationRealm':'password))