Java supports Socks proxy configuration through registered java.net.Authenticator or through settings, as described in Network Properties :
SOCKS protocol support settings
SOCKS username and password: purchased as follows. First, if the application registered a java.net.Authenticator default instance, it will be requested with the protocol installed on the string "SOCKS5" and the prompt set for the string "Authentication SOCKS". If the authenticator does not return a username / password, or if the authenticator is not registered then the system checks the user settings " java.net.socks.username " and " java.net.socks.password ". If these preferences do not exist, then the System property " user.name " is checked for the username. In this case, no password is provided.
SocksProxyHost
socksProxyPort (default: 1080)
Specifies the name of the SOCKS proxy server and the port number that will be used by the SOCKS protocol level. If socksProxyHost is specified, then all TCP sockets will use the SOCKS proxy server to establish or accept a connection. A SOCKS proxy server can be a SOCKS v4 or v5 server, and it must allow unauthenticated connections.
In the client code examples, you can check this response for stack overflow.
EDIT: update response as per comment
A side effect of SOCKS support in the JDK is that your entire JVM will go through the same SOCKS proxy. So this may not work for you.
Authenticator affects all authentication in your JVM (HTTP auth, Proxy Auth). So again, this may not work for you.
In your case, a possible solution would be to use the HttpClient from HttpComponents (the successor to the deprecated Commons HTTP Client 3.x ). Browse through the samples, and especially Proxy Request and Authentication Examples .
source share