我目前的问题一般是,我的机器上运行了两个Wildfly 8.2.0Final实例。
我知道,有类似的问题,但它们都没有真正帮助解决我的问题。
其中一个包含一个restful应用程序,它在收到GET时触发无状态会话bean SenderBean
。
之后,这个无状态会话bean应该从远程无状态会话bean PrintBean
调用一个方法,该方法位于另一个wildfly实例上。
我将首先解释一下到目前为止所做的事情(也许我错过了一些东西,我对Java EE和Wildfly来说还是一个新手)。
我将使用SenderBean
Sender
和PrintBean
Receiver
来调用Wildfly实例。
我在Stefan
上创建了一个名为stefan
的应用用户,其密码为guest
,属于群组Receiver
。
在Sender
,在standalone-full.xml
中,我添加了一个安全领域
<security-realm name="ejb-security-realm">
<server-identities>
<secret value="c3R1ZmFu"/>
</server-identities>
</security-realm>
进入<security-realms>
部分。
我还通过添加
<outbound-socket-binding name="remote-ejb">
<remote-destination host="localhost" port="8080"/>
</outbound-socket-binding>
进入<socket-binding-group ...>
部分。
最后,我通过添加
<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>
进入<subsystem xmlns="urn:jboss:domain:remoting:2.0">
部分。
我使用CLI命令Sender
启动standalone.bat -c standalone-full.xml -Djboss.socket.binding.port-offset=100 -Djboss.node.name=Sender
,使用Receiver
启动standalone.bat -c standalone-full.xml -Djboss.node.name=Receiver
。
Sender
上的本地无状态会话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() {
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();
}
}
}
Receiver
包含PrintBean
:
@Stateless
@Remote(PrintService.class)
public class PrintBean implements PrintService {
@Override
public String print(String name) {
return "Hello " + name;
}
}
现在的问题是,我总是得到一个IllegalStateException
,表示EJBCLIENT000025:没有可用于处理的EJB接收器......
我可能做错了吗?我是EJB和Wildfly的新手。 您可以在GitHub上找到项目设置。
答案 0 :(得分:2)
您应该将文件jboss-ejb-client.xml添加到您的发件人EAR(而不是WAR)。将它放在application.xml旁边。
jboss-ejb-client.xml内容:
<jboss-ejb-client>
<client-context>
<ejb-receivers>
<remoting-ejb-receiver outbound-connection-ref="remote-ejb-connection"/>
</ejb-receivers>
</client-context>
</jboss-ejb-client>
在sender bean中有两行就足够了:
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");
请注意,我从路径中删除了“Receiver /”。您可以在服务器日志中找到JNDI绑定。
答案 1 :(得分:0)
我认为问题在于InitialContext的参数,服务器配置都很好。尝试按照我的远程队列连接示例,如果是普通的企业bean,你也可以探索这样的场景(插入正确的用户登录名和密码):
env.put(Context.PROVIDER_URL, "http-remoting://localhost:8080");
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
env.put(Context.SECURITY_PRINCIPAL, "client");
env.put(Context.SECURITY_CREDENTIALS, "q");
Context ctx = new InitialContext(env);
connectionFactory = (ConnectionFactory)ctx.lookup("/jms/RemoteConnectionFactory");
connection = connectionFactory.createConnection("client", "q");
请记住,具有开放外部访问可能性的jndi资源必须从服务器配置开始,使用java:/ jboss / exported /,但在客户端,您可以删除这些单词。这条指令适用于WildFly,但不适用于JBoss EAP / AS等。您可以按照link。
获取更多信息答案 2 :(得分:0)
可以在两台JBoss服务器之间找到detailed description of configuration,在GitHub上提供配置文件的源代码quickstart