Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intercept all outgoing http calls java

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!

like image 841
IronKnight Avatar asked Nov 10 '22 21:11

IronKnight


1 Answers

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.

like image 134
PeterMmm Avatar answered Nov 14 '22 23:11

PeterMmm