我已经生成了两个简单的野蝇群项目。首先具有带有远程接口的 EJB 外观,其次应该查找它并发送消息。所以第二个应该是客户。
我用的是Wildfly swarm 2017.9.4版
我的 EJB 外观查找路径:
java:global/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
java:app/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
java:module/PingFacade!io.project.core.interfaces.PingFacadeRemote
java:jboss/exported/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote
java:global/ejb-one/PingFacade
java:app/ejb-one/PingFacade
java:module/PingFacade
我的客户 :
public static void main(String[] args) {
BackendConnectionManager manager = new BackendConnectionManager();
try {
manager.getPingFacadeRemote().savePingMessage("halloooooo");
} catch (NamingException ex) {
Logger.getLogger(BackendConnectionManager.class.getName()).log(Level.SEVERE, null, ex);
}
}
public PingFacadeRemote getPingFacadeRemote() throws NamingException {
final Hashtable jndiProperties = new Hashtable();
jndiProperties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
jndiProperties.put(Context.PROVIDER_URL,"http-remoting://localhost:8080");
//jndiProperties.put(Context.PROVIDER_URL,"http://localhost:8080");
final Context context = new InitialContext(jndiProperties);
return (PingFacadeRemote) context
.lookup("java:global/ejb-one/PingFacade!io.project.core.interfaces.PingFacadeRemote");
}
将客户端依赖项添加到 pom.xml
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>ejb-remote</artifactId>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-naming</artifactId>
</dependency>
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-ejb-client</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-api</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.remoting3</groupId>
<artifactId>jboss-remoting</artifactId>
<version>3.3.3.Final</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.sasl</groupId>
<artifactId>jboss-sasl</artifactId>
<scope>runtime</scope>
<version>1.0.5.Final</version>
</dependency>
<dependency>
<groupId>org.jboss.marshalling</groupId>
<artifactId>jboss-marshalling-river</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.transaction</groupId>
<artifactId>jboss-transaction-api_1.2_spec</artifactId>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.jms</groupId>
<artifactId>jboss-jms-api_2.0_spec</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.spec.javax.ejb</groupId>
<artifactId>jboss-ejb-api_3.2_spec</artifactId>
<scope>runtime</scope>
</dependency>
我不知道客户的全部依赖关系并且总是有
javax.naming.CommunicationException: WFNAM00018: Failed to connect to remote host [Root exception is org.jboss.remoting3.ServiceOpenException: Unknown service name]
at org.wildfly.naming.client.remote.RemoteContext.getRemoteTransport(RemoteContext.java:80)
at org.wildfly.naming.client.remote.RemoteContext.lambda$lookupNative$0(RemoteContext.java:106)
at org.wildfly.naming.client.NamingProvider.performExceptionAction(NamingProvider.java:150)
at org.wildfly.naming.client.remote.RemoteContext.lookupNative(RemoteContext.java:104)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:74)
at org.wildfly.naming.client.AbstractFederatingContext.lookup(AbstractFederatingContext.java:60)
at org.wildfly.naming.client.WildFlyRootContext.lookup(WildFlyRootContext.java:150)
at javax.naming.InitialContext.lookup(InitialContext.java:417)
at io.project.ejbtwo.rest.BackendConnectionManager.getPingFacadeRemote(BackendConnectionManager.java:57)
at io.project.ejbtwo.rest.BackendConnectionManager.main(BackendConnectionManager.java:43)
Caused by: org.jboss.remoting3.ServiceOpenException: Unknown service name
另外如何解决在客户端查找中传递安全凭据的问题?
项目本身在这里
https://drive.google.com/open?id=0B45Md1_c5-gGQ0p3Q2pURUxOY00