0

I have a Spring Boot rest service that would call another web service (written in .NET) but it requires a public certificate of that server where the web service is installed.

I am getting the following error:

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

Not sure if you can call .asmx web service using RestTemplate though but this is my code:

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);
dellboy
  • 95
  • 2
  • 10
  • Did you add the .Net server's public key to your server's truststore? If your service doesn't use a trusted certificate you'll need to add it manually to your truststore. – Mustafa Aug 25 '18 at 18:41
  • Possible duplicate of [Exception unable to validate certificate of the target in spring MVC](https://stackoverflow.com/questions/32051596/exception-unable-to-validate-certificate-of-the-target-in-spring-mvc) – Mustafa Aug 25 '18 at 18:47
  • Hi @Mustafa, thank you for this. I will check this out and get back to you. – dellboy Aug 26 '18 at 16:52

1 Answers1

-2

As mentioned by @Mustafa in the comment section above, the following was a duplicate and the issue got resolved.

Exception unable to validate certificate of the target in spring MVC

dellboy
  • 95
  • 2
  • 10