2

I am getting the subject mentioned error code in one of my programs. I looked around for solutions on Stackoverflow and tried to follow the suggestions on issues reported by Ilana Platonov and PPr. Unfortunately, these didn't resolve the errors.

As a next step, I simply tried to run the code presented in Ilana Platonov along with the resolutions (accepted there). My code: package examples;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Authenticator;
import java.net.HttpURLConnection;
import java.net.InetSocketAddress;
import java.net.PasswordAuthentication;
import java.net.Proxy;
import java.net.URL;


public class MyProxyPass {
    public MyProxyPass( String proxyHost, int proxyPort, final String userid, final String password, String url ) {

try {
        /* Create a HttpURLConnection Object and set the properties */
        URL u = new URL( url );
        Proxy proxy = new Proxy( Proxy.Type.HTTP, new InetSocketAddress( proxyHost, proxyPort ) );
        HttpURLConnection uc = (HttpURLConnection) u.openConnection( proxy );

        Authenticator.setDefault( new Authenticator() {
            @Override
            protected PasswordAuthentication getPasswordAuthentication() {
                if (getRequestorType().equals( RequestorType.PROXY )) {
                    return new PasswordAuthentication( userid, password.toCharArray() );
                }
                return super.getPasswordAuthentication();
            }
        } );
        uc.connect();
        /* Print the content of the url to the console. */
        showContent( uc );
    }
    catch (IOException e) {
        e.printStackTrace();
    }
}

private void showContent( HttpURLConnection uc ) throws IOException {
    InputStream i = uc.getInputStream();
    char c;
    InputStreamReader isr = new InputStreamReader( i );
    BufferedReader br = new BufferedReader( isr );
    String line;
    while ((line = br.readLine()) != null) {
        System.out.println( line );
    }
}

public static void main( String[] args ) {
    String proxyhost = "xxx.xxx.xx.xx";
    int proxyport = xxxx;
    final String proxylogin = "JOKER";
    final String proxypass = "passxxx";

    String url = "http://www.google.de";
    String surl = "https://www.google.de";

    System.setProperty("javax.net.ssl.trustStore", "C:\\Users\\JOKER\\Documents\\eclipse-jee-photon-R-win32\\eclipse");
    System.setProperty("javax.net.ssl.trustStorePassword", "changeit");

    //new MyProxyPass( proxyhost, proxyport, proxylogin, proxypass, url );  // uncomment this line to see that the https request works!
    //System.out.println( url + " ...ok" );   // uncomment this line to see that the https request works!
    new MyProxyPass( proxyhost, proxyport, proxylogin, proxypass, surl );
    System.out.println( surl + " ...ok" );
}
}

However, I still get the same errors that were reported by others:

   java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"
https://www.google.de ...ok 
at    sun.net.www.protocol.http.HttpURLConnection.doTunneling(HttpURLConnection.java:2124)
at    sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:183)
at    sun.net.www.protocol.https.HttpsURLConnectionImpl.connect(HttpsURLConnectionImpl.java:153)
    at    examples.MyProxyPass.<init>(MyProxyPass.java:32)
at examples.MyProxyPass.main(MyProxyPass.java:63)

What worked for others and not for me:

  1. The often given suggestion about setting the variables jdk.http.auth.tunneling.disabledSchemes and jdk.http.auth.proxying.disabledSchemes to blank did not work. I set these to blank in ..\Java\jdk1.8.0_112\jre\lib\net.properties file.

  2. Tying out with various JVM Args proposed by Andreas Panagiotidis didn't help either.

  3. From https://bugs.eclipse.org/bugs/show_bug.cgi?id=422665 I also tried to exclude HTTP libraries that might be conflicting. -Dorg.eclipse.ecf.provider.filetransfer.excludeContributors=org.eclipse.ecf.provider.filetransfer.httpclient4

I am using:

  • Eclipse IDE Photon Release (4.8.0),
  • java version "1.8.0_112" (build 1.8.0_112-b15)
  • Windows 10
  • I am behind a corporate proxy and have spent two full days on it without success. :(

Let me know if I should attach any other logs.

pfx
  • 10,612
  • 39
  • 29
  • 43
spaniard81
  • 61
  • 1
  • 8

2 Answers2

1

The corporate proxy was the culprit! Once I resolved those issues, the code that I have posted above worked smoothly.

spaniard81
  • 61
  • 1
  • 8
1

I came across another situation where I got the same error (with correct proxy details).

Could not retrive data: java.io.IOException: Unable to tunnel through proxy. Proxy returns "HTTP/1.1 407 Proxy Authentication Required"

This time the error was due Java version 1.8.0_111. Since this Java update, the Basic Authentication for HTTPS tunneling has been disabled. This is done by adding the protocol to disabledScheme list, i.e., jdk.http.auth.tunneling.disabledSchemes=Basic in the lib/net.properties file.

To resolve this error enable the Basic Authentication by setting the variable jdk.http.auth.tunneling.disabledSchemes to emtpy string as: '-Djdk.http.auth.tunneling.disabledSchemes='

Enable/Disable Basic Authentication for HTTPS

spaniard81
  • 61
  • 1
  • 8