OpenFeign / OpenFeign/feign

Can I add some requestinterceptors to a specific feignclient?

Open
#1,731 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feedback provided needs info
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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.