You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Seb <me...@hotmail.com> on 2008/03/03 17:11:44 UTC
Problem with httpclient 3-x and socks server
Hi,
I'm currently writing an application that needs to hit two different webapps, one using a socks server, and another one that does not need to use the socks server.
What I would like is to use the socks server only for the connection that needs it, and not for the other (because I want to avoid the eventual slowlinesses of the socks server).
According to the httpclient documentation, it seems that the only way to use a socks proxy is to set it up for the whole JVM (with socksProxyHost and socksProxyPort system parameters), what means that all HTTP connections will use socks :(
So my question is :
Is there a way to tell httpclient to build specific socks connections, as it is possible to do using the legacy java.net API ?
Example :
SocketAddress addr = new InetSocketAddress(host,port);
Proxy proxy = new Proxy(Proxy.Type.SOCKS, addr);
URLConnection conn = url.openConnection(proxy);
InputStream result = new DataInputStream(conn.getInputStream());
I've looked at the source code and I've finally found no way to be able to reach the socks server... I systematically get I/O timeout errors :(
Thanks a lot,
Sebastien.
_________________________________________________________________
Votre contact a choisi Hotmail, l'e-mail nouvelle génération. Créez un compte.
http://www.windowslive.fr/hotmail/default.asp
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
RE: Problem with httpclient 3-x and socks server
Posted by Seb <me...@hotmail.com>.
Thanks a lot, it solved my issue !I've already tried to create a new ProtocolSocketFactory, but I did not knew anything about Protocol.registerProtocol() method :(Thanks,Seb> Date: Mon, 3 Mar 2008 17:38:51 +0100> From: ossfwot@dubioso.net> To: httpclient-users@hc.apache.org> Subject: Re: Problem with httpclient 3-x and socks server> > Hi Sebastien, Alan,> > Alan Moss wrote:> > You need to create your own custom ProtocolSocketFactory[1] and > > implement the createSocket methods in the manner you mentioned. Once you > > do that, you need to tell HttpClient to use it. Something like this:> > > > if (shouldUseSocks) {> > Protocol.registerProtocol("http",> > new Protocol("http", new MyProtocolScoketFactory(), 80));> > }> > That's the idea, although I would move the if(...) part into the> socket factory. Things get ugly if you want to juggle between> different socket factories for the same protocol/scheme.> > Alternatively, if you're on Java 5 or later, you might want to> install your own ProxySelector in the "legacy" java.net API :-)> > http://java.sun.com/j2se/1.5.0/docs/api/java/net/ProxySelector.html#setDefault(java.net.ProxySelector)> http://java.sun.com/j2se/1.5.0/docs/guide/net/proxies.html> > > cheers,> Roland> > > > > [1] > > http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html > > > > > > Good luck.> > > > -Alan> > > > ---------------------------------------------------------------------> > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org> > For additional commands, e-mail: httpclient-users-help@hc.apache.org> > > > > ---------------------------------------------------------------------> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org> For additional commands, e-mail: httpclient-users-help@hc.apache.org>
_________________________________________________________________
Microsoft vous recommande de mettre à jour Internet Explorer.
http://specials.fr.msn.com/IE7P25
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Problem with httpclient 3-x and socks server
Posted by Roland Weber <os...@dubioso.net>.
Hi Sebastien, Alan,
Alan Moss wrote:
> You need to create your own custom ProtocolSocketFactory[1] and
> implement the createSocket methods in the manner you mentioned. Once you
> do that, you need to tell HttpClient to use it. Something like this:
>
> if (shouldUseSocks) {
> Protocol.registerProtocol("http",
> new Protocol("http", new MyProtocolScoketFactory(), 80));
> }
That's the idea, although I would move the if(...) part into the
socket factory. Things get ugly if you want to juggle between
different socket factories for the same protocol/scheme.
Alternatively, if you're on Java 5 or later, you might want to
install your own ProxySelector in the "legacy" java.net API :-)
http://java.sun.com/j2se/1.5.0/docs/api/java/net/ProxySelector.html#setDefault(java.net.ProxySelector)
http://java.sun.com/j2se/1.5.0/docs/guide/net/proxies.html
cheers,
Roland
>
> [1]
> http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html
>
>
> Good luck.
>
> -Alan
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org
Re: Problem with httpclient 3-x and socks server
Posted by Alan Moss <am...@learningsoft.net>.
You need to create your own custom ProtocolSocketFactory[1] and
implement the createSocket methods in the manner you mentioned. Once you
do that, you need to tell HttpClient to use it. Something like this:
if (shouldUseSocks) {
Protocol.registerProtocol("http",
new Protocol("http", new MyProtocolScoketFactory(), 80));
}
[1]
http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/protocol/ProtocolSocketFactory.html
Good luck.
-Alan
---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org