Reputation: 31
I am building a service that talks to multiple devices using SOAP over https. These devices expose the same webservice API (same wsdl). New devices can be added to this scheme any time at runtime.
I need to dynamically query each of these devices and any that may be added in the future. Each of these devices have a self signed certificate for ssl. The service that I am building needs to be implemented using Spring Integration.
Given the above I have two main questions:
Any help would be greatly appreciated.
Upvotes: 2
Views: 718
Reputation: 31
Thanks for your help Gary and Artem.
I was able to solve the problem of dynamic uri with a thread local variable and and SPEL.
For the trust of self signed certs, I implemented and new message-sender using the httpclient. HttpClient provides a TrustSelfSignedStrategy. I used this to trust all self signed certs. The solutions seems to be working. Following is the code if anyone has similar needs in the future.
KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType());
InputStream instream = getClass().getResourceAsStream(trustStoreFile);
try {
trustStore.load(instream, trustStorePassword.toCharArray());
} finally {
instream.close();
}
SSLContextBuilder builder = new SSLContextBuilder();
builder.loadTrustMaterial(trustStore, new TrustSelfSignedStrategy());
SSLContext sslcontext = builder.build();
SSLConnectionSocketFactory sslsf = new SSLConnectionSocketFactory(sslcontext,SSLConnectionSocketFactory.ALLOW_ALL_HOSTNAME_VERIFIER);
HttpClientBuilder httpClientBuilder = HttpClients.custom();
httpClientBuilder.setSSLSocketFactory(sslsf);
httpClientBuilder.addInterceptorFirst(new RemoveSoapHeadersInterceptor());
if (credentials!=null){
CredentialsProvider credsProvider = new BasicCredentialsProvider();
credsProvider.setCredentials(AuthScope.ANY,credentials);
httpClientBuilder.setDefaultCredentialsProvider(credsProvider);
}
CloseableHttpClient closeableHttpclient = httpClientBuilder.build();
setHttpClient(closeableHttpclient);
Upvotes: 1
Reputation: 174769
The first question is easy; see the XSD documentation:
The Destination URI for this Web Service Gateway. If the URI should be determined at runtime
(e.g. registry lookup), then configure a 'destination-provider' reference instead. Aternatively,
this URI may include {placeholders} whose values are determined by evaluating SpEL expressions
provided via 'uri-variable' sub-elements. The root object for those evaluations is the actual
request Message at runtime, i.e. you can access its payload or headers in the expression.
and the documentation about URI placeholders.
I don't know if you can dynamically add keys/certs to the keystore/truststore at runtime; I've never tried.
Upvotes: 0