feign icon indicating copy to clipboard operation
feign copied to clipboard

Allow to ignore methods on provided interface

Open dmarkhas opened this issue 6 years ago • 13 comments

When the Feign annotated interface (or class passed to the builder) contains methods that are not intended to be invoked by a web request (i.e. not annotated with RequestMapping), Feign (actually the BaseContract) throws an exception saying the method is not annotated with HTTP method type.

While this is legitimate, I'd like to request an enhancement to allow the contract to ignore methods on demand (kinda like it ignores static methods), for example via some annotation ("@FeignIgnore"?).

The motivation for this is that the same interface class can be used in different contexts, not just for http based communication. Specifically, we use the same interface class both for Feign and for sending messages to remote services via a queue - if there is a method that should only be invoked through a queue, we'd expect it to not be annotated with RequestMapping, which causes Feign to fail to process the class entirely.

dmarkhas avatar Apr 24 '18 10:04 dmarkhas

Would it make more sense to ignore all non-default methods not annotated with @RequestLine (or the equivalent in the Contract that is being used) and throw UnsupportedOperationException if those non-implemented methods are called on the feign target?

rage-shadowman avatar Apr 25 '18 00:04 rage-shadowman

IMO, the cleaner solution would be to make multiple interfaces (your concrete class on the server side can implement them both). The one for Feign, the other for your queue.

But if you are unable to do that for some (business-related?) reason, then it is likely you do not have control of the interface and thus can't add any sort of @FeignIgnore annotation either.

So if Feign wants to support this, then (again, IMO -- YMMV) I think it should ignore all methods it doesn't recognize as supported.

rage-shadowman avatar Apr 25 '18 00:04 rage-shadowman

We are doing exactly that just now - splitting the interface :) It has some drawbacks for us though, since using a single interface would have allowed us to clean up our own APIs. Your suggestion to ignore anything that is not annotated with RequestLine, RequestMapping, etc. sounds OK, I proposed the annotation simply because it is probably easier to implement and gives the developer finer control over what gets picked up by Feign, but both approaches are OK really.

dmarkhas avatar Apr 25 '18 04:04 dmarkhas

Complete untested and unverified suggestion, but has anyone tried to extend the interface ala Spring Data?

https://docs.spring.io/spring-data/jpa/docs/2.0.6.RELEASE/reference/html/#repositories.custom-implementations

interface MyCustomInterface {
  void myCustomMethod();
}

class MyCustomIntefaceImpl implements MyCustomInterface {
   public void myCustomMethod() {
       ...
   }
}
interface FeignClient extends MyCustomInterface {
   @RequestLine()
   public Foo myServiceCall();
}

I have no idea if there is some Spring magic going on here however.

kdavisk6 avatar Apr 25 '18 14:04 kdavisk6

From #615, we may want to consider either adding an explicit ignore annotation or update the default Contract to only intercept methods annotated. Thoughts?

kdavisk6 avatar Dec 05 '18 02:12 kdavisk6

As a user, having Feign only proxy annotated methods makes more sense and addresses the issue in this request and in #615.

dmarkhas avatar Dec 05 '18 06:12 dmarkhas

I want to ignore some method on api interface too.

XhstormR avatar Jan 08 '22 13:01 XhstormR

Any progress here?

hbprotoss avatar Apr 13 '22 06:04 hbprotoss

4 years have passed

XhstormR avatar Apr 13 '22 06:04 XhstormR

Would be very practical to ignore default methods especilly for generated interfaces, for instance, from Open API

ashakirin avatar Apr 30 '22 17:04 ashakirin

Default methods are not handled by feign. They are invoked as is

velo avatar May 01 '22 00:05 velo

Is there any updates for this proposal?

DanielLiu1123 avatar Jul 06 '22 10:07 DanielLiu1123

Hi @DanielLiu1123 well, still waiting of someone to take charge and make it happen. I can review and guide as needed, just don't have the time to do it myself

velo avatar Jul 06 '22 20:07 velo