Add InvocationHandlerFactory.MethodHandlerCustomizer#1515
Conversation
37c6c3a to
577a70e
Compare
577a70e to
63069fd
Compare
| errorDecoder, synchronousMethodHandlerFactory); | ||
| return new ReflectiveFeign(handlersByName, invocationHandlerFactory, queryMapEncoder); | ||
| return new ReflectiveFeign(handlersByName, invocationHandlerFactory, | ||
| queryMapEncoder, methodHandlerCustomizers); |
There was a problem hiding this comment.
this customizer basically acts just like one of enrich methods of Capability but I think it's too low level to be in there. Or is it?
| for (MethodHandlerCustomizer customizer : methodHandlerCustomizers) { | ||
| handler = customizer.customize(target, method, handler); | ||
| } |
There was a problem hiding this comment.
this for loop is repeated twice, I could add a static method MethodHandlerCustomizer#customizeAll(List< MethodHandlerCustomizer>, Target, Method, MethodHandler) to make it a one-liner.
velo
left a comment
There was a problem hiding this comment.
This is duplicating the efforts of capabilities, but in a different format.
Let's refactor this as part of capability API
Are you referring to this? |
|
If it was an |
|
I'm going to echo @velo here. The Caching, for instance, could be implemented as a Do you want it based on HTTP request? "Enrich" the The general rule here is, |
|
@kdavisk6 if you look at #1513, I did it using capability but I thought we could add a more specific customizer just for the method handlers. Also, the capability solution does not cover feign/core/src/main/java/feign/ReflectiveFeign.java Lines 72 to 78 in 63069fd |
|
Default Method handler proxies |
|
I see, thanks. So, would something like this be ok? It's basically a convenience method doing exactly the same as what I'm doing in #1513 //new class
MethodInvocation {
Target<?> target;
Method method;
Object[] arguments;
MethodHandler handler;
Object invoke() { return handler.invoke(arguments); }
}
Capability {
...
default MethodInvocation enrich(MethodInvocation invocation) {
return invocation;
}
}
Feign {
...
Feign build() {
...
invocationHandlerFactory = (target, dispatch) -> invocationHandlerFactory.create(target,
dispatch.entrySet().stream()
.map(e -> Map.entry(e.getKey(), (MethodHandler) args -> Capability.enrich(new MethodInvocation(target, e.getKey(), args, e.getValue()), capabilities).invoke())
.collect(toMap(Map.Entry::getKey, Map.Entry::getValue)));
invocationHandlerFactory = Capability.enrich(invocationHandlerFactory, capabilities);
}
}
//usage
new Capability() {
MethodInvocation enrich(MethodInvocation invocation) {
return new MethodInvocation(...pass stuff from "invocation" or enriched...) { ...override invoke()... };
}
} |
|
@velo @kdavisk6 so, do you guys think I should change it to the way I suggested in my last message or just reject the PR and let people do it through invocation handler capability like here? |
|
Hi Sam, You probably trying to achieve the same as we have for metrics, don't you? Sounds like there is no need to change feign at all |
|
Thanks, yes, you're right. I updated my PR on the spring side to do like you suggested: spring-cloud/spring-cloud-openfeign#608 (comment) |
This should make it easier for intergrations. Currently have to provide a capability to enrich the InvocationHandlerFactory itself to rebuild the "dispatch" map.
see #1513