Skip to content

Issue-6 Support custom interceptors - #7

Closed
gldiazcardenas wants to merge 3 commits into
taboola:mainfrom
gldiazcardenas:main
Closed

gldiazcardenas wants to merge 3 commits into
taboola:mainfrom
gldiazcardenas:main

Conversation

@gldiazcardenas

Copy link
Copy Markdown
  • Added a List of okhttp3.Interceptor into the CommunicationConfig.
  • Interceptors are registered when building the OkHttpClient in CommunicationFactory.

@gldiazcardenas

Copy link
Copy Markdown
Author

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.

@gldiazcardenas

Copy link
Copy Markdown
Author

@vladimanaev any change I can get this reviewed?

@vladimanaev

Copy link
Copy Markdown
Collaborator

Hi @gldiazcardenas sure let me review it.
We also planned to add aspect oriented flows.

import java.util.Objects;
import java.util.stream.Collectors;

import okhttp3.Interceptor;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

best to avoid coupling to okhttp3 so I prefer creating our own dedicated Interceptor interface

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, good point.

config.getKeepAliveDurationMillis(), TimeUnit.MILLISECONDS));

if (config.getInterceptors() != null) {
config.getInterceptors().forEach(builder::addInterceptor);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When do you think the aspect oriented flows would be in place? I wonder how it will be implemented.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

@gldiazcardenas gldiazcardenas Dec 19, 2023 •

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@vladimanaev

Copy link
Copy Markdown
Collaborator

Closing this one, instead adding similar functionality in #9

@vladimanaev vladimanaev closed this Feb 2, 2024
@gldiazcardenas

Copy link
Copy Markdown
Author

Yeah that one implementation in #9 is enough.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants