Client client = new Client(locator, cconfig);
client.connect();
// Verify SocketFactory was configured according to SSL parameters
// in config map.
ClientInvoker clientInvoker = client.getInvoker();
SocketFactory sf = clientInvoker.getSocketFactory();
assertTrue(sf instanceof CustomSSLSocketFactory);
CustomSSLSocketFactory cssf = (CustomSSLSocketFactory) sf;
builder = cssf.getSSLSocketBuilder();
assertTrue(builder.isSocketUseClientMode());
assertEquals("JKS", builder.getKeyStoreType());
file1 = new File(trustStoreFilePath);
file2 = new File(builder.getTrustStore().getFile());
assertEquals(file1, file2);
//////////////////////////////////////////////
///// 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 SocketFactory was configured according to SSL parameters in config map.
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();
sf = callbackClientInvoker.getSocketFactory();
assertTrue(sf instanceof CustomSSLSocketFactory);
cssf = (CustomSSLSocketFactory) sf;
builder = cssf.getSSLSocketBuilder();
assertFalse(builder.isSocketUseClientMode());
assertEquals("JKS", builder.getKeyStoreType());