SPR-5653: RestTemplate handles redirects incorrectly

This commit is contained in:
Arjen Poutsma
2009-04-09 11:03:35 +00:00
parent 859497b171
commit 7e3e79ca22
2 changed files with 73 additions and 14 deletions

View File

@@ -28,9 +28,9 @@ import org.springframework.util.Assert;
* {@link ClientHttpRequestFactory} implementation that uses standard J2SE facilities.
*
* @author Arjen Poutsma
* @since 3.0
* @see java.net.HttpURLConnection
* @see CommonsClientHttpRequestFactory
* @since 3.0
*/
public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory {
@@ -43,17 +43,25 @@ public class SimpleClientHttpRequestFactory implements ClientHttpRequestFactory
}
/**
* Template method for preparing the given {@link HttpURLConnection}.
* <p>The default implementation prepares the connection for input and output, and sets the HTTP method.
* Template method for preparing the given {@link HttpURLConnection}. <p>The default implementation prepares the
* connection for input and output, and sets the HTTP method.
*
* @param connection the connection to prepare
* @param httpMethod the HTTP request method ({@code GET}, {@code POST}, etc.)
* @throws IOException in case of I/O errors
*/
protected void prepareConnection(HttpURLConnection connection, String httpMethod) throws IOException {
connection.setDoInput(true);
if ("GET".equals(httpMethod)) {
connection.setInstanceFollowRedirects(true);
}
else {
connection.setInstanceFollowRedirects(false);
}
if ("PUT".equals(httpMethod) || "POST".equals(httpMethod)) {
connection.setDoOutput(true);
} else {
}
else {
connection.setDoOutput(false);
}
connection.setRequestMethod(httpMethod);