Repository navigation
Issue-6 Support custom interceptors - #7
gldiazcardenas wants to merge 3 commits into
Conversation
gldiazcardenas
commented
Dec 7, 2023
- Added a List of okhttp3.Interceptor into the CommunicationConfig.
- Interceptors are registered when building the OkHttpClient in CommunicationFactory.
|
Once this is merged, I will submit another PR in the https://github.com/taboola/backstage-api-java-client to support the interceptors in the Backstage class. |
|
@vladimanaev any change I can get this reviewed? |
|
Hi @gldiazcardenas sure let me review it. |
| import java.util.Objects; | ||
| import java.util.stream.Collectors; | ||
|
|
||
| import okhttp3.Interceptor; |
There was a problem hiding this comment.
best to avoid coupling to okhttp3 so I prefer creating our own dedicated Interceptor interface
| config.getKeepAliveDurationMillis(), TimeUnit.MILLISECONDS)); | ||
|
|
||
| if (config.getInterceptors() != null) { | ||
| config.getInterceptors().forEach(builder::addInterceptor); |
There was a problem hiding this comment.
I afraid of such a wide access to API protocol, I thought better to add some "safe" AroundAspect like interceptor which will be safe not to break API calls but allow different before/after code parts.
There was a problem hiding this comment.
When do you think the aspect oriented flows would be in place? I wonder how it will be implemented.
There was a problem hiding this comment.
Maybe meanwhile we can create something simple to allow interceptors but limit them to specific code parts like "beforeCall", "afterCall" you can do by creating dedicated interface and create one general interceptor that run list of such interfaces and let developer use those which will both limit the exposure of internal flows vs give enough abilities to save things or log or etc. WDYT?
There was a problem hiding this comment.
I think it is fine, as long as the new interface provides access to the request and response.. if it does not, then this dummy interceptor might be useless. so basically could be an interface like:
public interface Interceptor {
beforeCall(Request);
afterCall(Request, Response);
}
WDYT?
There was a problem hiding this comment.
I think we can provide both request and response data we just need to plan what response should contain, for example raw Retrofit response is problematic since you dont know which call adapter is handling it since interceptors happening before call adapter.
So sound like we need to handle "before" inside the interceptor wrapper but response to provide part of SynchronousCallAdapterFactory or StringConverterFactory.
For example I think that those provided "before/after" code injection parts can not manipulate request nor response so both request and response references should be immutable.
|
Closing this one, instead adding similar functionality in #9 |
|
Yeah that one implementation in #9 is enough. |