When I updated the version of Spring to 3.4.3, we received a PKIX error, although we set TrustAllStrategy
.
We sending request with getWebServiceTemplate().marshalSendAndReceive(url, request, soapAction)
;
This error comes with change from HttpComponentsMessageSender
to HttpComponents**5**MessageSender
.
... 71 common frames omitted
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:388)
at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:271)
at java.base/sun.security.validator.Validator.validate(Validator.java:256)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkTrusted(X509TrustManagerImpl.java:230)
at java.base/sun.security.ssl.X509TrustManagerImpl.checkServerTrusted(X509TrustManagerImpl.java:132)
at java.base/sun.security.ssl.CertificateMessage$T12CertificateConsumer.checkServerCerts(CertificateMessage.java:635)
... 117 common frames omitted
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at java.base/sun.security.provider.certpath.SunCertPathBuilder.build(SunCertPathBuilder.java:148)
at java.base/sun.security.provider.certpath.SunCertPathBuilder.engineBuild(SunCertPathBuilder.java:129)
at java.base/java.security.cert.CertPathBuilder.build(CertPathBuilder.java:297)
at java.base/sun.security.validator.PKIXValidator.doBuild(PKIXValidator.java:383)
... 122 common frames omitted
@Value("${foo}")
private Resource foo;
@Bean
public HttpComponents5MessageSender httpComponents5MessageSender() throws Exception {
HttpComponents5MessageSender httpComponents5MessageSender =
new HttpComponents5MessageSender();
httpComponents5MessageSender.setConnectionTimeout(Duration.ofMillis(timeout));
httpComponents5MessageSender.setReadTimeout(Duration.ofMillis(timeout));
httpComponents5MessageSender.setHttpClient(httpClient());
return httpComponents5MessageSender;
}
public HttpClient httpClient() throws Exception {
KeyStore keyStore = KeyStore.getInstance("PKCS12");
keyStore.load(foo.getInputStream(), "1111".toCharArray());
SSLContext sslContext =
SSLContexts.custom().loadKeyMaterial(keyStore, "1111".toCharArray())
.loadTrustMaterial(new TrustAllStrategy()).build();
DefaultClientTlsStrategy socketFactory =
new DefaultClientTlsStrategy(sslContext);
HttpClientConnectionManager connectionManager =
PoolingHttpClientConnectionManagerBuilder.create()
.setTlsSocketStrategy(socketFactory).build();
HttpClient httpClient = HttpClientBuilder.create()
.setConnectionManager(connectionManager)
.addRequestInterceptorFirst(new RemoveSoapHeadersInterceptor()).build();
return httpClient;
}
@Bean
public Jaxb2Marshaller sendSmsClientNewMarshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this package must match the package in the <generatePackage> specified in
// pom.xml
marshaller.setContextPath("example.model");
return marshaller;
}
@Bean
public ClientNew sendSmsClientNewClient(Jaxb2Marshaller sendSmsClientNewMarshaller)
throws Exception {
ClientNew client = new ClientNew();
//client.setDefaultUri("http://example");
client.setMarshaller(sendSmsClientNewMarshaller);
client.setUnmarshaller(sendSmsClientNewMarshaller);
client.setMessageSender(httpComponents5MessageSender());
return client;
}
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1744787396a4593710.html
评论列表(0条)