@远程JNDI通信:Wildfly到JBoss AS 5.1.0.GA [英] @Remote JNDI Communication: Wildfly to JBoss AS 5.1.0.GA
问题描述
体系结构: Windows客户端-> Wildfly JAX-RS服务-> JBoss 5.1.0.GA旧版系统.
Architecture: Windows Client -> Wildfly JAX-RS Services -> JBoss 5.1.0.GA legacy system.
我正在获取java.lang.ClassCastException:在Wildfly JAX-RS服务与JBoss 5.1.0.GA旧版系统之间进行通信时,无法将javax.naming.Reference强制转换为com.interfaces.GroupBookingManagerRemote.
I am getting a java.lang.ClassCastException: javax.naming.Reference cannot be cast to com.interfaces.GroupBookingManagerRemote when communicating here between Wildfly JAX-RS Services and JBoss 5.1.0.GA legacy system.
当我从Wildfly到JBoss AS 5.1.0.GA通信时,我试图使用JNDI进行连接.
As I am communicating from Wildfly to JBoss AS 5.1.0.GA I am attempting to connect using JNDI.
在我的Wildfly Server Maven pom中,我包括:
In my Wildfly Server Maven pom I include:
<dependency>
<groupId>jboss</groupId>
<artifactId>jnp-client</artifactId>
<version>4.2.2.GA</version>
</dependency>
这使我可以访问所需的org.jnp.*类和接口.
This gives me access to the required org.jnp.* classes and interfaces.
我只需使用以下代码连接到我的远程计算机,然后取回GroupBookingManager.但是,当我尝试将类强制转换为GroupBookingManagerRemote接口时,会出现问题.
I simply use the following code to connect to my remote machine and retrieve back a GroupBookingManager. However the issue appears when I attempt to cast the class to the interface GroupBookingManagerRemote.
Properties env = new Properties();
env.setProperty(Context.PROVIDER_URL, "jnp://myremoteserver:1099");
env.setProperty(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.setProperty(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
InitialContext initialContext = new InitialContext(env);
Object ref = initialContext.lookup("MyEARFile/GroupBookingManager/remote");
if (ref != null) {
bookingManager = (GroupBookingManagerRemote) ref; // java.lang.ClassCastException: javax.naming.Reference cannot be cast
}
我有一个myclient.jar文件,该文件已添加到包含远程接口GroupBookingManagerRemote的Wildfly应用程序中.
I have a myclient.jar file which I have added to my Wildfly application that contains the remote interface GroupBookingManagerRemote.
有人看到我所做的任何事情吗?
Does anyone see any issue with what I have done?
谢谢
Darren
推荐答案
感谢您对Gimby的帮助,
Thanks for your help Gimby,
经过一番混乱之后,我自己找到了答案.
I found the answer myself after a bit more messing about.
从Wildfly 8.1.0(客户端)-> JBoss AS 5
From Wildfly 8.1.0 (client) -> JBoss AS 5
您不需要任何JBoss 5罐子
You do not require any JBoss 5 jars
首先,您需要引用要在客户端使用的接口.这可以在your-project-client.jar中.如果使用Maven,则可以创建存储库并使用mvn
Firstly you need a reference to the interface that you wish to use on the client side. This can be in a your-project-client.jar. If using Maven you can create a repository and build the Maven directory structure using mvn
mvn install:install-file -DlocalRepositoryPath=DirectoryName -DcreateChecksum=true -Dpackaging=jar -Dfile=Path-to-you-project-client.jar -DgroupId=YourGroupId -DartifactId=YourartifactId -Dversion=1.0
然后,为了连接到远程计算机并将接口投射回您的接口,请使用:
Then in order to connect to the remote machine and cast the interface back to your-interface, you use:
final Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, org.jboss.naming.remote.client.InitialContextFactory.class.getName());
env.put(Context.PROVIDER_URL, "remote://remoteserver:4447");
InitialContext initialContext = new InitialContext(env);
这将使用Wildfly remote://(位于远程命名中)和wildfly-ejb-client-bom中的ejb
This uses Wildfly remote:// which is in remote naming and ejb in wildfly-ejb-client-bom
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-ejb-client-bom</artifactId>
<version>8.1.0.Final</version>
<scope>compile</scope>
<type>pom</type>
</dependency>
我也需要这种依赖性进行通信
And I also required this dependency for communication
<dependency>
<groupId>org.jboss.xnio</groupId>
<artifactId>xnio-nio</artifactId>
<version>3.2.2.Final</version>
<scope>compile</scope>
</dependency>
和这一个用于远程命名.
and this one for the remote naming.
<dependency>
<groupId>org.jboss</groupId>
<artifactId>jboss-remote-naming</artifactId>
<version>2.0.1.Final</version>
</dependency>
还要注意,该端口不是JBoss 5 JNDI:1099的常用端口,这是默认的远程端口:4447
Also note the port is not the ususal port for JBoss 5 JNDI:1099 this is the Default Remoting Port : 4447
Object ref = initialContext.lookup("ejb:Your-EAR/YourClass/remote!" + YouClass.class.getName());
然后您可以将您的引用投射到您的界面上,并照常使用它.
You can then cast your reference to your interface and use it as normal.
希望这是有道理的.
这篇关于@远程JNDI通信:Wildfly到JBoss AS 5.1.0.GA的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!