Hello,
I have the following problem:
On one of our servers runs a web application which connects through a
HttpUrlConnection to another server and sends requests. Our server has
two IP addresses. The other server only accepts requests from one of
those. But our server uses the other one as default...
The following options are not possible for different reasons:
- to write our own HttpUrlConnection class
- to change the default IP of our server
- to change the configuration of the other server
- to fiddle with the IP of outgoing packets via NAT or something
Does anyone know how to set the source IP of the request from Java?
Greetings and thanks in advance
Jan Strube
Gordon Beaton - 08 Jun 2007 08:19 GMT
> - to fiddle with the IP of outgoing packets via NAT or something
The "wrong" outgoing interface is chosen because it matches a routing
rule, probably the default route of the connecting machine.
You could set up a static route to the other server that specifies the
correct local interface, no need for NAT.
/gordon
--
Esmond Pitt - 08 Jun 2007 09:40 GMT
It can't be done in Java. AFAIK an HTTP request doesn't even contain it,
it's in the TCP packets, and you can't control that.
You will have to fix the fussy server.
js@deriva.de - 08 Jun 2007 12:36 GMT
I've got the solution:
With the Apache Commons HttpClient it is possible to set the local
address.
Greetings
Jan
Manivannan Palanichamy - 08 Jun 2007 15:13 GMT
On Jun 7, 3:00 pm, j...@deriva.de wrote:
> Hello,
>
[quoted text clipped - 14 lines]
> Greetings and thanks in advance
> Jan Strube
looks like a puzzle in java :-) Those 4 steps are the possible ways of
finding a solution to this prob.
anyway, you could set the source ip of packet in using Jpcap -- Java
packet filtering libraries. But, that will
require highest user login, such as root in linux or administrator in
windows.
--
Manivannan.Palanichamy (@) Oracle.com
http://mani.gw.googlepages.com/index.html