Spring boot, SOAP, with HttpComponents5MessageSender get soapjavax.net.ssl.SSLHandshakeException: (certificate_unknown) PKIX - S

When I updated the version of Spring to 3.4.3, we received a PKIX error,although we set TrustAllStrat

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

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信