EJB远程客户端从JBoss AS 7.1迁移到Wildfly 8.1 [英] EJB remote client migration from JBoss AS 7.1 to Wildfly 8.1

查看:212
本文介绍了EJB远程客户端从JBoss AS 7.1迁移到Wildfly 8.1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们开发了一个培训应用程序,其中包含与EJB通信的独立Java客户机。工作设置包括在Windows 7上的JBoss AS 7.1和通过/bin/add-user.bat创建的应用程序用户。



客户端的编码方式如下: p>

 属性jndiProps = new Properties(); 
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY,org.jboss.naming.remote.client.InitialContextFactory);
jndiProps.put(Context.URL_PKG_PREFIXES,org.jboss.ejb.client.naming);
jndiProps.put(jboss.naming.client.ejb.context,true);
jndiProps.put(Context.PROVIDER_URL,remote:// localhost:4447);
jndiProps.put(Context.SECURITY_PRINCIPAL,user);
jndiProps.put(Context.SECURITY_CREDENTIALS,xxx);
上下文ctx = new InitialContext(jndiProps);
MyBeanRemote myBean =(MyBeanRemote)ctx.lookup(ejb:/ training // MyBean!mypackage.MyBeanRemote);
String result = myBean.greet(John);

客户端是在类路径中的jboss-client.jar中启动的。



现在我们试图使用一个WildFly 8.1,而不是成功部署,但客户端失败了

 线程中的异常mainjava.lang.IllegalStateException:EJBCLIENT000025:没有EJB接收器可用于处理[appName :, moduleName:syjeews,distinctName:]组合用于调用上下文org.jboss.ejb.client.EJBClientInvocationContext@6e7d3146 
将JNDI查找名称更改为在部署期间打印出来的内容(例如 java:global /训练/ MyBean!mypackage.MyBeanRemote )导致

 线程main中的异常javax.naming .CommunicationException:无法连接到任何服务器。服务器尝试:[remote:// localhost:4447(java.net.ConnectException:Connection refused:no further information)] 

搜索google搜索一段时间后,我们收到了关于SO的几篇文章(例如 )或样本 Wildfly开发者指南,但所有替代方案,可能是最小的JNDI属性或通过ClientContext的扩展配置没有使其工作。



所以我的问题是,需要做什么来迁移代码/ co注意:这不是生产代码,所以安全性不是一个问题 - 如果我可以简化整个配置,这很好 - 它是很好的 - 它可以在WildFly上运行它运行它在WildFly?



<应该仅仅演示如何使用独立Java程序的EJB远程接口。

解决方案

您需要进行两个更改



而不是使用remote:// localhost:4447使用http-remoting:// localhost:8080

  jndiProps.put(Context.PROVIDER_URL,http-remoting:// localhost:8080); 

当您在代码中配置jndi属性时,查找名称不应包含 ejb:

  MyBeanRemote myBean =(MyBeanRemote)ctx.lookup(/ training // MyBean!mypackage。 MyBeanRemote); 

此解决方案经过测试和工作


We developed a training application which contains a standalone java clients communicating with EJBs. The working setup included a JBoss AS 7.1 on Windows 7 and an application user created via /bin/add-user.bat.

The client was coded like that:

Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
jndiProps.put("jboss.naming.client.ejb.context", true);
jndiProps.put(Context.PROVIDER_URL, "remote://localhost:4447");
jndiProps.put(Context.SECURITY_PRINCIPAL, "user");
jndiProps.put(Context.SECURITY_CREDENTIALS, "xxx");
Context ctx = new InitialContext(jndiProps);
MyBeanRemote myBean = (MyBeanRemote) ctx.lookup("ejb:/training//MyBean!mypackage.MyBeanRemote");
String result = myBean.greet("John");

The client was started with jboss-client.jar in the classpath.

Now we tried to use a WildFly 8.1 instead which deployed successfully, but the client fails with

Exception in thread "main" java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:, moduleName:syjeews, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@6e7d3146

Changing the JNDI lookup name into something which is printed out during deployment (e.g. java:global/training/MyBean!mypackage.MyBeanRemote) resulted in

Exception in thread "main" javax.naming.CommunicationException: Failed to connect to any server. Servers tried: [remote://localhost:4447 (java.net.ConnectException: Connection refused: no further information)]

After searching googling for a while we stumpled upon several articles on SO (e.g. this or that) or samples or the Wildfly Developer Guide, but all alternatives, may it be the minimal JNDI properties or the extended configuration via ClientContext didn't make it work.

So my question is, what needs to be done to migrate the code/configuration above to run it under WildFly?

Note: This is not production code, so security is not an issue - if I can simplify the whole configuration, it's fine - it should only demonstrate how to use an EJB remote interface from a standalone Java program.

解决方案

You need to do two changes

instead of using "remote://localhost:4447" use "http-remoting://localhost:8080"

jndiProps.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");

When you configure jndi properties in code, lookup name should not contain ejb:

MyBeanRemote myBean = (MyBeanRemote) ctx.lookup("/training//MyBean!mypackage.MyBeanRemote");

this solution is tested and working

这篇关于EJB远程客户端从JBoss AS 7.1迁移到Wildfly 8.1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆