@Configuration
public class FeginInterceptor implements RequestInterceptor {
@Override
public void apply(RequestTemplate requestTemplate) {
try {
Map<String,String> headers = getHeaders();
for(String headerName : headers.keySet()){
requestTemplate.header(headerName, headers.get(headerName));
}
}catch (Exception e){
e.printStackTrace();
}
}
private Map<String, String> getHeaders(){
HttpServletRequest request = ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
Map<String, String> map = new LinkedHashMap<>();
Enumeration<String> enumeration = request.getHeaderNames();
while (enumeration.hasMoreElements()) {
String key = enumeration.nextElement();
String value = request.getHeader(key);
map.put(key, value);
}
return map;
}
}