try {
ProtocolSocketFactoryBuilder factoryBuilder = (ProtocolSocketFactoryBuilder) factoryClass.newInstance();
factoryBuilder.setConfiguration(properties);
socketFactory = factoryBuilder.newInstance();
} catch (InstantiationException e) {
throw new ConfigurationException("Failed to instantiate ProtocolSocketFactoryBuilder implementation class [" + factory + "]. Must provide a default constructor.", e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Failed to instantiate ProtocolSocketFactoryBuilder implementation class [" + factory + "]. Must provide a default constructor.", e);
}
} else {
socketFactory = (ProtocolSocketFactory) factoryClass.newInstance();
}
} catch (ClassCastException e) {
throw new ConfigurationException("Class [" + factory + "] must implement [" + ProtocolSocketFactory.class.getName() + "].", e);
} catch (ClassNotFoundException e) {
throw new ConfigurationException("ProtocolSocketFactory implementation class [" + factory + "] not found in classpath.", e);
} catch (InstantiationException e) {
throw new ConfigurationException("Failed to instantiate ProtocolSocketFactory implementation class [" + factory + "].", e);
} catch (IllegalAccessException e) {
throw new ConfigurationException("Failed to instantiate ProtocolSocketFactory implementation class [" + factory + "].", e);
}
if(socketFactory instanceof SSLClient && keyMaterial != null) {
try {
((SSLClient)socketFactory).setKeyMaterial(keyMaterial);
} catch (NoSuchAlgorithmException e) {
throw new ConfigurationException("Failed to configure SSL Keystore on SSLClient.", e);
} catch (KeyStoreException e) {
throw new ConfigurationException("Failed to configure SSL Keystore on SSLClient.", e);
} catch (KeyManagementException e) {
throw new ConfigurationException("Failed to configure SSL Keystore on SSLClient.", e);
} catch (IOException e) {
throw new ConfigurationException("Failed to configure SSL Keystore on SSLClient.", e);
} catch (CertificateException e) {
throw new ConfigurationException("Failed to configure SSL Keystore on SSLClient.", e);
}
}
return socketFactory;
}