On Tue, Aug 25, 2009 at 01:25:21AM +0200, Peter Paul wrote:
> On Mon, 24 Aug 2009 10:35:09 +0200
> Oleg Kalnichevski <[email protected]> wrote:
> 
> > On Sun, Aug 23, 2009 at 11:57:56PM +0200, Peter Paul wrote:
> > > Hello,
> > > I'm about add SOCKS proxy support to an application that uses
> > > HttpClient and it's HttpProxy capabilities. While Http Proxy
> > > support is given by the HttpClient API, I could not find said thing
> > > for SOCKS, so I found that it would be nessesary to implement it via
> > > ProtocolSocketFactory.
> > > However, the application in question can has several open
> > > connections that even may go through different proxies. There is a
> > > HttpClient object for every connection. So I did a
> > > ProxySocketFactory class and specified a custom proxy protocol
> > > 
> > > Protocol myProxy = new Protocol("http", new
> > > ProxySocketFactory(proxy), 80);
> > > 
> > > How can I get the HttpClient object to use this protocol by default?
> > > There is a default protocol in HttpClient's HostConfiguration
> > > object, but it only provides a getProtocol method.
> > > 
> > 
> > Use static Protocol#register method
> 
> Do you mean I should override the default HTTP protocol with that? But
> then all HttpClients will use the same proxy - that's the reason I
> can't just set the proxy of the java enviroment.
> The idea behind having multiple HttpClients in this application is that
> they can use of different proxies (HTTP and SOCKS alike), so there
> might be two connections using SOCKS proxy A, a third one to use HTTP
> proxy B and another one using SOCKS proxy C at the same time.
> I don't see how I can accomplish this using Proxy.registerProtocol()
> 
> > > So maybe there is a better way on how to get an application support
> > > SOCKS as well? I have not figured out yet how to get
> > > authentification either.
> > >   
> > 
> > As far as I know SOCK proxying works on the java.net.Socket level and
> > therefore should be absolutely transparent for the HTTP layer.
> 
> Well, that's what the SocketFactory is for, but how can I get an
> HttpClient to always use this SocketFactory?
> 
> > Oleg
> 
> regards
> 
> Peter
> 

You should be using just a single instance of HttpClient, multiple
HostConfiguration objects (one per request), and (very important) relative
request URIs.

Alternatively, you should consider upgrading to HttpClient 4.0 which has a
significantly better API.

Hope this helps.

Oleg


> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to