再次从远程客户端调用EJB

时间:2017-04-21 09:49:55

标签: java-ee ejb wildfly-10

我从几天开始尝试通过客户端访问远程Wildfly 10.x服务器上的EJB,但我无法使其工作。

我看到了thisthisthisthis以及其他许多帖子,但仍然无效。

根据上述帖子中的建议,我有两个Java代码版本,无法注册EJB"或"无法连接到服务器"。

问题可能出在服务器配置上,但我不是专家。

我真的很感激任何帮助。

我在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);
    }

此版本抛出错误&#34;无法注册EJB接收器&#34;

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

此版本引发错误&#34;无法连接到任何服务器&#34;

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上的用户配置有关。不幸的是,我无法使用脚本来设置用户,所以我必须直接在application-users.properties中输入。

假设我想设置Username = MyUser和Password = MyUser,条目看起来像username = HEX(MD5(MyUser&#39;:&#39; realm&#39;:&#39; MyUser) )?

1 个答案:

答案 0 :(得分:0)

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

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

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

我的服务器是远程的,我无法运行add-user.sh脚本,因此我选择直接在application-user.properties文件中添加用户。 格式必须是:username = HEX(MD5(用户名&#39;:&#39; ApplicationRealm&#39;:&#39;密码))