문서의 선택한 두 판 사이의 차이를 보여줍니다.
| 양쪽 이전 판 이전 판 다음 판 | 이전 판 | ||
|
springframework:resttemplate [2015/09/21 11:30] kwon37xi |
springframework:resttemplate [2022/01/14 15:43] (현재) kwon37xi |
||
|---|---|---|---|
| 줄 2: | 줄 2: | ||
| * [[https:// | * [[https:// | ||
| * [[http:// | * [[http:// | ||
| + | * [[http:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * see [[springframework: | ||
| ===== HttpEntity ===== | ===== HttpEntity ===== | ||
| 줄 32: | 줄 36: | ||
| </ | </ | ||
| + | ===== 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:// | ||
| + | // ClientHttpRequestInterceptor 인터페이스를 로깅을 남기게 구현해서 넣어주면 된다. | ||
| + | |||
| + | RestTemplate restTemplate = new RestTemplate(); | ||
| + | restTemplate.setRequestFactory(new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())); | ||
| + | restTemplate.setInterceptors(Lists.newArrayList(new RestTemplateLoggingInterceptor())); | ||
| + | </ | ||
| + | |||
| + | ===== SpringBoot ===== | ||
| + | * with [[springframework: | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | * '' | ||
| + | |||
| + | <code java> | ||
| + | @Bean | ||
| + | public RestTemplate restTemplate(RestTemplateBuilder restTemplateBuilder) { | ||
| + | return restTemplateBuilder | ||
| + | .requestFactory(() -> new BufferingClientHttpRequestFactory(new SimpleClientHttpRequestFactory())) | ||
| + | .setConnectTimeout(Duration.ofMillis(5000)) // connection-timeout | ||
| + | .setReadTimeout(Duration.ofMillis(5000)) // read-timeout | ||
| + | .additionalMessageConverters(new StringHttpMessageConverter(Charset.forName(" | ||
| + | .build(); | ||
| + | } | ||
| + | </ | ||
| + | |||
| + | ===== 참조 ===== | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||
| + | * [[https:// | ||