您的配置必须与 https-sample 有所不同。您必须在 Citrus SOAP Web 服务客户端上设置消息发送方:
<bean class="com.consol.citrus.samples.todolist.config.SoapClientSslConfig"/>
<citrus-ws:client id="todoClient"
request-url="https://localhost:8443"
message-sender="sslRequestMessageSender"/>
证书是在 http 客户端 SSL 上下文中配置的。
@Configuration
public class SoapClientSslConfig {
@Bean
public HttpClient httpClient() {
try {
SSLContext sslcontext = SSLContexts.custom()
.loadTrustMaterial(new ClassPathResource("keys/citrus.jks").getFile(), "secret".toCharArray(),
new TrustSelfSignedStrategy())
.build();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(
sslcontext, NoopHostnameVerifier.INSTANCE);
return HttpClients.custom()
.setSSLSocketFactory(sslSocketFactory)
.setSSLHostnameVerifier(NoopHostnameVerifier.INSTANCE)
.addInterceptorFirst(new HttpComponentsMessageSender.RemoveSoapHeadersInterceptor())
.build();
} catch (IOException | CertificateException | NoSuchAlgorithmException | KeyStoreException | KeyManagementException e) {
throw new BeanCreationException("Failed to create http client for ssl connection", e);
}
}
@Bean
public HttpComponentsMessageSender sslRequestMessageSender() {
return new HttpComponentsMessageSender(httpClient());
}
}
示例代码现在也可以在 github 上找到:https ://github.com/christophd/citrus-samples/tree/master/sample-soap-ssl