简体   繁体   English

拦截所有传出的HTTP调用Java

[英]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. 类似于HttpFilter(javax.Servlet.Filter),当添加到web.xml中时,它可以独立于框架(Spring / CXF / Jersy等)而拦截对JVM的任何传入请求/传出(作为响应),我试图找到一个API可以拦截来自JVM的任何传出HTTP调用,以独立于框架添加/修改标头。 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. 在论坛中,经常会误解“发出HTTP呼叫”一词,因此,我以示例进行解释。

Let us assume there are two JVMs, jvm1 and jvm2. 让我们假设有两个JVM,jvm1和jvm2。 and there are HTTP calls being made from JVM1 to JVM2. 并且有从JVM1到JVM2的HTTP调用。 I would like to intercept the HTTP connection being made from JVM1 to modify the headers information before the call happens. 我想在调用发生之前拦截从JVM1建立的HTTP连接以修改标头信息。 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. 我不想将代码绑定到特定的框架,这样我就可以将拦截器像jar一样捆绑在一起,并与应用程序团队共享。 Changes in web.xml is fine. 在web.xml中进行更改就可以了。

Any suggestions? 有什么建议么? Please HELP! 请帮忙!

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. 两种JVM都可以以任何方式使用java.net.Socketjava.net.ServerSocket进行通信,并且这里没有办法拦截任何内容。

You may intercept any HTTP traffic if you connect thru a (transparent) proxy . 如果通过(透明) 代理进行连接,则可以拦截任何HTTP通信。 The proxy will intercept anything and you may modify any content. 代理将拦截任何内容,您可以修改任何内容。

We went with aspectj. 我们选择了Aspectj。 Not the best solution, but the only option we got. 不是最好的解决方案,而是我们得到的唯一选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM