-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCatcherFeignClientCommonConfig.java
More file actions
31 lines (24 loc) · 1.1 KB
/
CatcherFeignClientCommonConfig.java
File metadata and controls
31 lines (24 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
package com.catcher.batch.external.config;
import com.catcher.batch.core.converter.CatcherConverter;
import feign.RequestInterceptor;
import feign.ResponseInterceptor;
import feign.Util;
import org.springframework.context.annotation.Bean;
import org.springframework.http.HttpHeaders;
import org.springframework.http.MediaType;
public class CatcherFeignClientCommonConfig {
public static final String APPLICATION_FORM_URLENCODED_UTF8_VALUE =
MediaType.APPLICATION_FORM_URLENCODED_VALUE + ";charset=utf-8";
@Bean
public RequestInterceptor requestInterceptor() {
return requestTemplate -> requestTemplate.header(HttpHeaders.CONTENT_TYPE, APPLICATION_FORM_URLENCODED_UTF8_VALUE);
}
@Bean
public ResponseInterceptor responseInterceptor(CatcherConverter catcherConverter) {
return invocationContext -> {
Class<?> responseType = (Class<?>) invocationContext.returnType();
String responseBody = Util.toString(invocationContext.response().body().asReader());
return catcherConverter.parse(responseBody, responseType);
};
}
}