Soap SSL handshake

12,445

Solution 1

This line of code will not work in case of SSL.

SOAPMessage soapMessageResponse = connection.call(soapRequest, new URL(serviceLocation));

Create trustmanager and keymanagers from here.

In order to get response through SSL from axis2 webservice you need to open streams like given here

Solution 2

I'm pretty sure it will use the default SSLContext. You can change that with SSLContext.setDefault().

SSLContext c = SSLContext.getInstance("SSL");
TrustManagerFactory tmf = TrustManagerFactory.getInstance("PKIX");
tmf.init(yourKeystore);
TrustManager tm = tmf.getTrustManagers()[0];
tm.
c.init(null, tm, null);

Here are some other values for the string parameters above.

If you need more complete control, you can implement your own subclass of SSLContext which returns your own implementation of SSLSocketFactory and set that SSLContext as the default:

public class MySSLContext extends SSLContext {

    private SSLContext wrapped;
    private SSLSocketFactory mySocketFactory;

    public MySSLContext(SSLContext toWrap, SSLSocketFactory mySocketFactory) {
        wrapped = toWrap;
        this.mySocketFactory = mySocketFactory;
    }

    public SSLSocketFactory getSocketFactory() {
        return mySocketFactory;
    }

    public SSLSessionContext getClientSessionContext() {
        return wrapped;
    }

    // other delegates

}
Share:
12,445
Muhammad Imran Tariq
Author by

Muhammad Imran Tariq

I am a passionate Senior Software Engineer. Majorly work in Java and BigData. I completed my masters degree in computer science and since then I developed various business application on different domains including financial systems, digitalsignage, security etc. I am also a good web developer and worked on different websites such as blogs, shopping carts. I have good understanding of programming languages and software development pros and cons.

Updated on June 25, 2022

Comments

  • Muhammad Imran Tariq
    Muhammad Imran Tariq almost 2 years

    My client is successfully getting response from server through HTTP.

    SOAPConnectionFactory sfc = SOAPConnectionFactory.newInstance();
    SOAPConnection connection = sfc.createConnection();
    
    SOAPMessage soapMessageResponse = connection.call(soapRequest, new URL(serviceLocation));
    

    I want SSL communication between client/server.

    In another project I am successfully creating SSLSocketFactory from a KeyStore and TrustManagerFactory for SSL handshake.

    How can I use SSLSocketFactory code in webservice client to make client SSL communication successful to call server.