gpt4 book ai didi

web-services - 具有动态 uri 的 spring 集成出站 web 服务网关并信任所有证书

转载 作者:太空宇宙 更新时间:2023-11-03 13:03:48 25 4
gpt4 key购买 nike

我正在构建一个使用 SOAP over https 与多个设备通信的服务。这些设备公开相同的网络服务 API(相同的 wsdl)。可以在运行时随时将新设备添加到该方案中。

我需要动态查询这些设备中的每一个以及将来可能添加的任何设备。这些设备中的每一个都有一个用于 ssl 的自签名证书。我正在构建的服务需要使用 Spring Integration 来实现。

鉴于以上,我有两个主要问题:

  1. 在 Spring Integration 中,我如何在运行时动态分配服务 uri。
  2. 我如何信任所有证书。

如有任何帮助,我们将不胜感激。

最佳答案

感谢 Gary 和 Artem 的帮助。

我能够使用线程局部变量和 SPEL 解决动态 uri 的问题。

为了信任自签名证书,我使用 httpclient 实现了新的消息发送器。 HttpClient 提供了一个 TrustSelfSignedStrategy。我用它来信任所有自签名证书。解决方案似乎有效。代码如下,以后有类似需求的 friend 可以引用。

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

关于web-services - 具有动态 uri 的 spring 集成出站 web 服务网关并信任所有证书,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24536998/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com