I need to write my own class to tell mule that https connection to service (wsdl) is verified. I already have mule project nearly finnished but last piece is missing, sending file at specific url.
What I want to achieve:
establish connection and send xml to target url
read response that is also in xml
Server uses security with self signed certificate. What I did so far was that I got cert from that link and imported it in .jks. Then I followed probably all "tutorials" how to connect to server in mule with https connector but nothing worked in my case.
I think that the best thing would be if someone can help me create java class to bypass key checking and return true (as verified). Something like:
URL url = new URL("https://www.google.com");
HttpsURLConnection conn= (HttpsURLConnection) url.openConnection();
conn.setHostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String arg0, SSLSession arg1) {
return true;
}
});
How can I do that in mule? I expect that it would be something like this.
I am using current mule version (3.5.0)
Thank you!
EDIT:
My configuration:
解决方案
What worked for me is to set the TrustManagerFactory on the HTTPS connector. Here's how I did it.
First, create a keystore that contains the certificate of the SSL server you want to trust. You can create the keystore using the tools included with the JDK (here's an example).
Then, create a FactoryBean that gives you a TrustManagerFactory given a JKS keystore and password. Here's one I made that uses a Spring resource, so that I can provide the keystore from the classpath or from the filesystem:
public class ExampleFactoryBean implements FactoryBean {
private Resource keystore;
private String password;
@Override
public TrustManagerFactory getObject() throws Exception {
KeyStore truststore = KeyStore.getInstance("JKS");
truststore.load(keystore.getInputStream(), password.toCharArray());
TrustManagerFactory tmf = TrustManagerFactory.getInstance("SunX509");
tmf.init(truststore);
return tmf;
}
@Override
public Class> getObjectType() {
return TrustManagerFactory.class;
}
@Override
public boolean isSingleton() {
return true;
}
public void setKeystore(Resource keystore) {
this.keystore = keystore;
}
public void setPassword(String password) {
this.password = password;
}
}
Finally, set the TrustManagerFactory on the HTTP connector like so: