Java Client with certificate authentication to access SOAP Webservice
This is an example to explain how to authenticate java stub client with certification and send request to SOAP WSDL.
public static void applyCertificateAuthentication(MyWsdlDataRequest wsdlClientRequest)
throws Exception {
String keyStoreLocation="resources/keys/testKey.jks";
String password="key@12345";
ClassLoader classLoader = this.class.getClassLoader();
InputStream keyInputStream = classLoader.getResourceAsStream(keyStoreLocation);
SSLContext sc = SSLContext.getInstance("SSLv3");
KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(keyInputStream, password.toCharArray());
factory.init(keyStore, password.toCharArray());
sc.init(factory.getKeyManagers(), null, null);
MyWsdlService serviceImpl = new MyWsdlService ();
MyWsdlDataStub servicePort = serviceImpl.getPort(MyWsdlDataStub .class); BindingProvider bp = (BindingProvider) servicePort;
((BindingProvider) servicePort).getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory",
sc.getSocketFactory());
MyWsdlDataResponse response = servicePort.siSaveSocDataOut(wsdlClientRequest);
}
public static void applyCertificateAuthentication(MyWsdlDataRequest wsdlClientRequest)
throws Exception {
String keyStoreLocation="resources/keys/testKey.jks";
String password="key@12345";
ClassLoader classLoader = this.class.getClassLoader();
InputStream keyInputStream = classLoader.getResourceAsStream(keyStoreLocation);
SSLContext sc = SSLContext.getInstance("SSLv3");
KeyManagerFactory factory = KeyManagerFactory.getInstance(KeyManagerFactory.getDefaultAlgorithm());
KeyStore keyStore = KeyStore.getInstance(KeyStore.getDefaultType());
keyStore.load(keyInputStream, password.toCharArray());
factory.init(keyStore, password.toCharArray());
sc.init(factory.getKeyManagers(), null, null);
MyWsdlService serviceImpl = new MyWsdlService ();
MyWsdlDataStub servicePort = serviceImpl.getPort(MyWsdlDataStub .class); BindingProvider bp = (BindingProvider) servicePort;
((BindingProvider) servicePort).getRequestContext().put("com.sun.xml.internal.ws.transport.https.client.SSLSocketFactory",
sc.getSocketFactory());
MyWsdlDataResponse response = servicePort.siSaveSocDataOut(wsdlClientRequest);
}
Comments
Post a Comment