本文介紹了找不到指向請(qǐng)求的目標(biāo)的有效認(rèn)證路徑的處理方法,對(duì)大家解決問題具有一定的參考價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)吧!
問題描述
我正在使用REST模板發(fā)出POST請(qǐng)求,并收到以下錯(cuò)誤:無法找到指向所請(qǐng)求目標(biāo)的有效證書路徑
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'transformToListClass': Invocation of init method failed; nested exception is java.lang.RuntimeException: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://emploenefitsdev/rion/v1/rion/": 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
Caused by: java.lang.RuntimeException: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://emploenefitsdev/rion/v1/rion/": 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
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on POST request for "https://emploenefitsdev/rion/v1/rion/": 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
Caused by: 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
Caused by: sun.security.validator.ValidatorException: PKIX path building failed: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
和我的方法如下:
public ImageDescriptor generateImage(String payLoad, String templateName, String slogPrefix) {
try {
ImageDescriptor descriptor = new ImageDescriptor();
String myEUrl = "https://emploenefitsdev/rion/v1/rion/";
String eURL = myUrl.concat(Constant.F_SLASH).concat(templateName);
log.info("payload" + payLoad);
ResponseEntity<Resource> responseEntity = restTemplate.exchange(
eURL,
HttpMethod.POST,
niService.getStringHttpEntityWithPayload(payLoad),
Resource.class);
log.info(String.format("%s generateImage Result: [%s] ", slogPrefix, responseEntity.getStatusCode()));
descriptor.setInputStream(Objects.requireNonNull(responseEntity.getBody()).getInputStream());
convert(responseEntity.getBody().getInputStream(), "sherrr.pdf");
log.info("file is:"+ convert(responseEntity.getBody().getInputStream(), "sherrr.pdf"));
return descriptor;
} catch (IOException e) {
e.printStackTrace();
log.error("Error: " + slogPrefix + " generate image failed " + e.getMessage());
throw new RuntimeException(e);
}
}
HTTPS
,因?yàn)槟诮目蛻舳说椒?wù)器的推薦答案連接。握手過程失敗,因?yàn)榭蛻舳诵枰?yàn)證服務(wù)器證書。在客戶端,您需要頒發(fā)者證書(根CA)來驗(yàn)證服務(wù)器證書。大多數(shù)根證書都是JDK中預(yù)先存在的。默認(rèn)情況下,根證書存儲(chǔ)在名為cacerts的密鑰庫文件中。這里,服務(wù)器證書不是由證書頒發(fā)機(jī)構(gòu)頒發(fā)的,服務(wù)器使用的是自簽名證書或由內(nèi)部CA頒發(fā)的證書。您需要將根CA證書添加到Java cacerts密鑰存儲(chǔ)區(qū)。
您可以通過在瀏覽器中訪問服務(wù)器站點(diǎn)來輕松檢索根CA證書。點(diǎn)擊url欄中的安全鎖墊,然后瀏覽證書選項(xiàng)。您需要使用復(fù)制選項(xiàng)導(dǎo)出根CA證書,并將證書文件保存在系統(tǒng)上。
轉(zhuǎn)到cacerts所在的位置eg: C:Program FilesJavajdk1.8.0_121jrelibsecurity
并打開命令提示符以執(zhí)行以下命令。
keytool -import -alias -aliasName -file pathToRootCA.crt -keystore cacerts
密碼為changeit
這篇關(guān)于找不到指向請(qǐng)求的目標(biāo)的有效認(rèn)證路徑的文章就介紹到這了,希望我們推薦的答案對(duì)大家有所幫助,