How to make the JVM use a given source IP by defau

2019-06-24 06:24发布

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.

1条回答
啃猪蹄的小仙女
2楼-- · 2019-06-24 07:03

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

"ConnRoutePNames.LOCAL_ADDRESS='http.route.local-address': defines a local address to be used by all default route planner. On machines with multiple network interfaces, this parameter can be used to select the network interface from which the connection originates. This parameter expects a value of type java.net.InetAddress. If this parameter is not set, a default local address will be used automatically."

查看更多
登录 后发表回答