[
https://issues.apache.org/jira/browse/HTTPCLIENT-1966?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16751409#comment-16751409
]
Mikolaj Broniszewski commented on HTTPCLIENT-1966:
--------------------------------------------------
Hi [~olegk], [~michael-o],
I understand that HttpClient 4.5.x does not support SOCKS protocol. However
while using the "useSystemProperties()" option I would not expect that my
application will use both HTTP and SOCKS proxies. If SOCKS proxy is not
supported at all, I think that it would be nice if library simply ignore it
(which will also meet Oracle documentation)?
I tried to simplify my example. But originally I wanted to use the:
{code}
java.net.useSystemProxies=true
{code}
This java property allows us to use the system properties configured by end
user. Unfortunately if only the user will define the proxy for both HTTP and
SOCKS Apache HttpClient will fail - which puts some limitation on library usage.
I think that most problematic part is how the Socket object is created. In
PlainConnectionSocketFactory you are creating new Socket object:
https://github.com/apache/httpcomponents-client/blob/123bd993cff822e02242197a24f47ee36bfa3744/httpclient5/src/main/java/org/apache/hc/client5/http/socket/PlainConnectionSocketFactory.java#L61
If no arguments are passed, it means that the Socket object will contain
default implementation (which is SocksSocketImpl). And while applying
connection on this Socket the ProxySelector for "socket://<uri>" will be used.
If only any proxy is found then system hangs up. However according to Oracle
documentation when we already used HTTP proxy we should no longer rely on SOCKS
proxy.
Best regards,
Mikolaj Broniszewski
> System Proxy - HTTP and SOCKS
> -----------------------------
>
> Key: HTTPCLIENT-1966
> URL: https://issues.apache.org/jira/browse/HTTPCLIENT-1966
> Project: HttpComponents HttpClient
> Issue Type: Bug
> Components: HttpClient (Windows)
> Affects Versions: 4.5.5, 4.5.6
> Reporter: Mikolaj Broniszewski
> Priority: Major
>
> Hello,
> I have created a proxy server basing on squid solution. And I have hidden the
> server (Apache Tomcat 8) which I would like to access behind this proxy (it's
> not available from my local machine directly). Then, I have created an
> example project which only connects to this hidden server basing on Apache
> HttpClient libraries:
> * org.apache.httpcomponents:httpcore:4.4.11
> * org.apache.httpcomponents:httpclient:4.5.6
> The code looks like:
> {code:java}
> public static void main(String ...args) throws Exception {
> System.setProperty("https.proxyHost", "<proxy_url>");
> System.setProperty("https.proxyPort", "<proxy_port>");
> System.setProperty("socksProxyHost", "<proxy_url>");
> System.setProperty("socksProxyPort", "<proxy_port>");
> URI uri = new URI("https://<hidden_server_url>");
> try (CloseableHttpClient build = HttpClientBuilder.create()
> .useSystemProperties()
> .build()) {
> final HttpUriRequest uriRequest = RequestBuilder.get()
> .setUri(uri)
> .build();
> try (CloseableHttpResponse response =
> build.execute(uriRequest)) {
> final StatusLine statusLine = response.getStatusLine();
> System.out.println(statusLine.toString());
> }
> }
> }
> {code}
> Unfortunately, as squid does not support SOCKS protocol, opening socket and
> waiting for response hangs the program. I was thinking that maybe I'm basing
> on invalid server configuration however when using below code everything
> works fine for same system properties:
> {code:java}
> public static void main(String ...args) throws Exception {
> System.setProperty("https.proxyHost", "<proxy_url>");
> System.setProperty("https.proxyPort", "<proxy_port>");
> System.setProperty("socksProxyHost", "<proxy_url>");
> System.setProperty("socksProxyPort", "<proxy_port>");
> URI uri = new URI("https://<hidden_server_url>");
> try (InputStream stream = uri.toURL().openStream()){
> String s = IOUtils.toString(stream, "UTF-8");
> System.out.println(s != null);
> } catch (IOException e) {
> e.printStackTrace();
> }
> }
> {code}
> So java itself handles it correctly. What is more if I simply remove the
> socksProxyHost and socksProxyPort settings, then Apache HttpClient connects
> correctly to the hidden server. I don't think that having both HTTPS proxy
> configuration and SOCKS is incorrect as according to Oracle documentation:
> [https://docs.oracle.com/javase/8/docs/technotes/guides/net/proxies.html]
> {code:java}
> "Now, what happens when both a SOCKS proxy and a HTTP proxy are defined? Well
> the rule is that settings for higher level protocols, like HTTP or FTP, take
> precedence over SOCKS settings. So, in that particular case, when
> establishing a HTTP connection, the SOCKS proxy settings will be ignored and
> the HTTP proxy will be contacted. Let's look at an example:"
> {code}
> As in Apache HttpClient I'm using system properties (useSystemProperties) I
> would expect that it is handled the same as Oracle does (the SOCK proxy
> should be ignored). I also checked it for simple HTTP proxy (http.proxyHost,
> http.proxyPort) and it acts the same (fails).
> Could you please help me with this issue?
> Best regards,
> Mikolaj Broniszewski
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]