1
package org.jboss.test.remoting.transport.socket.ssl.builder;
3
import junit.framework.TestCase;
4
import org.apache.log4j.Level;
5
import org.jboss.logging.Logger;
6
import org.jboss.remoting.Client;
7
import org.jboss.remoting.InvocationRequest;
8
import org.jboss.remoting.InvokerLocator;
9
import org.jboss.remoting.ServerInvocationHandler;
10
import org.jboss.remoting.ServerInvoker;
11
import org.jboss.remoting.callback.Callback;
12
import org.jboss.remoting.callback.HandleCallbackException;
13
import org.jboss.remoting.callback.InvokerCallbackHandler;
14
import org.jboss.remoting.invocation.NameBasedInvocation;
15
import org.jboss.remoting.security.SSLSocketBuilder;
16
import org.jboss.remoting.transport.Connector;
17
import org.jboss.test.remoting.transport.socket.ssl.SSLInvokerConstants;
19
import javax.management.MBeanServer;
20
import java.util.HashMap;
24
* This is the client for the test to make regular ssl based invocation to the server and
25
* have a ssl based callback server. The special test in this case is want to have the callback
26
* client that lives on the server to be in client mode so that this client test only has to have
27
* a truststore locally, yet still use ssl.
29
* @author <a href="mailto:tom.elrod@jboss.com">Tom Elrod</a>
31
public class SSLSocketInvokerTestClient extends TestCase implements SSLInvokerConstants
33
private Client client;
34
private Connector callbackConnector;
35
private static final Logger log = Logger.getLogger(SSLSocketInvokerTestClient.class);
36
private boolean gotCallback = false;
38
public void init() throws Exception
40
// since doing basic (using default ssl server socket factory)
41
// need to set the system properties to the truststore
42
String trustStoreFilePath = this.getClass().getResource("../.truststore").getFile();
43
System.setProperty("javax.net.ssl.trustStore", trustStoreFilePath);
44
System.setProperty("javax.net.ssl.trustStorePassword", "unit-tests-client");
45
// System.setProperty("javax.net.ssl.trustStorePassword", "secureexample");
47
InvokerLocator locator = new InvokerLocator(getTransport() + "://" + host + ":" + getPort());
49
// create callback connector
50
Map config = new HashMap();
51
config.put(SSLSocketBuilder.REMOTING_SERVER_SOCKET_USE_CLIENT_MODE, "true");
52
callbackConnector = new Connector(getTransport() + "://" + host + ":" + (getPort() + 5), config);
53
callbackConnector.create();
54
callbackConnector.addInvocationHandler("callback", new CallbackInvokerHandler());
55
callbackConnector.start();
57
client = new Client(locator, "mock");
62
client.addListener(new TestCallbackHandler(), callbackConnector.getLocator());
64
catch (Throwable throwable)
66
Exception e = new Exception(throwable.getMessage());
67
e.initCause(throwable);
73
public void testRemoteCall() throws Throwable
75
log.debug("running testRemoteCall()");
77
// simple invoke, should return bar
78
Object ret = makeInvocation("foo", "bar");
79
assertTrue("Result of testRemoteCall() invocation of foo.", "bar".equals(ret));
80
assertEquals("bar", ret);
82
// this will cause the server to start sending callbacks
83
ret = makeInvocation("test", "foobar");
85
System.out.println("ret = " + ret);
90
// Thread.sleep(600000);
92
assertTrue(gotCallback);
97
protected String getTransport()
102
protected int getPort()
107
private Object makeInvocation(String method, String param) throws Throwable
109
Object ret = client.invoke(new NameBasedInvocation(method,
111
new String[]{String.class.getName()}),
117
public void setUp() throws Exception
119
org.apache.log4j.BasicConfigurator.configure();
120
org.apache.log4j.Category.getRoot().setLevel(Level.INFO);
121
org.apache.log4j.Category.getInstance("org.jgroups").setLevel(Level.INFO);
122
org.apache.log4j.Category.getInstance("org.jboss.remoting").setLevel(Level.DEBUG);
123
org.apache.log4j.Category.getInstance("test").setLevel(Level.DEBUG);
128
public void tearDown() throws Exception
137
public class TestCallbackHandler implements InvokerCallbackHandler
140
public void handleCallback(Callback callback) throws HandleCallbackException
142
System.out.println("TestCallbackHandler.handleCallback() - " + callback);
147
public class CallbackInvokerHandler implements ServerInvocationHandler
149
private InvokerCallbackHandler listener;
151
public void setMBeanServer(MBeanServer server)
155
public void setInvoker(ServerInvoker invoker)
159
public Object invoke(InvocationRequest invocation) throws Throwable
161
System.out.println("CallbackInvokerHandler.invoke() called with " + invocation.getParameter());
165
public void addListener(InvokerCallbackHandler callbackHandler)
167
listener = callbackHandler;
170
public void removeListener(InvokerCallbackHandler callbackHandler)