Wildfly上的EJB从另一个Wildfly调用远程EJB [英] EJB on Wildfly calling remote EJB from another Wildfly
问题描述
我知道,有类似的问题,但他们中没有一个真正帮助我的问题。
其中一个持有一个休息的应用程序,当它收到GET时触发无状态会话bean
SenderBean
。 此后,此无状态会话bean应该调用位于另一个wildfly实例上的远程无状态会话bean
PrintBean
的方法。 我将开始解释我迄今为止做过的事情(也许我错过了一些东西,我对Java EE和Wildfly来说都是新手。)
我将使用 SenderBean
发件人
调用Wildfly实例, PrintBean
Receiver
。
我创建了一个应用程序用户命名为 Stefan
密码 stefan
,属于客人
接收者
。
在发件人
中,在 standalone-full.xml
中,我添加了一个安全领域
< security-realm name =ejb-security-realm>
<服务器身份>
< secret value =c3R1ZmFu/>
< / server-identityities>
< / security-realm>
到< security-realms>
部分。
我还添加了一个outbound-socket-binding通过放置
< outbound-socket-binding name =remote -ejb>
< remote-destination host =localhostport =8080/>
< / outbound-socket-binding>
到< socket-binding-group ...>
部分。
最后,我创建了一个出站连接,通过放置
< outbound-connections>
< remote-outbound-connection name =remote-ejb-connectionoutbound-socket-binding-ref =remote-ejbusername =Stefansecurity-realm =ejb-security-realm> ;
<属性>
< property name =SASL_POLICY_NOANONYMOUSvalue =false/>
< property name =SSL_ENABLEDvalue =false/>
< / properties>
< / remote-outbound-connection>
< / outbound-connections>
进入<子系统xmlns =urn:jboss:domain:remoting :2.0>
部分。
使用CLI命令启动发件人
standalone.bat -c standalone-full.xml -Djboss.socket.binding.port-offset = 100 -Djboss.node.name = Sender
和接收者
with standalone.bat -c standalone-full.xml -Djboss.node.name = Receiver
。
发件人
上的本地无状态会话Bean称为 SenderBean
:
@Stateless
public class SenderBean implements SenderService {
private static final Logger logger = Logger.getLogger(SenderBean .class.getSimpleName());
public void send(){
logger.info(Trying to invoke);
this.invoke();
}
private void invoke(){
属性clientProperties = new Properties();
clientProperties.put(remote.connections,default);
clientProperties.put(remote.connection.default.port,8080);
clientProperties.put(remote.connection.default.host,localhost);
属性属性= new Properties();
properties.put(Context.URL_PKG_PREFIXES,org.jboss.ejb.client.naming);
try {
Context context = new InitialContext(properties);
context = new InitialContext(properties);
对象x = context.lookup(ejb:baseproject-ear-01.00.00-SNAPSHOT / testdomain-service-01.00.00-SNAPSHOT / Receiver / PrintBean!com.schubert.baseproject.testdomain.service.PrintService );
logger.info(获取一些对象+ x.toString());
logger.info(Trying to cast。);
PrintService s =(PrintService)x;
logger.info(Cast successful);
logger.info(使用远程ejb打印+ s.print(Markus));
} catch(NamingException e){
e.printStackTrace();
}
}
}
而$ code>接收者包含 PrintBean
:
@Stateless
@Remote(PrintService.class)
public class PrintBean实现PrintService {
@Override
public String print(String name){
返回你好+名字;
}
}
现在的问题是,我总是得到一个code> IllegalStateException 说EJBCLIENT000025:没有EJB接收器可用于处理...
我可能会做错事吗?我对EJB和Wildfly来说相当新鲜。
您可以在 GitHub 上找到项目设置。
您应该将文件jboss-ejb-client.xml添加到发件人EAR(而不是WAR)中。将它放在application.xml旁边。
jboss-ejb-client.xml内容:
< JBoss的-EJB-客户机GT;
< client-context>
< ejb-recipients>
< remoting-ejb-receiver outbound-connection-ref =remote-ejb-connection/>
< / ejb-recipients>
< / client-context>
< / jboss-ejb-client>
在发件人bean中有两行足够:
Context context = new InitialContext();
对象x = context.lookup(ejb:baseproject-ear-01.00.00-SNAPSHOT / testdomain-service-01.00.00-SNAPSHOT / PrintBean!com.schubert.baseproject.testdomain.service.PrintService);
请注意,我从路径中删除了Receiver /。您可以在服务器日志中找到JNDI绑定。
my current problem in general is, that i have two Wildfly 8.2.0Final instances running on my machine.
I know, there are similar questions, but none of them really help with my problem.
One of them holds a restful application that triggers a stateless session bean SenderBean
when it receives a GET.
Afterwards, this stateless session bean should invoke a method from a remote stateless session bean PrintBean
, which is located on the other wildfly instance.
I'll start of by explaining what i have done so far (maybe i missed something, i'm quite new to Java EE and Wildfly).
I'm going to call the Wildfly instance with the SenderBean
the Sender
and the one with the PrintBean
the Receiver
.
I created an Application user named Stefan
with Password stefan
, belonging to group guest
on the Receiver
.
On the Sender
, in the standalone-full.xml
, i added a Security-Realm by putting
<security-realm name="ejb-security-realm">
<server-identities>
<secret value="c3R1ZmFu"/>
</server-identities>
</security-realm>
into the <security-realms>
section.
I also added a outbound-socket-binding by putting
<outbound-socket-binding name="remote-ejb">
<remote-destination host="localhost" port="8080"/>
</outbound-socket-binding>
into the <socket-binding-group ...>
section.
Last, i created an outbound-connection, by putting
<outbound-connections>
<remote-outbound-connection name="remote-ejb-connection" outbound-socket-binding-ref="remote-ejb" username="Stefan" security-realm="ejb-security-realm">
<properties>
<property name="SASL_POLICY_NOANONYMOUS" value="false"/>
<property name="SSL_ENABLED" value="false"/>
</properties>
</remote-outbound-connection>
</outbound-connections>
into the <subsystem xmlns="urn:jboss:domain:remoting:2.0">
section.
I start the Sender
with the CLI command standalone.bat -c standalone-full.xml -Djboss.socket.binding.port-offset=100 -Djboss.node.name=Sender
and the Receiver
with standalone.bat -c standalone-full.xml -Djboss.node.name=Receiver
.
The Local Stateless Session Bean on the Sender
is called SenderBean
:
@Stateless
public class SenderBean implements SenderService {
private static final Logger logger = Logger.getLogger(SenderBean.class.getSimpleName());
public void send(){
logger.info("Trying to invoke");
this.invoke();
}
private void invoke() {
Properties clientProperties = new Properties();
clientProperties.put("remote.connections", "default");
clientProperties.put("remote.connection.default.port", "8080");
clientProperties.put("remote.connection.default.host", "localhost");
Properties properties = new Properties();
properties.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
try {
Context context = new InitialContext(properties);
context = new InitialContext(properties);
Object x = context.lookup("ejb:baseproject-ear-01.00.00-SNAPSHOT/testdomain-service-01.00.00-SNAPSHOT/Receiver/PrintBean!com.schubert.baseproject.testdomain.service.PrintService");
logger.info("Obtained some object "+x.toString());
logger.info("Trying to cast.");
PrintService s = (PrintService) x;
logger.info("Cast successful");
logger.info("Printing using remote ejb: "+s.print("Markus"));
} catch (NamingException e) {
e.printStackTrace();
}
}
}
And the Receiver
contains the PrintBean
:
@Stateless
@Remote(PrintService.class)
public class PrintBean implements PrintService {
@Override
public String print(String name) {
return "Hello " + name;
}
}
the problem now is, I always get a IllegalStateException
that says EJBCLIENT000025: No EJB receiver available for handling ...
Am I maybe doing something very wrong? I am fairly new to EJBs and Wildfly. You can find the project setup on GitHub.
You should add file jboss-ejb-client.xml to your sender EAR (not to WAR). Place it next to application.xml.
jboss-ejb-client.xml content:
<jboss-ejb-client>
<client-context>
<ejb-receivers>
<remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection"/>
</ejb-receivers>
</client-context>
</jboss-ejb-client>
In sender bean two lines are enough:
Context context = new InitialContext();
Object x = context.lookup("ejb:baseproject-ear-01.00.00-SNAPSHOT/testdomain-service-01.00.00-SNAPSHOT/PrintBean!com.schubert.baseproject.testdomain.service.PrintService");
Note that I removed "Receiver/" from path. You can find JNDI bindings in server log.
这篇关于Wildfly上的EJB从另一个Wildfly调用远程EJB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!