First strike: Self-signed certificate
When certificate if self signed it definetely not reliable. Bu it is very common in testing code. I had to get it somehow to make it trusted.openssl s_client -connect 172.16.3.1:8243 | sed -ne '/-BEGIN CERTIFICATE-/,/-END CERTIFICATE-/p' > /tmp/certname.certCertificate must be added to keystore:
C:\jdk1.7.0\bin>keytool -import -trustcacerts -keystore cccc -storepass secretpassword -noprompt -file c:\tmp\certificate.certCertificate was added to keystoreTo inform the java to set certificates during runtime:
System.setProperty("javax.net.ssl.trustStore","C:\\jdk1.7.0\\bin\\cccc"); System.setProperty("javax.net.ssl.trustStorePassword", "secretpassword");
Second strike: Missing class?
Really I don't understand this error but I had to deal with this. Somebody found out that this class can be implemented with little help of jsslUtuils which is fortunately LGPL.PKIXSSLContextFactory sslContextFactory = new PKIXSSLContextFactory();
sslContextFactory.setTrustManagerWrapper(new X509TrustManagerWrapper() {
@Override
public X509TrustManager wrapTrustManager(final X509TrustManager origManager) {
return new X509TrustManager() {
@Override
public X509Certificate[] getAcceptedIssuers() {
return origManager.getAcceptedIssuers();
}
@Override
public void checkServerTrusted(X509Certificate[] chain,
String authType)
throws CertificateException {
try {
origManager.checkServerTrusted(chain, authType);
} catch (CertificateExpiredException e) {
// TODO log or do something else to rethrow
// the exception if chain[0] isn't the certificate
// for which you want to make this special case.
}
}
@Override
public void checkClientTrusted(X509Certificate[] chain,
String authType)
throws CertificateException {
origManager.checkClientTrusted(chain, authType);
}
};
}
});
SSLContext sslContext = sslContextFactory.buildSSLContext();
SSLContext.setDefault(sslContext);
Final encounter: Wrong address
We need to disable another check to make it happen:
TLSClientParameters tlsParams = new TLSClientParameters();Yeah! We finally can consume the service.
tlsParams.setDisableCNCheck(true);
Client client2 = ClientProxy.getClient(service);
HTTPConduit http = (HTTPConduit) client2.getConduit();
http.setTlsClientParameters(tlsParams);
Epilogue
If service serve unexpected elements You can disable validation:Services sh= new Services(new URL("http://172.16.5.3:8080/axis2/services/Services?wsdl"));
ServicesPortType port = sh.getServicesHttpSoap11Endpoint();java.util.Map<String, Object> requestContext = ((javax.xml.ws.BindingProvider)
port).getRequestContext();
requestContext.put("set-jaxb-validation-event-handler", "false");
End of transmission



