简体   繁体   English

再次从远程客户端调用EJB

[英]EJB invocation from a remote client again

I'm trying since days to access EJBs on a remote Wildfly 10.x server through a client but I cannot make it work. 自几天以来,我一直在尝试通过客户端访问远程Wildfly 10.x服务器上的EJB,但是我无法使其正常工作。

I have see this , this , this , this and many other posts but still it does not work. 我已经看到了thisthisthisthis和许多其他帖子,但仍然无法正常工作。

Following the suggestions in the above posts I have two Java code versions throwing either "could not register EJB" or "Fail to connect to server". 按照上述文章中的建议,我有两个Java代码版本抛出“无法注册EJB”或“无法连接到服务器”。

Maybe the problem is with the server configuration but I'm not the expert here. 也许问题出在服务器配置上,但我不是这里的专家。

I would really appreciate any help. 我真的很感谢您的帮助。

I deployed EJBs on WildFly 10.1 remote 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

the server configuration: 服务器配置:

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

the pom configuration: pom配置:

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

         </dependency>

I have now two versions of my code. 我现在有两个版本的代码。

Version 1: 版本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);
    }

this version is throwing the error "Could not register a EJB receiver" : 此版本引发错误“无法注册EJB接收器”

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)

Version 2: 版本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);
    }

this version is throwing the error "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)]

for both versions the jboss-ejb-client.properties is looking like: 对于这两个版本, 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

EDIT: 编辑:

I guess that the problem maybe with the User Configuration on WildFly. 我想可能是WildFly上的用户配置有问题。 Unfortunatelly I cannot use a script to setup a User so I have to type it directly into the application-users.properties. 不幸的是,我无法使用脚本来设置用户,因此必须直接将其键入到application-users.properties中。

Supposing I want to Setup a Username=MyUser and a Password=MyUser should the entry looking like username=HEX( MD5( MyUser ':' realm ':' MyUser))? 假设我要设置一个Username = MyUser和一个Password = MyUser,条目应该像username = HEX(MD5(MyUser':'realm':'MyUser))一样吗?

ok, thanks to @Federico Sierra comments I could solve the problem 好的,感谢@Federico Sierra的评论,我可以解决问题

the first issue was with the remote port, 8080 needed to be used instead of 4447 第一个问题是远程端口,需要使用8080而不是4447

the second issue was with the application user not been correctly setup on the server side. 第二个问题是应用程序用户未在服务器端正确设置。

my server is remote and I could not run the add-user.sh script, so I choose to add the user directly in the application-user.properties file. 我的服务器是远程服务器,无法运行add-user.sh脚本,因此我选择直接在application-user.properties文件中添加用户。 the format must be: username=HEX( MD5( username ':' ApplicationRealm ':' password)) 格式必须为:username = HEX(MD5(username':'ApplicationRealm':'password))

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM