question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Using multiple interceptors only produces the output from the last interceptor.

See original GitHub issue

Describe the bug When using configuring multiple interceptors, only the last one in the config produces output.

To Reproduce

  1. 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:closed
  • Created 3 years ago
  • Comments:9 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
rybercommented, Aug 3, 2020

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

1reaction
rybercommented, Aug 3, 2020

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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found