简体   繁体   English

无法在 spring rest 模板客户端中找到请求目标的有效认证路径

[英]Unable to find valid certification path to requested target in spring rest template client

I am getting我正进入(状态

Exception in thread "main" org.springframework.web.client.ResourceAccessException线程“main” org.springframework.web.client.ResourceAccessException 中的异常

for the following program:对于以下程序:

private static String       url    = "https://localhost:8080/ipn";
public static void main( String[] args )
{
    HttpHeaders headers = new HttpHeaders();
    headers.add( "Accept", "application/json" );
    headers.setContentType( MediaType.APPLICATION_JSON );
    HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
    DefaultHttpClient httpClient = (DefaultHttpClient) requestFactory.getHttpClient();

    RestTemplate restTemplate = new RestTemplate( requestFactory );
    requestChange( headers, restTemplate );
}

private static void requestChange( HttpHeaders inHeaders, RestTemplate inRestTemplate )
{
    Map<String, String> params = new HashMap<String, String>();

    params.put( "PresentmentCurrencyCode", "INR" );
    params.put( "SettlementCurrencyCode", "INR" );
    HttpEntity<String> request = new HttpEntity<String>( inHeaders );
    ResponseEntity<String> response = inRestTemplate.exchange( url, HttpMethod.GET, request, String.class, params );
    System.out.println( response.toString() );
}

I am getting the following error while access the url in spring rest template client.在 spring rest 模板客户端中访问url时出现以下错误。

Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://xmlservice-stg03extf.symantec.com/SymWalletServices/PayPalListner/ipn":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
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:503)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:459)
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:408)
at com.np.symantec.ChargeBackClient.requestChargeBack(ChargeBackClient.java:94)
at com.np.symantec.ChargeBackClient.main(ChargeBackClient.java:74)
    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
at com.sun.net.ssl.internal.ssl.Alerts.getSSLException(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.fatal(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.fatalSE(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.serverCertificate(Unknown Source)
at com.sun.net.ssl.internal.ssl.ClientHandshaker.processMessage(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.processLoop(Unknown Source)
at com.sun.net.ssl.internal.ssl.Handshaker.process_record(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.readRecord(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at com.sun.net.ssl.internal.ssl.SSLSocketImpl.startHandshake(Unknown Source)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:543)
at org.apache.http.conn.ssl.SSLSocketFactory.connectSocket(SSLSocketFactory.java:409)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:177)
at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:88)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:46)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:49)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:488)
... 4 more
    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 sun.security.validator.PKIXValidator.doBuild(Unknown Source)
at sun.security.validator.PKIXValidator.engineValidate(Unknown Source)
at sun.security.validator.Validator.validate(Unknown Source)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.validate(Unknown Source)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
at com.sun.net.ssl.internal.ssl.X509TrustManagerImpl.checkServerTrusted(Unknown Source)
... 25 more
    Caused by: sun.security.provider.certpath.SunCertPathBuilderException: unable to find valid certification path to requested target
at sun.security.provider.certpath.SunCertPathBuilder.engineBuild(Unknown Source)
at java.security.cert.CertPathBuilder.build(Unknown Source)
... 31 more

It seems that your client does not trust the resource you are calling.您的客户似乎不信任您正在调用的资源。 You will have to import the public key of your target resource您必须导入目标资源的公钥

There may be typo error for localhost spelling localhost拼写可能有拼写错误

Try changing it as below:尝试改变它如下:

private static String url = " https://localhost:8080/ipn ";私有静态字符串 url = " https://localhost:8080/ipn ";

You don't appear to have set an SSL context anywhere, so your app doesn't know how to validate the https connection you've made.您似乎没有在任何地方设置 SSL 上下文,因此您的应用程序不知道如何验证您建立的 https 连接。

You need to set it when you initialise your httpClient, for example:您需要在初始化 httpClient 时对其进行设置,例如:

socketFactory = new SSLConnectionSocketFactory(sslContext);
httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).build();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 REST 客户端调用失败并显示“SunCertPathBuilderException:无法找到到请求目标的有效认证路径” - REST client call fails with "SunCertPathBuilderException: unable to find valid certification path to requested target" 调用Rest Client呼叫WSO2 ESB服务:无法找到到所请求目标的有效认证路径 - Invoking Rest Client to call WSO2 ESB Service :unable to find valid certification path to requested target 无法找到到请求目标的有效证书路径 - unable to find valid certification path to requested target 无法找到到请求目标的有效证书路径 - unable to find a valid certification path to requested target Spring LDAP TLS / SSL异常:PKIX路径构建失败:无法找到到请求目标的有效证书路径 - Spring LDAP TLS / SSL Exception: PKIX path building failed: unable to find valid certification path to requested target Java证书客户端SSL:无法找到到请求目标的有效证书路径 - Java Certificate Client SSL: unable to find valid certification path to requested target Web客户端应用程序收到“无法找到请求的目标的有效证书路径” - Web Client Application receives a “unable to find valid certification path to requested target” 如何强制客户端信任PKCS12证书(无法找到到请求目标的有效证书路径)? - How to force client trusting in PKCS12 certificate(unable to find valid certification path to requested target)? gradlew 无法找到请求目标的有效认证路径 - gradlew unable to find valid certification path to requested target 突然“无法找到到请求目标的有效认证路径” - Sudden "unable to find valid certification path to requested target"
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM