1

我知道这里有一些类似的问题,但我仍然找不到解决方案。我有两台 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, 
                ....

                )
                {

                ...

                }
                ...

}

最后,接口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);

ETC....

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

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 进行访问。

4

1 回答 1

0

解决了!我退出访问远程 EJB 和访问 WS,而无需创建存根等。因此,我需要创建一个方法来让端口进行通信。

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( ....

}

一切看起来都很完美

更多信息在这里:

参考 - JBoss Web 服务第一部分

于 2013-11-12T17:28:31.190 回答