JDK-8029127 : Redirected POST request throws IllegalStateException on HttpURLConnection.getInputStream
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.net
  • Affected Version: 8
  • Priority: P2
  • Status: Closed
  • Resolution: Fixed
  • OS: windows_7
  • CPU: x86_64
  • Submitted: 2013-11-25
  • Updated: 2014-01-08
  • Resolved: 2013-12-03
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 8
8 b120Fixed
Related Reports
Relates :  
Description
A redirect on a POST request does not work with Java 8. This work without any problems with Java 6 and Java 7. It is a regression.

Full java version:
java version "1.8.0-ea"
Java(TM) SE Runtime Environment (build 1.8.0-ea-b115)
Java HotSpot(TM) Client VM (build 25.0-b57, mixed mode, sharing)

OS: Windows 8

The follow code sequence:

            URL url = new URL( job.getUrl() + "build?delay=0sec" );
            HttpURLConnection connection = (HttpURLConnection)url.openConnection();
            connection.setConnectTimeout( 20000 );
            connection.setReadTimeout( 20000 );
            connection.setRequestMethod( "POST" );
            inputStream = connection.getInputStream();

produce the follow exception:

java.lang.IllegalStateException: connect in progress
    at sun.net.www.protocol.http.HttpURLConnection.setRequestMethod(HttpURLConnection.java:515)
    at sun.net.www.protocol.http.HttpURLConnection.followRedirect0(HttpURLConnection.java:2597)
    at sun.net.www.protocol.http.HttpURLConnection.followRedirect(HttpURLConnection.java:2529)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1723)
    at sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1394)
    at com.inet.tests.monitor.gui.GuiController.executeJob(GuiController.java:181)

The wireshark show the follow on the network:

POST /job/DTRAPIDocInternal/build?delay=0sec HTTP/1.1
User-Agent: Java/1.8.0-ea
Host: hudson
Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2
Connection: keep-alive

HTTP/1.1 302 Found
Server: Winstone Servlet Engine v0.9.10
Location: http://hudson/job/DTRAPIDocInternal/
Content-Length: 0
Connection: Keep-Alive
Date: Mon, 25 Nov 2013 13:21:27 GMT
X-Powered-By: Servlet/2.5 (Winstone/0.9.10)
Comments
SQE approves this critical request. This is a regression. Regression test coverage is good.
04-12-2013

Release team: Approved for fixing
03-12-2013

critical request justification: It's a fairly serious regression that will definitely affect many networking apps, and the fix is very simple.
02-12-2013

This would appear to be a behavior change as a result of 8010464: Evolve java networking same origin policy, see http://hg.openjdk.java.net/jdk8/tl/jdk/rev/93a268759ec3
29-11-2013

This happens in the case when we switch the POST to a GET and call setRequestMethod() a second time. need to avoid the connecting check by calling super.setRequestMethod().
29-11-2013