简体   繁体   中英

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.

I have see this , this , this , this and many other posts but still it does not work.

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".

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:

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:

<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:

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" :

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:

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:

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. Unfortunatelly I cannot use a script to setup a User so I have to type it directly into the 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))?

ok, thanks to @Federico Sierra comments I could solve the problem

the first issue was with the remote port, 8080 needed to be used instead of 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. the format must be: username=HEX( MD5( username ':' ApplicationRealm ':' password))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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