users@jersey.java.net

[Jersey] Re: Client and custom socket factory

From: Christopher Piggott <cpiggott_at_gmail.com>
Date: Fri, 11 Feb 2011 08:58:21 -0500

Hi,

I am still trying to figure out how I can create a jersey client and
have it bound to a specific outbound network interface (identified by
source IP).

I'm looking at jersey-apache-client as a possible way to do this but I
still haven't figured out how. Something somewhere creates a
SocketFactory and calls it. The default way to do this with apache
http client seems to be:

   connectSocket(Socket socket, InetSocketAddress remoteAddress,
InetSocketAddress localAddress, org.apache.http.params.HttpParams
params)



but I don't know how localAddress gets set (this is what I want to override).

My next step, I think, is going to be to try to create my own
SocketFactory and attach it to jersey-apache-client, but implement the
SocketFactory to ignore the localAddress and bind whatever I want.
This is not desirable to me though, since I really need to be able to
send requests out multiple interfaces.

To explain ... one interface is a cell card, the other is wifi. The
cell card is expensive. The strategy is to only send certain data via
wifi, unless the application determined (based on priority, history,
etc.) that this is important enough to go out the cell card.

Ideally I'd like to make that decision every time I create a jersey Client.