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);

    }

Popular posts from this blog

Can not connect to git using ssh (Permissions 0644 for '/root/.ssh/id_rsa' are too open.

Upload file on Google cloud storage using Java servlet on google app engine

Create Nested table inside a table on a pdf document using iText