Lookup of stateful session bean from second application in same Wildfly instance
ckoelle Jul 3, 2018 4:17 AMHi
I have a problem with calling a stateful session bean remotely from another application deployed in the same Wildfly (12.0.0.Final) instance.
The first application (backend application) contains the stateful bean:
package ch.nic.reg.backend;
import javax.ejb.Stateful;
import ch.nic.reg.common.BackendRemote;
@Stateful
public class EPPBackendBean implements EPPBackendRemote {
public String getSessionId() throws Exception {
return "NewSessionId123";
}
}
The bean is inside an ejb-jar and packed in an ear. The ear deploys fine in the server:
08:43:14,778 INFO [org.jboss.as.ejb3.deployment] (MSC service thread 1-5) WFLYEJB0473: JNDI bindings for session bean named 'BackendBean' in deployment unit 'subdeployment "backend.jar" of deployment "backend.ear"' are as follows:
java:global/backend/backend/BackendBean!ch.nic.reg.common.BackendRemote
java:app/backend/BackendBean!ch.nic.reg.common.BackendRemote
java:module/BackendBean!ch.nic.reg.common.BackendRemote
java:jboss/exported/backend/backend/BackendBean!ch.nic.reg.common.BackendRemote
java:global/backend/backend/BackendBean
java:app/backend/BackendBean
java:module/BackendBean
The second application (frontend application) has a singleton bean which calls the backend bean:
@Singleton
@Startup
public class Frontend {
@PostConstruct
public void start() {
InitialContext context = null;
Backend remote = null;
try {
Map<String, String> environment = new Hashtable<>();
environment.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
environment.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");
context = new InitialContext((Hashtable<String, String>) environment);
remote = (BackendRemote) context.lookup("ejb:backend/backend/BackendBean!ch.nic.reg.common.BackendRemote?stateful");
} catch (Exception e) {
e.printStackTrace();
}
}
}
In order to ensure that the backend is deployed before the singleton bean starts we have a dependency between the two deploments defined in jboss-all.xml in frontend ear:
<jboss umlns="urn:jboss:1.0">
<jboss-deployment-dependencies xmlns="urn:jboss:deployment-dependencies:1.0">
<dependency name="reg-epp-backend-client.ear" />
</jboss-deployment-dependencies>
</jboss>
Additionaly the frontend ear has also a wildfly-config.xml:
<configuration>
<authentication-client xmlns="urn:elytron:1.0">
<authentication-rules>
<rule use-configuration="default" />
</authentication-rules>
<authentication-configurations>
<configuration name="default">
<sasl-mechanism-selector selector="#ALL" />
<set-mechanism-properties>
<property key="wildfly.sasl.local-user.quiet-auth" value="true" />
</set-mechanism-properties>
<providers>
<use-service-loader/>
</providers>
</configuration>
</authentication-configurations>
</authentication-client>
</configuration>
Here's the error message:
08:43:19,915 ERROR [stderr] (ServerService Thread Pool -- 75) javax.naming.CommunicationException: EJBCLIENT000062: Failed to look up "backend/backend/BackendBean!ch.nic.reg.common.BackendRemote?stateful" [Root exception is org.jboss.ejb.client.RequestSendFailedException: EJBCLIENT000409: No more destinations are available]
08:43:19,916 ERROR [stderr] (ServerService Thread Pool -- 75) at org.jboss.ejb.client.EJBRootContext.lookupNative(EJBRootContext.java:160)
....
08:43:19,925 ERROR [stderr] (ServerService Thread Pool -- 75) Caused by: org.jboss.ejb.client.RequestSendFailedException: EJBCLIENT000409: No more destinations are available
08:43:19,925 ERROR [stderr] (ServerService Thread Pool -- 75) at org.jboss.ejb.client.NamingEJBClientInterceptor.handleSessionCreation(NamingEJBClientInterceptor.java:100)
If i try to lookup the backend bean from a standalone EJB client with the exact same lookup code it works perfectly.
Any ideas what's the difference?
Christian