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

时间:2016-01-12 13:11:46

标签: java spring rest security ssl

我正在

  

线程“main”中的异常org.springframework.web.client.ResourceAccessException

以下程序:

var

访问spring rest template client中的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() ); } 时出现以下错误。

url

3 个答案:

答案 0 :(得分:1)

localhost 拼写可能会出现拼写错误

尝试按以下方式更改它:

private static String url =&#34; https://localhost:8080/ipn&#34;;

答案 1 :(得分:1)

您的客户似乎不信任您呼叫的资源。您必须导入目标资源的公钥

答案 2 :(得分:0)

您似乎没有在任何地方设置SSL上下文,因此您的应用程序不知道如何验证已建立的https连接。

您需要在初始化httpClient时进行设置,例如:

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