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

Redirect problem with HttpsURLConnection using a proxy

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3 P3
    • 6
    • 5.0
    • core-libs
    • beta
    • x86
    • windows_2000, windows_xp

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

        ADDITIONAL OS VERSION INFORMATION :
        Microsoft Windows 2000 [Version 5.00.2195]

        EXTRA RELEVANT SYSTEM CONFIGURATION :
        The client application runs on Windows 2000.

        The proxy server (Squid 2.5-STABLE-3-2) runs on Fidora Linux Core 1.

        The webserver (Apache/2.0.50 (Unix) mod_ssl/2 OpenSSL/0.9.6c PHP/4.3.8) runs on SuSE Linux 8.0.




        A DESCRIPTION OF THE PROBLEM :
        When using the HttpsURLConnection to retrieve an URL over a proxy the implementation generates an invalid HTTP header in the case of a redirect by the webserver to another URL.

        In detail each of the first two lines of the HTTP header will contain a GET request. The first line contains the redirected URL an the second line contains the initial URL. It seems to be, that the second line should be the referrer header field.

        This bug also exists in all Java 1.4 versions and of course in all Plug-Ins
        of 1.4.x and 1.5. The bug doesn't appear without proxy.

        STEPS TO FOLLOW TO REPRODUCE THE PROBLEM :
        Setup a proxy server and a ssl webserver.
        On the webserver two files are needed:

        1. /redirect.php:

        <?php
        // please correct the redirect URL for your test environment!
        header('Location: https://amrum.devel.pago.de/index.php&#39;, TRUE, 302 );
        ?>

        2: /index.php: this file can be any html document or php script.

        Edit the source of HttpsClass and correct the proxy settings and initial request URL accordingly to your test environment.

        Perhaps you need to register the ssl server certificate in the jre keystore.

        Run the class HttpsTest. This will produce the failure.




        EXPECTED VERSUS ACTUAL BEHAVIOR :
        EXPECTED -
        The class HttpsTest should execute normally without any exception.
        ACTUAL -
        java.io.IOException: Server returned HTTP response code: 400 for URL: https://amrum.devel.pago.de/index.php
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1133)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
        at HttpsTest.main(HttpsTest.java:19)
        Using proxy: true


        ERROR MESSAGES/STACK TRACES THAT OCCUR :
        java.io.IOException: Server returned HTTP response code: 400 for URL: https://amrum.devel.pago.de/index.php
        at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1133)
        at sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:234)
        at HttpsTest.main(HttpsTest.java:19)
        Using proxy: true

        Rest of the information included in the attachment Log.

        REPRODUCIBILITY :
        This bug can be reproduced always.

        ---------- BEGIN SOURCE ----------
        import java.net.HttpURLConnection;
        import java.net.URL;

        import javax.net.ssl.HttpsURLConnection;

        public class HttpsTest
        {
          public static void main( String[] args )
          {
            HttpURLConnection con = null;
            try
            {
              HttpsURLConnection.setDefaultAllowUserInteraction( true );
              HttpsURLConnection.setFollowRedirects( true );
              System.setProperty( "javax.net.debug", "all" );
              // please correct the proxy settings and request URL accordingly to your environment
              System.setProperty( "https.proxyHost", "nimdenbus" );
              System.setProperty( "https.proxyPort", "3128" );
              URL url = new URL( "https://amrum.devel.pago.de/redirect.php" );
              con = ( HttpURLConnection )url.openConnection();
              con.getInputStream();
            }
            catch( Exception e )
            {
              e.printStackTrace();
            }
            finally
            {
              if( con != null )
              {
                System.out.println( "Using proxy: " + con.usingProxy() );
              }
            }
            System.exit( 0 );
          }
        }
        ---------- END SOURCE ----------

        CUSTOMER SUBMITTED WORKAROUND :
        Make the redirect on your own:
        Disable following of redirect...

        HttpsURLConnection.setFollowRedirects( false );

        ...read the Location HTTP header field, build the complete redirect url (if necessary) and perform the following request. That's it.
        ###@###.### 2005-1-11 13:25:44 GMT

              yuwangsunw Yujiang Wang (Inactive)
              ndcosta Nelson Dcosta (Inactive)
              Votes:
              0 Vote for this issue
              Watchers:
              0 Start watching this issue

                Created:
                Updated:
                Resolved:
                Imported:
                Indexed: