Using multiple interceptors only produces the output from the last interceptor.
See original GitHub issueDescribe the bug When using configuring multiple interceptors, only the last one in the config produces output.
To Reproduce
- Configure two interceptors
Unirest.config()
.interceptor(new Interceptor() {
@Override
public void onRequest(HttpRequest<?> request, Config config) {
System.out.println("Output from first interceptor");
}
}).interceptor(new Interceptor() {
@Override
public void onRequest(HttpRequest<?> request, Config config) {
System.out.println("Output from Second interceptor");
}
});
Unirest.get("https://reqres.in/api/users?page=2").asJson();
Expected behavior Outcome from both interceptors
Output from first interceptor
Output from Second interceptor
but we only see the output from the 2nd interceptor.
Output from Second interceptor
Screenshots If applicable, add screenshots to help explain your problem.
Environmental Data:
- Java Version - 11
- Version [e.g. 3.8.06]
Additional context Add any other context about the problem here.
Issue Analytics
- State:
- Created 3 years ago
- Comments:9 (4 by maintainers)
Top Results From Across the Web
Angular HTTP Interceptors : Multiple Interceptors and 6 Code ...
In this article I will explain how to use multiple interceptors and 6 most common uses of Interceptors with Example. By reading my...
Read more >How to split HTTP Interceptors between multiple backends
This article will teach you how to implement different types of the standard HttpClient version and associate module scoped interceptors with each type....
Read more >Angular Interceptors to Manage HTTP Requests
Learn how to use Angular interceptors to manage HTTP requests including JWT authorization , caching and logging.
Read more >54.2 Using Interceptors - The Java EE Tutorial
Use the @AroundInvoke annotation to designate interceptor methods for managed object methods. Only one around-invoke interceptor method per class is allowed.
Read more >How to integrate interceptor in angular 9? - Third Rock Techkno
You should use interceptor in Angular. Interceptors provide a mechanism to intercept and mutate outgoing requests or incoming responses like ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
One thing to be aware of is that Unirest.config() is of course static itself. It will be the same instance of the config everywhere you use it in the JVM. So the recommendation is to do that on startup once, rather than before you invoke Unirest
Two anonymous objects of the same interface in java are not the same. They are different instances. Like with any java object you could override equals/hash code to make them the same or you could pass in a singleton instance of the interceptor or you could set it up as a static variable.
In any case Configs in unirest are not designed to be messed with a lot. They should mostly be done once.