Intercept all outgoing http calls java
Asked Answered
J

2

6

Similar to HttpFilter (javax.Servlet.Filter ) which when added in web.xml can intercept any incoming request to JVM / outgoing (as response) independent of framework ( Spring/CXF/Jersy etc ) , I am trying to find an API which could intercept any outgoing HTTP calls from JVM to add/modify headers independent of framework. Also routing the requests through a proxy sounds overwhelming.

Quite often the word Outgoing HTTP call is misinterpreted in the forums so let me explain with example.

Let us assume there are two JVMs, jvm1 and jvm2. and there are HTTP calls being made from JVM1 to JVM2. I would like to intercept the HTTP connection being made from JVM1 to modify the headers information before the call happens. I do not want the code to be tied to a specific framework so that I can as bundle the interceptor as a jar and share it with application team. Changes in web.xml is fine.

Any suggestions? Please HELP!

Junkie answered 15/12, 2014 at 15:54 Comment(0)
M
1

Both JVM may use java.net.Socket or java.net.ServerSocket in any way for communication and there is no way to intercept anything here.

You may intercept any HTTP traffic if you connect thru a (transparent) proxy. The proxy will intercept anything and you may modify any content.

Marko answered 15/12, 2014 at 16:7 Comment(2)
Thanks Peter for your answer. A proxy wouldn't help as well. I am trying to resend a header information which JVM1 had received as it is to JVM2.Junkie
3 years late I know... I had to do this recently and found your question. I ended up creating a custom generic rest client builder that uses Feign and a RequestInterceptor to intercept the outgoing calls.Tacy
J
0

We went with aspectj. Not the best solution, but the only option we got.

Junkie answered 16/7, 2015 at 20:9 Comment(1)
ironknight Could you share the solution code/approach?Unbeknown

© 2022 - 2024 — McMap. All rights reserved.