Reuse Eclipse proxy handling when making HTTP connections [message #1403643] |
Thu, 24 July 2014 14:30  |
Eclipse User |
|
|
|
Hi,
I'm currently struggling with making HTTP connections using proxies in Eclipse and I need a some pointers (and I hope to get them here).
We have several locations in code that do http requests. All these locations need to respect the user's proxy settings as specified in Eclipse preferences (native proxy, manual proxy, direct etc.).
Currently, I have to take care of this at every location, e.g. as shown below:
@Override
public HttpURLConnection getHttpURLConnection(URL url) throws IOException {
Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress(host, port));
return (HttpURLConnection) url.openConnection(proxy);
}
});
I wonder whether there is something (besides IProxyService/ProxyData) that I could reuse to get the proxy handling right. For instance, in the example above: is there a way how this could be simplified using ECF?
Thanks for some pointers
Marcel
|
|
|
Re: Reuse Eclipse proxy handling when making HTTP connections [message #1403647 is a reply to message #1403643] |
Thu, 24 July 2014 15:20   |
Eclipse User |
|
|
|
First, you might want to be aware of this apparent proxy bug that was discovered in Apache httpcomponents 4.2:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=422665
It seems to be limited to NTLMv2 proxies...with authentication...so it may not be relevant to you, but it may be. We are trying to figure out what to do about it for Luna SR 1, as it seems to be caused by the change from using httpcomponents 4.1 in Kepler (no problem) to 4.2 in Luna.
Second, ECF filetransfer *optionally* uses the Eclipse proxy API config (if org.eclipse.core.runtime.net is present in framework). If it is present, then ECF filetransfer provider uses the proxy information across any/all filetransfer providers (httpcomponents 4, jre urlconnection). If the Eclipse proxy API is not present, then ECF falls back on using the JRE proxy config (i.e. the proxy.* Java system properties).
So if you didn't want to use IProxyService, you could simply leave out the org.eclipse.core.runtime.net bundle from your environment, and use the JRE system properties. Also, you can use either the httpcomponents 4, httpclient 3.1, or the jre/urlconnection-based provider, just by including or leaving out the appropriate bundles. For example, it may be that in your proxy environment the best thing would be the jre/urlconnection-based provider. ECF will fall back to using that provider if the httpcomponents 4 provider bundles are not present in a given framework (at runtime).
There's much more detail, obviously, but hopefully this can get a discussion started.
|
|
|
|
|
Powered by
FUDForum. Page generated in 0.24512 seconds