Java PKIX路径生成失败:从自签名到自签名的API调用
我正在尝试从具有自签名证书的主机向具有自签名证书的另一台主机发出GET请求:Java PKIX路径生成失败:从自签名到自签名的API调用,java,spring-boot,Java,Spring Boot,我正在尝试从具有自签名证书的主机向具有自签名证书的另一台主机发出GET请求: @GetMapping(path = "devices") public ResponseEntity<String> getDevices(HttpServletRequest request) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException { url = &
@GetMapping(path = "devices")
public ResponseEntity<String> getDevices(HttpServletRequest request) throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException {
url = "https://someurl:8448/device-data";
return get(url);
}
private ResponseEntity<String> get(String url) {
RestTemplate restTemplate = new RestTemplate();
try {
HttpHeaders headers = new HttpHeaders();
headers.add("Content-Type", "application/json");
HttpEntity<String> entity = new HttpEntity<String>(headers);
return restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
} catch (Exception e) {
logger.error("Failed to send GET " + url, e);
}
return null;
}
我调用的API必须是自签名的,因为它是动态内部IP。
您知道如何调用此API并跳过自签名/证书问题吗?我相信这就是您想要的(标准免责声明,在生产环境中这样做不安全)
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:439)
at java.base/sun.security.validator.PKIXValidator.engineValidate(PKIXValidator.java:306)
at java.base/sun.security.validator.Validator.validate(Validator.java:264)