远程 JMS 通信正常,EJB 通信失败
Remote JMS communication works, EJB communication fails
我目前正在介绍 Java EE,尤其是如何使用 EJB 和 JMS。
问题简述
我在互联网上有一个本地客户端和一个远程服务器。 JMS 通信工作正常,EJB 通信不行。在我的本地网络中通信成功。
更详细的问题
我正在使用 Maven 构建:
- 一个包含几个无状态远程 EJB 和一个 MDB 的 EAR
- 一个桌面客户端,包括由 Maven 生成的用于与服务器通信的 EJB 客户端 JAR。
我正在使用 WildFly 应用程序服务器来部署 EAR。根据服务器日志,EJB 已成功导出。所有流量均基于 http-remoting
。 Undertow 根据需要根据嗅探流量切换协议。
我们以客户端登录为例。登录API调用基于远程EJB通信,同时发送JMS消息。
如果我从 Eclipse 运行 本地计算机上的客户端和服务器,登录工作正常并且 JMS 消息被正确处理。如果我 运行 同一网络中不同机器上的客户端,同样适用。如果我 运行 我的本地网络中的客户端,但互联网中的服务器,EJB 通信失败并且 JMS 消息仍能正确处理。
这是为什么?
日志内容
没有调用远程EJB 的登录方法,没有日志。我已将 log4j.logger.org.jboss.ejb.client=TRACE
添加到 log4j.properties
。那是客户端在 API 调用失败时的日志:
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - endpoint.create.options. has the following options {}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {} have been merged with defaults {org.xnio.Options.THREAD_DAEMON=>true} to form {org.xnio.Options.THREAD_DAEMON=>true}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connectionprovider.create.options. has the following options {org.xnio.Options.SSL_ENABLED=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {org.xnio.Options.SSL_ENABLED=>false} have been merged with defaults {} to form {org.xnio.Options.SSL_ENABLED=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connection.default.connect.options. has the following options {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false} have been merged with defaults {} to form {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connection.default.channel.options. has the following options {}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:490 - Connection org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration$RemotingConnectionConfigurationImpl@33f49f38 successfully created for connection named default
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:295 - No clusters configured in properties
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG EJBClientPropertiesLoader:100 - Looking for jboss-ejb-client.properties using classloader sun.misc.Launcher$AppClassLoader@58644d46
2015-06-21 16:47:49 [GS Desktop Init Thread] INFO client:45 - JBoss EJB Client version 2.1.1.Final
...
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-4] DEBUG RemotingConnectionEJBReceiver:191 - Channel Channel ID eb5d763d (outbound) of Remoting connection 25bff644 to euve1234.vserver.de/84.46.96.86:8080 opened for context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]} Waiting for version handshake message from server
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-5] INFO remoting:103 - EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
2015-06-21 16:47:51 [GS Desktop Thread 0] INFO remoting:218 - EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]} on channel Channel ID eb5d763d (outbound) of Remoting connection 25bff644 to euve1234.vserver.de/84.46.96.86:8080
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] TRACE ChannelAssociation:375 - Received message with header 0x8
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:763 - Received module availability report for 11 modules
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSAuthManagerEjb-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSNotificationManagerEjb-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
...
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSServerEAR-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
2015-06-21 16:47:51 [GS Desktop Thread 0] DEBUG ConfigBasedEJBClientContextSelector:174 - Registered 1 remoting EJB receivers for EJB client context org.jboss.ejb.client.EJBClientContext@3baeae68
...
2015-06-21 16:47:51 [JavaFX Application Thread] WARN GsTask:38 - API call background task failed
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:GSServerEAR, moduleName:GSAuthManagerEjb-0.0.1, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@63dd58c4
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:774)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
at com.sun.proxy.$Proxy7.createSession(Unknown Source)
...
我的一些想法
问题可能是由
引起的
- IP 无效?
- 没有。移动服务器后,我更新了
standalone.xml
配置,并通过观察所有机器上的网络流量确保收到所有呼叫。 JMS 有效。
- WildFly 安全设置,例如关于安全领域配置?
- 没有。登录在本地工作。这些设置在移动服务器后应该有效。 JMS 和 EJB 使用相同的 WildFly 应用程序用户。 JMS 有效。
- 可能是 networking/routing 问题,因为 EJB 基于 RMI,还是某种防火墙问题?
- 可能,但 JMS 有效。我还没有真正习惯 JMS,但它不是基于 RMI 的吗?我发送
javax.jms.ObjectMessage
s。 Session.createObjectMessage(Serializable object)
需要一个 Serializable
,这就是为什么我建议我们在这里也有 RMI。
- 本地,WildFly 运行s on Windows 7. 远程,Wildfly 运行s on Ubuntu。为此,我尝试了 Ubuntu 10/12/14。
- 关于 Java 和 WildFly:它们与平台无关。写一次,到处都是运行。我建议问题是由底层OS引起的可能性很小。我已验证流量和 JMS 正常工作。
如有错误请指正
补充说明
- 我知道这么久以来我提供的信息很少,因为我不想夸大我的问题。如果您需要更多信息,请随时询问。这也适用于代码。
- 我正在使用 Java SE 8 / Java EE 7。关于 WildFly:我测试了 8.1.0.Final、8.2.0.Final 和 9.0。 0.Beta2.
- 请不要简单的参考网上的例子。我已经为此工作好几天了,请记住 local 通信已经正常工作了。
我非常感谢任何关于此的想法和评论,因为我真的被困住了。非常感谢。
更新 1:EJB 实现、客户端上下文创建和 EJB 查找
服务器:
@Remote
public interface GsAuthManager {
GsClientSession createSession(String username, String password);
}
@Stateless
public class GsAuthManagerBean implements GsAuthManager {
@Override
public GsClientSession createSession(String username, String password) {
// ...
}
}
WildFly 日志:
java:jboss/exported/GSServerEAR/GSAuthManagerEjb-0.0.1/GsAuthManagerBean!de.genesys.server.ejb.auth.GsAuthManager
客户:
static void initEjbClient(String serverHostname, String username, String password) {
final Properties ejbClientProps = new Properties();
ejbClientProps.put("remote.connections", "default");
ejbClientProps.put("remote.connection.default.port", "8080");
ejbClientProps.put("remote.connection.default.host", serverHostname);
ejbClientProps.put("remote.connection.default.username", username);
ejbClientProps.put("remote.connection.default.password", password);
ejbClientProps.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
ejbClientProps.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
ejbClientProps.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
EJBClientConfiguration clientConfig = new PropertiesBasedEJBClientConfiguration(ejbClientProps);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(clientConfig);
EJBClientContext.setSelector(selector);
}
static GsAuthManager initEjbProxy(String serverHostname, String username, String password) throws NamingException{
Properties props = new Properties();
props.put("jboss.naming.client.ejb.context", true);
props.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "http-remoting://" + serverHostname + ":8080");
props.put(Context.SECURITY_PRINCIPAL, username);
props.put(Context.SECURITY_CREDENTIALS, password);
InitialContext context = new InitialContext(props); // Stripped down, original code keeps a strong reference and closes context on program termination
return (GsAuthManager) context.lookup("ejb:GSServerEAR/GSAuthManagerEjb-0.0.1/GsAuthManagerBean!de.genesys.server.ejb.auth.GsAuthManager");
}
在部署 appName='GSServerEAR-0.0.1'
的日志中,但发生异常时:appName:GSServerEAR
。所以我想,你的 EAR 文件的运行时(当你部署它时)包含版本,它不应该。
我目前正在介绍 Java EE,尤其是如何使用 EJB 和 JMS。
问题简述
我在互联网上有一个本地客户端和一个远程服务器。 JMS 通信工作正常,EJB 通信不行。在我的本地网络中通信成功。
更详细的问题
我正在使用 Maven 构建:
- 一个包含几个无状态远程 EJB 和一个 MDB 的 EAR
- 一个桌面客户端,包括由 Maven 生成的用于与服务器通信的 EJB 客户端 JAR。
我正在使用 WildFly 应用程序服务器来部署 EAR。根据服务器日志,EJB 已成功导出。所有流量均基于 http-remoting
。 Undertow 根据需要根据嗅探流量切换协议。
我们以客户端登录为例。登录API调用基于远程EJB通信,同时发送JMS消息。
如果我从 Eclipse 运行 本地计算机上的客户端和服务器,登录工作正常并且 JMS 消息被正确处理。如果我 运行 同一网络中不同机器上的客户端,同样适用。如果我 运行 我的本地网络中的客户端,但互联网中的服务器,EJB 通信失败并且 JMS 消息仍能正确处理。
这是为什么?
日志内容
没有调用远程EJB 的登录方法,没有日志。我已将 log4j.logger.org.jboss.ejb.client=TRACE
添加到 log4j.properties
。那是客户端在 API 调用失败时的日志:
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - endpoint.create.options. has the following options {}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {} have been merged with defaults {org.xnio.Options.THREAD_DAEMON=>true} to form {org.xnio.Options.THREAD_DAEMON=>true}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connectionprovider.create.options. has the following options {org.xnio.Options.SSL_ENABLED=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {org.xnio.Options.SSL_ENABLED=>false} have been merged with defaults {} to form {org.xnio.Options.SSL_ENABLED=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connection.default.connect.options. has the following options {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] TRACE PropertiesBasedEJBClientConfiguration:272 - Options {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false} have been merged with defaults {} to form {org.xnio.Options.SASL_DISALLOWED_MECHANISMS=>[JBOSS-LOCAL-USER],org.xnio.Options.SASL_POLICY_NOANONYMOUS=>false}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:242 - remote.connection.default.channel.options. has the following options {}
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:490 - Connection org.jboss.ejb.client.PropertiesBasedEJBClientConfiguration$RemotingConnectionConfigurationImpl@33f49f38 successfully created for connection named default
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG PropertiesBasedEJBClientConfiguration:295 - No clusters configured in properties
2015-06-21 16:47:49 [GS Desktop Init Thread] DEBUG EJBClientPropertiesLoader:100 - Looking for jboss-ejb-client.properties using classloader sun.misc.Launcher$AppClassLoader@58644d46
2015-06-21 16:47:49 [GS Desktop Init Thread] INFO client:45 - JBoss EJB Client version 2.1.1.Final
...
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-4] DEBUG RemotingConnectionEJBReceiver:191 - Channel Channel ID eb5d763d (outbound) of Remoting connection 25bff644 to euve1234.vserver.de/84.46.96.86:8080 opened for context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]} Waiting for version handshake message from server
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-5] INFO remoting:103 - EJBCLIENT000017: Received server version 2 and marshalling strategies [river]
2015-06-21 16:47:51 [GS Desktop Thread 0] INFO remoting:218 - EJBCLIENT000013: Successful version handshake completed for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]} on channel Channel ID eb5d763d (outbound) of Remoting connection 25bff644 to euve1234.vserver.de/84.46.96.86:8080
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] TRACE ChannelAssociation:375 - Received message with header 0x8
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:763 - Received module availability report for 11 modules
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSAuthManagerEjb-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSNotificationManagerEjb-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
...
2015-06-21 16:47:51 [Remoting "config-based-ejb-client-endpoint" task-6] DEBUG RemotingConnectionEJBReceiver:765 - Registering module EJBModuleIdentifier{appName='GSServerEAR-0.0.1', moduleName='GSServerEAR-0.0.1', distinctName=''} availability for receiver context EJBReceiverContext{clientContext=org.jboss.ejb.client.EJBClientContext@3baeae68, receiver=Remoting connection EJB receiver [connection=org.jboss.ejb.client.remoting.ConnectionPool$PooledConnection@3f310404,channel=jboss.ejb,nodename=euve1234]}
2015-06-21 16:47:51 [GS Desktop Thread 0] DEBUG ConfigBasedEJBClientContextSelector:174 - Registered 1 remoting EJB receivers for EJB client context org.jboss.ejb.client.EJBClientContext@3baeae68
...
2015-06-21 16:47:51 [JavaFX Application Thread] WARN GsTask:38 - API call background task failed
java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:GSServerEAR, moduleName:GSAuthManagerEjb-0.0.1, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@63dd58c4
at org.jboss.ejb.client.EJBClientContext.requireEJBReceiver(EJBClientContext.java:774)
at org.jboss.ejb.client.ReceiverInterceptor.handleInvocation(ReceiverInterceptor.java:116)
at org.jboss.ejb.client.EJBClientInvocationContext.sendRequest(EJBClientInvocationContext.java:186)
at org.jboss.ejb.client.EJBInvocationHandler.sendRequestWithPossibleRetries(EJBInvocationHandler.java:255)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:200)
at org.jboss.ejb.client.EJBInvocationHandler.doInvoke(EJBInvocationHandler.java:183)
at org.jboss.ejb.client.EJBInvocationHandler.invoke(EJBInvocationHandler.java:146)
at com.sun.proxy.$Proxy7.createSession(Unknown Source)
...
我的一些想法
问题可能是由
引起的- IP 无效?
- 没有。移动服务器后,我更新了
standalone.xml
配置,并通过观察所有机器上的网络流量确保收到所有呼叫。 JMS 有效。
- 没有。移动服务器后,我更新了
- WildFly 安全设置,例如关于安全领域配置?
- 没有。登录在本地工作。这些设置在移动服务器后应该有效。 JMS 和 EJB 使用相同的 WildFly 应用程序用户。 JMS 有效。
- 可能是 networking/routing 问题,因为 EJB 基于 RMI,还是某种防火墙问题?
- 可能,但 JMS 有效。我还没有真正习惯 JMS,但它不是基于 RMI 的吗?我发送
javax.jms.ObjectMessage
s。Session.createObjectMessage(Serializable object)
需要一个Serializable
,这就是为什么我建议我们在这里也有 RMI。
- 可能,但 JMS 有效。我还没有真正习惯 JMS,但它不是基于 RMI 的吗?我发送
- 本地,WildFly 运行s on Windows 7. 远程,Wildfly 运行s on Ubuntu。为此,我尝试了 Ubuntu 10/12/14。
- 关于 Java 和 WildFly:它们与平台无关。写一次,到处都是运行。我建议问题是由底层OS引起的可能性很小。我已验证流量和 JMS 正常工作。
如有错误请指正
补充说明
- 我知道这么久以来我提供的信息很少,因为我不想夸大我的问题。如果您需要更多信息,请随时询问。这也适用于代码。
- 我正在使用 Java SE 8 / Java EE 7。关于 WildFly:我测试了 8.1.0.Final、8.2.0.Final 和 9.0。 0.Beta2.
- 请不要简单的参考网上的例子。我已经为此工作好几天了,请记住 local 通信已经正常工作了。
我非常感谢任何关于此的想法和评论,因为我真的被困住了。非常感谢。
更新 1:EJB 实现、客户端上下文创建和 EJB 查找
服务器:
@Remote
public interface GsAuthManager {
GsClientSession createSession(String username, String password);
}
@Stateless
public class GsAuthManagerBean implements GsAuthManager {
@Override
public GsClientSession createSession(String username, String password) {
// ...
}
}
WildFly 日志:
java:jboss/exported/GSServerEAR/GSAuthManagerEjb-0.0.1/GsAuthManagerBean!de.genesys.server.ejb.auth.GsAuthManager
客户:
static void initEjbClient(String serverHostname, String username, String password) {
final Properties ejbClientProps = new Properties();
ejbClientProps.put("remote.connections", "default");
ejbClientProps.put("remote.connection.default.port", "8080");
ejbClientProps.put("remote.connection.default.host", serverHostname);
ejbClientProps.put("remote.connection.default.username", username);
ejbClientProps.put("remote.connection.default.password", password);
ejbClientProps.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
ejbClientProps.put("remote.connection.default.connect.options.org.xnio.Options.SASL_DISALLOWED_MECHANISMS", "JBOSS-LOCAL-USER");
ejbClientProps.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
EJBClientConfiguration clientConfig = new PropertiesBasedEJBClientConfiguration(ejbClientProps);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(clientConfig);
EJBClientContext.setSelector(selector);
}
static GsAuthManager initEjbProxy(String serverHostname, String username, String password) throws NamingException{
Properties props = new Properties();
props.put("jboss.naming.client.ejb.context", true);
props.put("jboss.naming.client.connect.options.org.xnio.Options.SASL_POLICY_NOPLAINTEXT", "false");
props.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
props.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
props.put(Context.PROVIDER_URL, "http-remoting://" + serverHostname + ":8080");
props.put(Context.SECURITY_PRINCIPAL, username);
props.put(Context.SECURITY_CREDENTIALS, password);
InitialContext context = new InitialContext(props); // Stripped down, original code keeps a strong reference and closes context on program termination
return (GsAuthManager) context.lookup("ejb:GSServerEAR/GSAuthManagerEjb-0.0.1/GsAuthManagerBean!de.genesys.server.ejb.auth.GsAuthManager");
}
在部署 appName='GSServerEAR-0.0.1'
的日志中,但发生异常时:appName:GSServerEAR
。所以我想,你的 EAR 文件的运行时(当你部署它时)包含版本,它不应该。