Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6670868

StackOverFlow with authenticated Proxy tunnels

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 8
    • 5.0, 6u20
    • core-libs
    • b01
    • x86
    • windows_xp, windows_7
    • Verified

        FULL PRODUCT VERSION :
        java version "1.5.0_14"
        Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_14-b03)
        Java HotSpot(TM) Client VM (build 1.5.0_14-b03, mixed mode, sharing)

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows XP [Version 5.1.2600]

        A DESCRIPTION OF THE PROBLEM :
        When using HttpsUrlConnection in in conjunction with authenticated proxies, an endless recursion can occur when the proxy reacts unexpected. See coding below.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Run the coding supplied, the ProxyConnect class first.

        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        ProxyTest should fail cleanly.
        ACTUAL -
        StackOverFlowError

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.io.InputStream;
        import java.net.ServerSocket;
        import java.net.Socket;

        /**
         * TODO_DOC add type comment
         * <p/>
         * @author Richard Birenheide (D035816)
         */
        public class ProxyConnect {
        /**
        * TODO_DOC add method comment
        * <p/>
        * @param args
        * @throws Exception
        */
        public static void main(String[] args) throws Exception {
        ServerSocket ss = new ServerSocket(9000);
        while (true) {
        Socket s = ss.accept();
        InputStream is = s.getInputStream();
        byte[] buffer = new byte[10000];
        is.read(buffer);
        System.out.println(new String(buffer));
        // Thread.sleep(10000);
        s.getOutputStream().write("HTTP/1.1 407\nProxy-Authenticate:Basic realm=\"WallyWorld\"\n\n".getBytes());
        s.close();

        s = ss.accept();
        is = s.getInputStream();
        buffer = new byte[10000];
        is.read(buffer);
        System.out.println(new String(buffer));
        // Thread.sleep(10000);
        // s.getOutputStream().write("HTTP/1.0 407 \n\n".getBytes());
        s.close();
        }
        }
        }

        ---------------------------------------------------------------------------------------------------
        import java.net.Authenticator;
        import java.net.InetSocketAddress;
        import java.net.PasswordAuthentication;
        import java.net.Proxy;
        import java.net.URL;

        import javax.net.ssl.HttpsURLConnection;

        /**
         * TODO_DOC add type comment
         * <p/>
         * @author Richard Birenheide (D035816)
         */
        public class ProxyTest {

        /**
        * TODO_DOC add method comment
        * <p/>
        * @param args
        */
        public static void main(String[] args) throws Exception {
        URL url = new URL("https://localhost:80");
        Authenticator.setDefault(new Authenticator() {
        @Override
        protected PasswordAuthentication getPasswordAuthentication() {
        System.out.println("Called");
        return new PasswordAuthentication("Test", "Test".toCharArray());
        }
        });
        HttpsURLConnection conn = (HttpsURLConnection) url.openConnection(new Proxy(Proxy.Type.HTTP, new InetSocketAddress("localhost", 9000)));
        conn.setAllowUserInteraction(true);
        conn.setUseCaches(false);
        conn.addRequestProperty("Proxy-Authorization", "blabla");
        conn.connect();
        }

        }
        ---------- END SOURCE ----------

              chegar Chris Hegarty
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: