|
|
@ -68,8 +68,10 @@ public class MetadataTransferAutoConfiguration {
|
|
|
|
DecodeTransferMetadataServletFilter decodeTransferMetadataServletFilter) {
|
|
|
|
DecodeTransferMetadataServletFilter decodeTransferMetadataServletFilter) {
|
|
|
|
FilterRegistrationBean<DecodeTransferMetadataServletFilter> filterRegistrationBean = new FilterRegistrationBean<>(
|
|
|
|
FilterRegistrationBean<DecodeTransferMetadataServletFilter> filterRegistrationBean = new FilterRegistrationBean<>(
|
|
|
|
decodeTransferMetadataServletFilter);
|
|
|
|
decodeTransferMetadataServletFilter);
|
|
|
|
filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE, REQUEST);
|
|
|
|
filterRegistrationBean.setDispatcherTypes(ASYNC, ERROR, FORWARD, INCLUDE,
|
|
|
|
filterRegistrationBean.setOrder(MetadataConstant.OrderConstant.WEB_FILTER_ORDER);
|
|
|
|
REQUEST);
|
|
|
|
|
|
|
|
filterRegistrationBean
|
|
|
|
|
|
|
|
.setOrder(MetadataConstant.OrderConstant.WEB_FILTER_ORDER);
|
|
|
|
return filterRegistrationBean;
|
|
|
|
return filterRegistrationBean;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -140,29 +142,34 @@ public class MetadataTransferAutoConfiguration {
|
|
|
|
BeanPostProcessor encodeTransferMetadataRestTemplatePostProcessor(
|
|
|
|
BeanPostProcessor encodeTransferMetadataRestTemplatePostProcessor(
|
|
|
|
EncodeTransferMedataRestTemplateInterceptor encodeTransferMedataRestTemplateInterceptor) {
|
|
|
|
EncodeTransferMedataRestTemplateInterceptor encodeTransferMedataRestTemplateInterceptor) {
|
|
|
|
// Coping with multiple bean injection scenarios
|
|
|
|
// Coping with multiple bean injection scenarios
|
|
|
|
Map<String, RestTemplate> beans = this.context.getBeansOfType(RestTemplate.class);
|
|
|
|
Map<String, RestTemplate> beans = this.context
|
|
|
|
|
|
|
|
.getBeansOfType(RestTemplate.class);
|
|
|
|
// If the restTemplate has been created when the
|
|
|
|
// If the restTemplate has been created when the
|
|
|
|
// MetadataRestTemplatePostProcessor Bean
|
|
|
|
// MetadataRestTemplatePostProcessor Bean
|
|
|
|
// is initialized, then manually set the interceptor.
|
|
|
|
// is initialized, then manually set the interceptor.
|
|
|
|
if (!CollectionUtils.isEmpty(beans)) {
|
|
|
|
if (!CollectionUtils.isEmpty(beans)) {
|
|
|
|
for (RestTemplate restTemplate : beans.values()) {
|
|
|
|
for (RestTemplate restTemplate : beans.values()) {
|
|
|
|
List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
|
|
|
|
List<ClientHttpRequestInterceptor> interceptors = restTemplate
|
|
|
|
|
|
|
|
.getInterceptors();
|
|
|
|
// Avoid setting interceptor repeatedly.
|
|
|
|
// Avoid setting interceptor repeatedly.
|
|
|
|
if (null != interceptors && !interceptors.contains(encodeTransferMedataRestTemplateInterceptor)) {
|
|
|
|
if (!interceptors.contains(encodeTransferMedataRestTemplateInterceptor)) {
|
|
|
|
interceptors.add(encodeTransferMedataRestTemplateInterceptor);
|
|
|
|
interceptors.add(encodeTransferMedataRestTemplateInterceptor);
|
|
|
|
restTemplate.setInterceptors(interceptors);
|
|
|
|
restTemplate.setInterceptors(interceptors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return new EncodeTransferMetadataRestTemplatePostProcessor(encodeTransferMedataRestTemplateInterceptor);
|
|
|
|
return new EncodeTransferMetadataRestTemplatePostProcessor(
|
|
|
|
|
|
|
|
encodeTransferMedataRestTemplateInterceptor);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
|
|
|
public void setApplicationContext(ApplicationContext applicationContext)
|
|
|
|
|
|
|
|
throws BeansException {
|
|
|
|
this.context = applicationContext;
|
|
|
|
this.context = applicationContext;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static class EncodeTransferMetadataRestTemplatePostProcessor implements BeanPostProcessor {
|
|
|
|
public static class EncodeTransferMetadataRestTemplatePostProcessor
|
|
|
|
|
|
|
|
implements BeanPostProcessor {
|
|
|
|
|
|
|
|
|
|
|
|
private EncodeTransferMedataRestTemplateInterceptor encodeTransferMedataRestTemplateInterceptor;
|
|
|
|
private EncodeTransferMedataRestTemplateInterceptor encodeTransferMedataRestTemplateInterceptor;
|
|
|
|
|
|
|
|
|
|
|
@ -180,9 +187,10 @@ public class MetadataTransferAutoConfiguration {
|
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName) {
|
|
|
|
public Object postProcessAfterInitialization(Object bean, String beanName) {
|
|
|
|
if (bean instanceof RestTemplate) {
|
|
|
|
if (bean instanceof RestTemplate) {
|
|
|
|
RestTemplate restTemplate = (RestTemplate) bean;
|
|
|
|
RestTemplate restTemplate = (RestTemplate) bean;
|
|
|
|
List<ClientHttpRequestInterceptor> interceptors = restTemplate.getInterceptors();
|
|
|
|
List<ClientHttpRequestInterceptor> interceptors = restTemplate
|
|
|
|
|
|
|
|
.getInterceptors();
|
|
|
|
// Avoid setting interceptor repeatedly.
|
|
|
|
// Avoid setting interceptor repeatedly.
|
|
|
|
if (null != interceptors && !interceptors.contains(encodeTransferMedataRestTemplateInterceptor)) {
|
|
|
|
if (!interceptors.contains(encodeTransferMedataRestTemplateInterceptor)) {
|
|
|
|
interceptors.add(this.encodeTransferMedataRestTemplateInterceptor);
|
|
|
|
interceptors.add(this.encodeTransferMedataRestTemplateInterceptor);
|
|
|
|
restTemplate.setInterceptors(interceptors);
|
|
|
|
restTemplate.setInterceptors(interceptors);
|
|
|
|
}
|
|
|
|
}
|
|
|
|