如何使JVM默认使用给定的源IP? [英] How to make the JVM use a given source IP by default?

查看:404
本文介绍了如何使JVM默认使用给定的源IP?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用默认的内置java.xml.SOAPConnectionFactory时,有没有办法强制JVM使用特定的源IP地址?看来默认最终会创建HttpSOAPConnection对象(sun私有API),然后在底层使用HttpURLConnection。我似乎找不到任何系统属性来使HttpURLConnection使用特定的源IP。有一个类似的 stackoverflow问题,但我希望别人有更多的信息,或者我可以使用的技巧。

Is there any way to force the JVM to use a specific source IP address when using the default, built-in java.xml.SOAPConnectionFactory? It appears the default ends up creating HttpSOAPConnection objects (sun private API), which then uses HttpURLConnection underneath the hood. I can't seem to find any system property to make HttpURLConnection use a specific source IP. There is a similar stackoverflow question, but I'm hoping someone else has more information, or a trick I can use.

推荐答案

Apache Commons的Http客户端(http://hc.apache.org/httpcomponents-client-ga/)支持这个:

Http Client from Apache Commons (http://hc.apache.org/httpcomponents-client-ga/) supports this:

ConnRoutePNames.LOCAL_ADDRESS ='http.route.local-address'将本地地址定义为
。所有默认路由规划器使用的。在具有多个网络接口的计算机上,此参数可用于选择连接源自的网络​​接口。此参数需要java.net.InetAddress类型的值。如果未设置此参数,将自动使用默认本地地址

这篇关于如何使JVM默认使用给定的源IP?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆