commons-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "John Brayton" <johnbray...@gmail.com>
Subject HttpClient/Socket within Applet behind SOCKS v4 proxy
Date Wed, 04 Apr 2007 15:12:56 GMT
I am wondering if someone can shed some light on a problem I am having
using HTTPClient in an applet running behind a SOCKS v4 proxy.

Client System Configuration:
-IE6 on Win XP
-Java 1.5.0_11
-Applet is using HTTP Client 3.0.1.

If IE is configured to connect directly to the web server, or is
configured to use a SOCKS v5 proxy, the applet works as expected.  If
IE is configured to connect to a SOCKS v4 proxy, I get this exception:

java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(Unknown Source)
    at java.net.SOCKSSocketImpl.readSOCKSReply(Unknown Source)
    at java.net.SOCKSSocketImpl.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.connect(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at java.net.Socket.<init>(Unknown Source)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:80)
    at org.apache.commons.httpclient.protocol.DefaultProtocolSocketFactory.createSocket(DefaultProtocolSocketFactory.java:122)
    at org.apache.commons.httpclient.HttpConnection.open(HttpConnection.java:707)
    at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(HttpMethodDirector.java:387)
    at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:171)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397)
    at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323)

This happens regardless of whether I set the "socksProxyHost" and
"socksProxyPort" system properties.

Note that in my test environment, the applet could connect directly to
the web server if it tried to, so it seems that the applet is trying
to connect to via the SOCKS v4 proxy.

Based on the debug information above, the error is occuring on this
constructor within DefaultProtocolSocketFactory:
  new Socket(host, port, localAddress, localPort);

The "host" and "port" parameter values are correct; localAddress is
set to null, and localPort is set to 0.  So the constructor call looks
correct.  If I call this Socket constructor at the start of the applet
with hard-coded values I get identical symptoms:
  Socket(String,int)

Packet-sniffing with Ethereal shows that while IE is making SOCKS v4
connections and succeeding; the applet is trying to make SOCKS v5
connections and failing.

Perusing the JVM code, the "java.net.SocksSocketImpl" class has a
setV4() method, but I can't find anything in the JVM that ever calls
it.  The logical thing to do would be to call that setV4() method, but
the method is not public; a class has to be within the "java.net"
namespace in order to call it.  And trying to create my own "java.net"
class results in a SecurityException, even from within a
PrivilegedAction.run() method.  I don't believe an applet can have an
"endorsed" class.

What I suspect would theoretically work is this:
-Copying the JVM "java.net.SocksSocketImpl" class into my own class
namespace, in addition to the non-public code within the "java.net"
namespace that it needs.
-Calling SocksSocketImpl.setV4().
-Calling Socket.setSocketImplFactory(...) with a factory that returned
my own SocksSocketImpl object.
But I'd have to copy a *lot* of "java.net" JVM code, creating a big
mess and perhaps violating the JVM source license, so this seems like
a bad idea.

Does anyone have any advice on this?

John

---------------------------------------------------------------------
To unsubscribe, e-mail: commons-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-user-help@jakarta.apache.org


Mime
View raw message