Spring Boot-调用另一个需要证书的Web服务

时间:2018-08-25 17:30:04

标签: spring-boot

我有一个Spring Boot rest服务,该服务可以调用另一个Web服务(用.NET编写),但是需要安装该Web服务的服务器的公共证书。

我遇到以下错误:

org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://domain.sample.com/api/message.asmx": sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target; nested exception is javax.net.ssl.SSLHandshakeException: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target

Process finished with exit code -1

虽然不确定是否可以使用RestTemplate调用.asmx Web服务,但这是我的代码:

RestTemplate restTemplate = new RestTemplate();

HttpHeaders httpHeaders = new HttpHeaders();
httpHeaders.setContentType(MediaType.TEXT_XML);

HttpEntity<String> entity = new HttpEntity<>(rawDeviceMessage, httpHeaders);

ResponseEntity<String> resultEntity = restTemplate.postForEntity("https://domain.sample.com/api/message.asmx", entity, String.class);

1 个答案:

答案 0 :(得分:-2)

如@Mustafa在上面的评论部分中所述,以下内容重复,并且问题已解决。

Exception unable to validate certificate of the target in spring MVC