-1

I want to intercept a whole class with java standard features, because i am not allowed to add new dependencies to the project (websphere 85).

I want to call a function, which does multiple api calls (swagger generated) for example myapi.bla(), myapi.blabla(), etc and get the headers from the response.
I thought about intercepting all methods of the class "myapi" and then access the headers (myapi.getApiClient.getResponseheaders).

Do you know how to intercept all methods of a class with java or websphere85 built in features? Thank you!

1 Answers1

1

There are prominently 2 ways to achieve this,

  1. AOP, you can use AspectJ to achieve this which basically modifies the class to inject interceptions, either at compile or load time. Example.

  2. Dynamic Proxy. A good explanation on how to use it with example. Though it comes with a performance cost.

Adwait Kumar
  • 1,552
  • 10
  • 25