无法通过server1

时间:2017-08-31 07:05:43

标签: wildfly wildfly-10 session-bean ejb-3.2

我想通过server1调用server2的EJB,但仍然被服务器1接收。

看看我的cliet代码&截图

test1& test2没问题

test3失败

有谁知道怎么办?感谢

服务器:wildfly-10.1.0.Final

EJB:3.2

Screenshot

Test Code

会话Bean

public void sayHello(String serverAddress, String clientName) {
    System.out.println("<<<<<<<<<< server[" + serverAddress + "]:hello " + clientName);
}

public void invokeServer2SayHelloViaServer1(String server1Address, String server2Address) {
    try {
        System.out.println(">>>>>>>>>> server[" + server1Address + "] invoke server[" + server2Address + "]'s sayHello");
        Properties jndiProperties = new Properties();
        jndiProperties.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
        jndiProperties.put(Context.PROVIDER_URL,"remote+http://" + server2Address);
        jndiProperties.put(Context.SECURITY_PRINCIPAL, "bpm");
        jndiProperties.put(Context.SECURITY_CREDENTIALS, "1234");

        final Context context = new InitialContext(jndiProperties);
        Test test = (Test) context.lookup("ejb:test-ear/test-ejb/TestBean!com.ejb.Test");
        test.sayHello(server2Address, "server[" + server1Address + "]");
    } catch (Exception e) {
        e.printStackTrace();
    }
}

客户端

public static void main(String[] args) throws Exception {
    String server1Address = "10.20.9.135:8086";
    String server2Address = "10.20.9.20:8086";

    Properties jndiProperties1 = new Properties();
    jndiProperties1.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
    jndiProperties1.put(Context.PROVIDER_URL,"remote+http://" + server1Address);
    jndiProperties1.put(Context.SECURITY_PRINCIPAL, "bpm");
    jndiProperties1.put(Context.SECURITY_CREDENTIALS, "1234");
    final Context context1 = new InitialContext(jndiProperties1);
    Test test1 = (Test) context1.lookup("ejb:test-ear/test-ejb/TestBean!com.ejb.Test");

    Properties jndiProperties2 = new Properties();
    jndiProperties2.put(Context.INITIAL_CONTEXT_FACTORY, "org.wildfly.naming.client.WildFlyInitialContextFactory");
    jndiProperties2.put(Context.PROVIDER_URL,"remote+http://" + server2Address);
    jndiProperties2.put(Context.SECURITY_PRINCIPAL, "bpm");
    jndiProperties2.put(Context.SECURITY_CREDENTIALS, "1234");
    final Context context2 = new InitialContext(jndiProperties2);
    Test test2 = (Test) context2.lookup("ejb:test-ear/test-ejb/TestBean!com.ejb.Test");

    System.out.println("===========test1 invoke server1[" + server1Address +"] sayHello");
    test1.sayHello(server1Address, "client test1");

    System.out.println("===========test2 invoke server2[" + server1Address +"] sayHello");
    test2.sayHello(server1Address, "client test2");

    System.out.println("===========test3 invoke server2[" + server1Address +"] sayHello via server1[" + server1Address +"]");
    test1.invokeServer2SayHelloViaServer1(server1Address, server2Address);

}

0 个答案:

没有答案