JDK-8147770 : bind proxy Authenticator to URLConnection
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8u66,9
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2016-01-20
  • Updated: 2016-12-02
  • Resolved: 2016-12-02
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
Now, we use the code below to use proxy in URLConnection. But the Authenticator is JVM global, not bind to a specific URLConnection. But actually we need to access different proxy(with different Authenticator) in applications.

Authenticator.setDefault(
   new Authenticator() {
      public PasswordAuthentication getPasswordAuthentication() {
         return new PasswordAuthentication(
               authUser, authPassword.toCharArray());
      }
   }
);

Proxy proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress("10.0.0.1", 8080));
conn = new URL(urlString).openConnection(proxy);

JUSTIFICATION :
the concept of model of proxy Authenticator is built not correctly.



Comments
Please check the new method HttpURLConnection::setAuthenticator method added by JDK-8169495.
02-12-2016

It is unclear whether this refers to authentication with the proxy or authentication with the target or both. If it's same authentication with both proxy and target server - and the URL is an HTTP url - that is - if the returned connection is an instance of HttpURLConnection, then I guess JDK-8169495 would solve the issue.
10-11-2016

Is this enhancement still needed give that JDK 9 will have a new HTTP Client API that provides it? If not, then this issue should be closed.
29-07-2016