Index: wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java =================================================================== --- wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java (revision 919138) +++ wagon-providers/wagon-http-lightweight/src/main/java/org/apache/maven/wagon/providers/http/LightweightHttpWagon.java (working copy) @@ -24,6 +24,7 @@ import java.net.HttpURLConnection; import java.net.MalformedURLException; import java.net.PasswordAuthentication; +import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; import java.util.List; @@ -60,6 +61,8 @@ private HttpURLConnection putConnection; + public static final int maxRedirects = 20; + /** * Whether to use any proxy cache or not. * @@ -74,22 +77,34 @@ try { URL url = resolveResourceURL( resource ); - URLConnection urlConnection = url.openConnection(); - urlConnection.setRequestProperty( "Accept-Encoding", "gzip" ); - if ( !useCache ) - { - urlConnection.setRequestProperty( "Pragma", "no-cache" ); + int redirectct = 0; + for (; redirectct < maxRedirects; ++redirectct) { + URLConnection urlConnection = url.openConnection(); + urlConnection.setRequestProperty( "Accept-Encoding", "gzip" ); + if ( !useCache ) + { + urlConnection.setRequestProperty( "Pragma", "no-cache" ); + } + InputStream is = urlConnection.getInputStream(); + // handle redirects that the connection refuses to handle, + // like http->https or vice versa + int status = ((HttpURLConnection) urlConnection).getResponseCode(); + if (status >= 300 && status < 400 && status != 305) { + url = new URL( url, urlConnection.getHeaderField( "Location" )); + is.close(); + continue; + } + String contentEncoding = urlConnection.getHeaderField( "Content-Encoding" ); + boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase(contentEncoding); + if (isGZipped) + { + is = new GZIPInputStream( is ); + } + inputData.setInputStream( is ); + resource.setLastModified( urlConnection.getLastModified() ); + resource.setContentLength( urlConnection.getContentLength() ); + break; } - InputStream is = urlConnection.getInputStream(); - String contentEncoding = urlConnection.getHeaderField( "Content-Encoding" ); - boolean isGZipped = contentEncoding == null ? false : "gzip".equalsIgnoreCase(contentEncoding); - if (isGZipped) - { - is = new GZIPInputStream( is ); - } - inputData.setInputStream( is ); - resource.setLastModified( urlConnection.getLastModified() ); - resource.setContentLength( urlConnection.getContentLength() ); } catch ( MalformedURLException e ) {