RequestInterceptor是feign的拦截器,可以拦截请求,我们可以往请求里放一下公共参数,例如请求头等。
不废话,直接上代码
public class WpsAuthFeignInterceptor implements RequestInterceptor {
private static final String[] PASS_PATHS = {"/open","/o/oauth","/graph"};
@Override
public void apply(RequestTemplate template) {
String path = template.url();
WpsCompanyPathMappingDTO mappingDTO = pathMappingReqInfo(path);
// open不参与签名,做替换处理
for (String passPath : PASS_PATHS) {
if (path.startsWith(passPath)) {
path = path.replace(passPath, "");
break;
}
}
template.header(WpsSignatureUtil.WPS_AUTHORIZATION_HEADER, bearerToken);
}
}