Client client = new Client(locator, cconfig);
client.connect();
// Set SocketFactory in ClientInvoker.
SocketFactory sf4 = getDefaultSocketFactory();
ClientInvoker clientInvoker = client.getInvoker();
clientInvoker.setSocketFactory(sf4);
// Verify SocketFactory is the one set in ClientInvoker.
assertTrue(sf4 == clientInvoker.getSocketFactory());
//////////////////////////////////////////////
///// Do server side callback test. ////
//////////////////////////////////////////////
Thread.sleep(500);
freeport = PortUtil.findFreePort(getHostName());
InvokerLocator callbackLocator = new InvokerLocator(getTransport() + "://" + getHostName() + ":" + freeport);
HashMap config = new HashMap();
addExtraCallbackConfig(config);
Connector callbackConnector = new Connector(callbackLocator.getLocatorURI(), config);
ServerSocketFactory ssf3 = getDefaultCallbackServerSocketFactory();
callbackConnector.setServerSocketFactory(ssf3);
callbackConnector.create();
callbackConnector.addInvocationHandler("sample", new SampleInvocationHandler());
callbackConnector.start();
CallbackHandler callbackHandler = new CallbackHandler();
String callbackHandleObject = "myCallbackHandleObject";
client.addListener(callbackHandler, callbackLocator, callbackHandleObject);
// Verify that callback succeeded.
assertEquals(1, callbackHandler.getCallbacks().size());
// Verify callback SocketFactory is the one set in SocketInvoker.
Field field = ServerInvoker.class.getDeclaredField("handlers");
field.setAccessible(true);
Map handlers = (Map) field.get(serverInvoker);
Object obj = handlers.values().iterator().next();
SampleInvocationHandler sampleInvocationHandler = (SampleInvocationHandler) obj;
obj = sampleInvocationHandler.getCallbackHandler();
ServerInvokerCallbackHandler serverInvokerCallbackHandler = (ServerInvokerCallbackHandler) obj;
field = ServerInvokerCallbackHandler.class.getDeclaredField("callBackClient");
field.setAccessible(true);
Client callbackClient = (Client) field.get(serverInvokerCallbackHandler);
ClientInvoker callbackClientInvoker = callbackClient.getInvoker();
assertTrue(sf2 == callbackClientInvoker.getSocketFactory());
client.disconnect();
callbackConnector.stop();
connector.stop();
log.info(getName() + " PASSES");