0

I had worked on an application with SOAP web service where all the soap api calls will be triggered through one place using handler method invocation.

I've not seen the implementation in detail but I know how it was working.

Can we have one class where I can track all the REST apis before it hits and after i receive the response. I use spring. Except AOP, how to write handler method invocation for REST service?

What I'm asking is, instead of writing RestTemplate.exchange() in all the services wherever I make rest call, can I have a method invocation handler mechanism to invoke all the request at one place and to get the response asynchronously?

Shakthi
  • 826
  • 3
  • 15
  • 33
  • Possible duplicate of [How can I run common code for most requests in my Spring MVC Web App?](https://stackoverflow.com/questions/8928410/how-can-i-run-common-code-for-most-requests-in-my-spring-mvc-web-app) – Rodrigo Oliveira Jan 28 '19 at 17:12
  • What I'm asking is, instead of writing RestTemplate.exchange() in all the services wherever I make rest call, can I have a method invocation handler mechanism to invoke all the request at one place and to get the response asynchronously? – Shakthi Jan 28 '19 at 17:27

1 Answers1

0

You can use a javax.servlet.Filter to intercept all the requests sent to the server and intercept all the responses from the server to the client. From javadoc:

A filter is an object that performs filtering tasks on either the request to a resource (a servlet or static content), or on the response from a resource, or both.

Examples that have been identified for this design are

1) Authentication Filters

2) Logging and Auditing Filters

3) Image conversion Filters

4) Data compression Filters

5) Encryption Filters

6) Tokenizing Filters

7) Filters that trigger resource access events

8) XSL/T filters

9) Mime-type chain Filter*

Davide Lorenzo MARINO
  • 26,420
  • 4
  • 39
  • 56
  • Hi. Similar to this example, https://dzone.com/articles/java-dynamic-proxy I want one place where the rest implementation should be. – Shakthi Jan 28 '19 at 17:33
  • @Shakthi you can use a filter to intercept all the http requests and handle all the requests in the java code. A dynamic proxy is a class that can be used to proxy call to other classes. This approach is not the right approach for intercepting http requests, but is necessary used if you need to proxy any internal call to methods – Davide Lorenzo MARINO Jan 28 '19 at 17:48
  • Is it a good approach to have resttemplate.exchnge() in all the places wherever we make a call to rest api? Or we can have a util class to have it in one place? – Shakthi Jan 28 '19 at 18:26