首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >远程JMS通信工作,EJB通信失败。

远程JMS通信工作,EJB通信失败。
EN

Stack Overflow用户
提问于 2015-06-21 15:56:01
回答 1查看 991关注 0票数 0

我目前正在介绍Java,特别是如何使用EJB和JMS。

简单地说,这个问题

我在互联网上有一个本地客户端和一个远程服务器。JMS通信工作正常,EJB通信不起作用,这两种通信都在本地网络中成功。

更详细的问题

我正在使用Maven构建:

  • 包含两个无状态远程EJB和一个MDB的EAR
  • 一个桌面客户端,它包含由Maven生成的EJB客户机JAR,用于与服务器进行通信。

我正在使用WildFly应用服务器来部署EAR。根据服务器日志,EJB被成功地导出。所有流量都是基于http-remoting的。根据需要根据嗅探的通信量向下拖曳交换机协议。

让我们以客户端登录为例。登录API调用基于远程EJB通信,同时发送JMS消息。

如果我从Eclipse在本地机器上同时运行客户机和服务器,登录就可以正常工作,JMS消息也会被正确处理。如果我在同一网络中的另一台计算机上运行客户端,则同样适用。如果我在本地网络中运行客户机,但在internet上运行服务器,则EJB通信将失败,JMS消息仍将被正确处理。

为什么会这样呢?

日志内容

没有调用远程EJB的登录方法,也没有日志。我已将log4j.logger.org.jboss.ejb.client=TRACE添加到log4j.properties中。这是客户端在API调用失败时的日志记录:

代码语言:javascript
复制
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)
    ...

我的一些想法

这个问题是否是由

  1. 无效IP?
    • 不是的。移动服务器后,我更新了standalone.xml配置,并通过观察所有机器上的网络流量来确保接收到所有调用。JMS起作用。

  1. WildFly安全设置,例如关于安全域配置?
    • 不是的。登录在本地工作。移动服务器后,这些设置应该是有效的。JMS和EJB都使用相同的WildFly应用程序用户。JMS起作用。

  1. 可能是网络/路由问题,因为EJB是基于RMI的,或者是某种防火墙问题?。
    • 也许吧,但JMS很管用。我还不太习惯JMS,但它不是基于RMI吗?我发送给javax.jms.ObjectMessages. Session.createObjectMessage(Serializable object)一个Serializable,这就是为什么我建议我们这里也有一个Serializable

  1. 在本地,WildFly运行在Windows7上。远程,Wildfly运行在Ubuntu上。我试过Ubuntu 10/12/14。
    • 关于Java和WildFly:它们与平台无关。写一次,到处跑。我认为这个问题不太可能是由底层操作系统引起的。我已经验证了流量和JMS是否有效。

如果我错了,请纠正我。

补充说明

  • 我知道我提供的信息太少了,因为我不想把我的问题搞砸。如果你需要更多的信息,请不要犹豫。这也适用于代码。
  • 我使用Java 8/ Java 7。关于WildFly:我测试了8.1.0.Final、8.2.0 using和9.0.Beta 2。
  • 请不要简单地参考网上的例子。我已经在这方面工作了好几天了,请记住,当地的交流已经很好了。

我非常感谢对此的任何想法和评论,因为我真的被困住了。在此之前,非常感谢您。

更新1: EJB实现、客户端上下文创建和EJB查找

服务器:

代码语言:javascript
复制
@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日志:

代码语言:javascript
复制
java:jboss/exported/GSServerEAR/GSAuthManagerEjb-0.0.1/GsAuthManagerBean!de.genesys.server.ejb.auth.GsAuthManager

客户端:

代码语言:javascript
复制
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");
}
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-23 07:51:40

在日志中,您可以使用deploy appName='GSServerEAR-0.0.1',但是当异常发生时:appName:GSServerEAR。因此,我想,您的EAR文件的运行时(当您部署它)包含版本,它不应该。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30966429

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档