Can I add some requestinterceptors to a specific feignclient?
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 9.8k
- Forks
- 1.9k
- Avg merge
- 1d 2h
- Merged PRs (30d)
- 41
Description
I want add some requestinterceptors to a specific feignclient,those requestinterceptors only works for feign1,but not work for feign2.
can RequestInterceptor add an method to decide whether to add the interceptor to feignclient when the system is running?
now i do it works as follows。
public interface MyRequestInterceptor extends RequestInterceptor {
boolean ignore(String feignName);
}
public class GreyFeignIntercepter implements MyRequestInterceptor {
@Override
public boolean ignore(String feignName) {
return "my-service".equals(feignName);
}
}
replace TraceFeignContext。
public class TraceFeignContext extends FeignContext{
public TraceFeignObjectWrapper traceFeignObjectWrapper;
public FeignContext delegate;
TraceFeignContext(TraceFeignObjectWrapper traceFeignObjectWrapper, FeignContext delegate) {
this.delegate = delegate;
this.traceFeignObjectWrapper = traceFeignObjectWrapper;
}
@Override
public <T> T getInstance(String name, Class<T> type) {
T object = this.delegate.getInstance(name, type);
return (T) this.traceFeignObjectWrapper.wrap(object);
}
@Override
public <T> Map<String, T> getInstances(String name, Class<T> type) {
Map<String, T> instances = this.delegate.getInstances(name, type);
if (instances == null) {
return null;
} else {
Map<String, T> convertedInstances = new HashMap();
Iterator var5 = instances.entrySet().iterator();
while(var5.hasNext()) {
Map.Entry<String, T> entry = (Map.Entry)var5.next();
if(!(entry.getValue() instanceof MyRequestInterceptor) || !((MyRequestInterceptor) entry.getValue()).ignore(name)){
convertedInstances.put(entry.getKey(), (T) this.traceFeignObjectWrapper.wrap(entry.getValue()));
}
}
return convertedInstances;
}
}
}
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by reading the RequestInterceptor contract and the FeignContext getInstances path shown in the issue, then trace how interceptors are selected for each named client. The change would be complete when an interceptor can be applied to one named Feign client without a replacement context wrapper, with behavior verified for both matching and non-matching clients.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100