gpt4 book ai didi

java - JBoss AS 7 Bean 查找 EJB

转载 作者:行者123 更新时间:2023-12-01 04:12:08 26 4
gpt4 key购买 nike

我知道这里有一些类似的问题,但我仍然找不到解决方案。我有两台 JBoss AS 7.0 服务器运行在同一台机器上,即 A 和 B。

A,是服务器并提供此服务:

15:49:02,998 INFO  [org.jboss.as.ejb3.deployment.processors.EjbJndiBindingsDeploymentUnitProcessor] (MSC service thread 1-4) JNDI bindings for session bean named QuartzManagerBean in deployment unit subdeployment "Foo-Services.jar" of deployment "Foo-Batch.ear" are as follows:

java:global/Foo-Batch/Foo-Services/QuartzManagerBean!foo.services.interfaces.IQuartzManagerLocal
java:app/Foo-Services/QuartzManagerBean!foo.services.interfaces.IQuartzManagerLocal
java:module/QuartzManagerBean!foo.services.interfaces.IQuartzManagerLocal
java:global/Foo-Batch/Foo-Services/QuartzManagerBean!foo.services.interfaces.IQuartzManagerRemote
java:app/Foo-Services/QuartzManagerBean!foo.services.interfaces.IQuartzManagerRemote
java:module/QuartzManagerBean!foo.services.interfaces.IQuartzManagerRemote
java:jboss/exported/Foo-Batch/Foo-Services/QuartzManagerBean!foo.services.interfaces.IQuartzManagerRemote

QuartzManagerBean

package foo.services.bean;


@Startup
@Singleton

@Remote(IQuartzManagerRemote.class)


@TransactionManagement(value=TransactionManagementType.BEAN)
@TransactionAttribute(value=TransactionAttributeType.NOT_SUPPORTED)


@WebService(name = "BatchQuartzManagerBean", targetNamespace = "urn:foo", serviceName = "BatchQuartzManagerBean")
@SOAPBinding(style = SOAPBinding.Style.DOCUMENT, parameterStyle = SOAPBinding.ParameterStyle.WRAPPED, use = SOAPBinding.Use.LITERAL)

public class QuartzManagerBean implements IQuartzManagerLocal, IQuartzManagerRemote{

...

public synchronized ReturnType fooMethod(
String serverName,
....

)
{

...

}
...

}

最后是接口(interface)IQuartzManagerRemote

@Remote
@WebService
public interface IQuartzManagerRemote {


@WebMethod(operationName = "fooMethod")
public ReturnType fooMethod(
@WebParam(name="serverName") String serverName,
....
);


}

在服务器B上,我需要远程访问此EJB。我尝试了几种方法,像这样

        env.put("endpoint.name","client-endpoint"); 
env.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
env.put("remote.connections", "default");
env.put("remote.connection.default.host","127.0.0.1");
env.put("remote.connection.default.port","4447");
env.put("remote.connection.default.connect.options.org.xnio.Options.SASL_POLICY_NOANONYMOUS", "false");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.ejb.client.naming");
env.put("jboss.naming.client.ejb.context", true);
context = new InitialContext(env);

或者这个

    Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"rhttp://localhost:8080/Foo-Services/BatchQuartzManagerBean/BatchQuartzManagerBean:4447");
// This is an important property to set if you want to do EJB invocations via the remote-naming project
jndiProps.put("jboss.naming.client.ejb.context", true);
// create a context passing these properties
Context context = new InitialContext(jndiProps);

或者这个

    Properties jndiProps = new Properties();
jndiProps.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
jndiProps.put(Context.PROVIDER_URL,"remote://localhost:4447");
jndiProps.put("jboss.naming.client.ejb.context", true);
// create a context passing these properties
InitialContext ctx = new InitialContext(jndiProps);

或者这个

 Properties p = new Properties();
p.put("remote.connectionprovider.create.options.org.xnio.Options.SSL_ENABLED", "false");
p.put("remote.connections", "one");
p.put("remote.connection.one.port", "4447");
p.put("remote.connection.one.host", "localhost");
p.put("jboss.naming.client.ejb.context", true);

EJBClientConfiguration cc = new PropertiesBasedEJBClientConfiguration(p);
ContextSelector<EJBClientContext> selector = new ConfigBasedEJBClientContextSelector(cc);
EJBClientContext.setSelector(selector);

等等......

最后,我需要执行查找,并且我再次尝试了不同的方法。

QuartzManagerRemote quartzWSClient = (IQuartzManagerRemote) context.lookup("ejb:" + "Foo-Batch" + "/" + "Foo-Services" + "/" + "/" +"QuartzManagerBean" + "!" +IQuartzManagerRemote.class.getName());

或使用 java:java:exported/可能是所有组合..

结果几乎总是相同的。如果我使用以 java: 开头的查找我明白了

ERROR [stderr] (http-/127.0.0.1:8180-6) javax.naming.NameNotFoundException: Foo-Batch/Foo-Services//QuartzManagerBean!foo.services.interfaces.IQuartzManagerRemote -- service jboss.naming.context.java.jboss.exported.Foo-Batch.Foo-Services."QuartzManagerBean!foo.services.interfaces.IQuartzManagerRemote"

另一方面,如果我使用以 ejb... 开头的查找

java.lang.IllegalStateException: EJBCLIENT000025: No EJB receiver available for handling [appName:Foo-Batch, moduleName:Foo-Services, distinctName:] combination for invocation context org.jboss.ejb.client.EJBClientInvocationContext@4c42ff8

注意 我可以使用 SOAP-UI 和生成的 WSDL 作为 Web 服务来访问此 bean,因此该服务已启动。但是,我的目的是使用 EJB 进行访问。

最佳答案

解决了!我退出以访问远程 EJB 并访问 WS,而无需创建 stub 等。因此,我需要创建一个方法来获取端口进行通信。

private static IQuartzManagerRemote getPort(String endpointURI) throws MalformedURLException   {
QName serviceName = new QName("urn:foo", "FooQuartzManagerBean");
URL wsdlURL = new URL(endpointURI);

Service service = Service.create(wsdlURL, serviceName);
return service.getPort(IQuartzManagerRemote.class);
}

在我的方法中只需进行一个简单的调用

.... myMethod() {

String endpointURI ="http://127.0.0.1:8080/Foo-Services/FooQuartzManagerBean/FooQuartzManagerBean?WSDL";

//call webmethod instatianteJob
getPort(endpointURI).instantiateJob( ....

}

一切看起来都很完美

更多信息请参见:

Reference - JBoss Web Services Part I

关于java - JBoss AS 7 Bean 查找 EJB,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19817427/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com