-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
FilterableService<T> doesn't work if you have multiple request/response filters? #458
Comments
Thank for pointing this out. this is a known issue and we will fix it in a future release. |
Thanks @xuezhai. For our purposes we ended up forking the repo and creating a fix for this. The commit in question which has the fixes is here: avranju@0fa83ae. I can create a pull request from this if you think the approach is acceptable. + @BeatriceOltean, @martinsawicki |
This should be fixed. Please reopen if you see a recurrence |
The
FilterableService<T>
interface works by accepting objects that implementServiceRequestFilter
. This is a thin wrapper around the support for request/response interceptors in the Apache HTTP Client library. The code adapting objects implementingServiceRequestFilter
as objects that implement Apache'sHttpRequestInterceptor
interface is in the classServiceClient
(from which all key management client classes inherit). Specifically,ServiceClient
implementsFilterableService
and in its implementation of the methods fromFilterableService
it adapts theServiceRequestFilter
objects intoHttpRequestInterceptor
objects viaHttpRequestInterceptorAdapter
.This means that if a given client needs 3 different types of filters added to the request/response pipeline then they'd have to write 3 different classes all implementing
ServiceRequestFilter
- which is perfectly fine. As described above this should cause 3 instances ofHttpRequestInterceptorAdapter
to be created and added to theHttpClientBuilder
's first or last interceptor. See here for a sample implementation.The problem with this setup is that, for some reason, the Apache HTTP Client library allows only one instance to be added to the interception chain of each class that implements
HttpRequestInterceptor
for a particular type of interceptor (request/response). The relevant code from the library appears to be in theensureUnique
method of the ChainBuilder class. So in the example above, though there are 3 different classes implementingServiceRequestFilter
, all of them end up getting adapted via instances ofHttpRequestInterceptorAdapter
. As far as Apache HTTP Client is concerned all 3 objects are of the same type -HttpRequestInterceptorAdapter
- so only one of them ends up getting added to the interception chain (as far as I can tell, the last interceptor that happens to get added).Though I have only 1 object added to the request pipeline it turns out that the Azure SDK adds a filter of it's own to the pipeline (
ClientRequestTrackingHandler
) which ends up replacing my filter instance.The text was updated successfully, but these errors were encountered: