unable to invoke server2 EJB via server1

52 views Asked by At

I want to invoke server2's EJB via server1, but still received by server 1.

Look at my cliet code & screenshot

test1 & test2 is ok

test3 is fail

Does anyone know how to do? thanks

Server:wildfly-10.1.0.Final

EJB:3.2

Screenshot

Test Code

Session 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();
    }
}

Client

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

There are 0 answers