// in config map.
ServerInvoker serverInvoker = connector.getServerInvoker();
ServerSocketFactory ssf = serverInvoker.getServerSocketFactory();
assertTrue(ssf instanceof CustomSSLServerSocketFactory);
CustomSSLServerSocketFactory csssf = (CustomSSLServerSocketFactory) ssf;
SSLSocketBuilderMBean builder = csssf.getSSLSocketBuilder();
assertFalse(builder.isServerSocketUseClientMode());
assertEquals("JKS", builder.getKeyStoreType());
File file1 = new File(keyStoreFilePath);
File file2 = new File(builder.getKeyStore().getFile());
assertEquals(file1, file2);
/////////////////////////////////////
///// Do client side test. ////
/////////////////////////////////////
HashMap cconfig = new HashMap();
// Make Client use remote invoker.
cconfig.put(InvokerLocator.FORCE_REMOTE, "true");
// Put SSL parameters in config map.
cconfig.put(SSLSocketBuilder.REMOTING_SOCKET_USE_CLIENT_MODE, "true");
cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_TYPE, "JKS");
trustStoreFilePath = getTruststoreFilePath();
cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_FILE_PATH, trustStoreFilePath);
cconfig.put(SSLSocketBuilder.REMOTING_TRUST_STORE_PASSWORD, "unit-tests-client");
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());
file1 = new File(keyStoreFilePath);
file2 = new File(builder.getKeyStore().getFile());
assertEquals(file1, file2);
client.disconnect();
callbackConnector.stop();
connector.stop();