RestTemplate远程调用服务忽略异常,获取HttpStatus状态码,关闭证书验证

@Bean

RestTemplaterestTemplate(){

RestTemplate restTemplate=new RestTemplate();

  restTemplate.setErrorHandler(new ResponseErrorHandler() {

@Override

      public boolean hasError(ClientHttpResponse response)throws IOException {

return false;

      }

@Override

      public void handleError(ClientHttpResponse response)throws IOException {

}

});

  OkHttpClient okHttpClient=new OkHttpClient.Builder().hostnameVerifier(

(s, sslSession) ->true

  ).build();

  OkHttp3ClientHttpRequestFactory factory=new OkHttp3ClientHttpRequestFactory(okHttpClient);

  factory.setConnectTimeout(60*1000);

  factory.setReadTimeout(60*1000);

  factory.setWriteTimeout(60*1000);

  restTemplate.setRequestFactory(factory);

  return restTemplate;

}

你可能感兴趣的:(RestTemplate远程调用服务忽略异常,获取HttpStatus状态码,关闭证书验证)