[
https://issues.apache.org/jira/browse/HTTPCLIENT-1966?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=16752210#comment-16752210
]
Mikolaj Broniszewski commented on HTTPCLIENT-1966:
--------------------------------------------------
Hi [~olegk],
As I mentioned earlier I think that most problematic part is usage of
SocksSocketImpl in Socket object. In such case HttpClient simply move the
responsibility of Proxy to Java. SocksSocketImpl are using ProxySelector for
determining the available proxies for selected uri. So if only the JVM has an
argument for -DsocksProxyHost=<host>, -DsocksProxyPort=<port> or we are using
-Djava.net.useSystemProxies=true and in system we configured proxy for all
protocols, then HttpClient will use the SOCKS proxies as well. It's not even
required to have this useSystemProperties() flag set on builder.
If indeed HttpClient is not supporting SOCKS at all, shouldn't it use
PlainSocketImpl instead of SocksSocketImpl (as it is supposed to go to super
methods anyway)?
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]