문서의 선택한 두 판 사이의 차이를 보여줍니다.
양쪽 이전 판 이전 판 다음 판 | 이전 판 다음 판 양쪽 다음 판 | ||
springframework:resttemplate [2015/09/21 11:30] kwon37xi |
springframework:resttemplate [2018/03/09 14:36] kwon37xi |
||
---|---|---|---|
줄 32: | 줄 32: | ||
</ | </ | ||
+ | ===== Exception 처리 ===== | ||
+ | * [[https:// | ||
+ | <code java> | ||
+ | public class MyErrorHandler implements ResponseErrorHandler { | ||
+ | @Override | ||
+ | public void handleError(ClientHttpResponse response) throws IOException { | ||
+ | // your error handling here | ||
+ | } | ||
+ | |||
+ | @Override | ||
+ | public boolean hasError(ClientHttpResponse response) throws IOException { | ||
+ | // ... | ||
+ | } | ||
+ | } | ||
+ | |||
+ | // [...] | ||
+ | |||
+ | public static void main(String args[]) { | ||
+ | RestTemplate restTemplate = new RestTemplate(); | ||
+ | restTemplate.setErrorHandler(new MyErrorHandler()); | ||
+ | } | ||
+ | </ | ||
+ | * 기본 구현체인 [[https:// | ||
+ | |||
+ | ===== Interceptor를 통한 로깅 ===== | ||
+ | * [[http:// | ||
+ | |||
+ | RestTemplate restTemplate = new RestTemplate(); | ||
+ | restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); | ||
+ | restTemplate.setInterceptors(Lists.newArrayList(new RestTemplateLoggingInterceptor())); | ||
+ | </ | ||