From a72efaea6d136131e0bbc9be260a7dba0a7670e2 Mon Sep 17 00:00:00 2001 From: Adrian Cole Date: Sun, 21 Feb 2010 10:43:00 -0800 Subject: [PATCH] Issue 177: support scheme-only redirects --- .../handlers/AWSRedirectionRetryHandler.java | 3 +- .../org/jclouds/aws/s3/util/S3UtilsTest.java | 2 +- .../internal/StubAsyncBlobStore.java | 2 +- .../java/org/jclouds/http/HttpCommand.java | 5 +-- .../http/TransformingHttpCommandImpl.java | 3 +- .../handlers/RedirectionRetryHandler.java | 6 ++-- .../http/TransformingHttpCommandImplTest.java | 33 +++++++++++++++++-- .../gae/GaeHttpCommandExecutorService.java | 3 +- 8 files changed, 46 insertions(+), 11 deletions(-) diff --git a/aws/core/src/main/java/org/jclouds/aws/handlers/AWSRedirectionRetryHandler.java b/aws/core/src/main/java/org/jclouds/aws/handlers/AWSRedirectionRetryHandler.java index 12eab594b7..65e42087c2 100755 --- a/aws/core/src/main/java/org/jclouds/aws/handlers/AWSRedirectionRetryHandler.java +++ b/aws/core/src/main/java/org/jclouds/aws/handlers/AWSRedirectionRetryHandler.java @@ -66,7 +66,8 @@ public class AWSRedirectionRetryHandler extends RedirectionRetryHandler { // http://developer.amazonwebservices.com/connect/thread.jspa?messageID=72287𑩟 return backoffHandler.shouldRetryRequest(command, response); } else { - command.changeHostAndPortTo(host, command.getRequest().getEndpoint().getPort()); + command.changeSchemeHostAndPortTo(command.getRequest().getEndpoint() + .getScheme(), host, command.getRequest().getEndpoint().getPort()); } return true; } else { diff --git a/aws/core/src/test/java/org/jclouds/aws/s3/util/S3UtilsTest.java b/aws/core/src/test/java/org/jclouds/aws/s3/util/S3UtilsTest.java index 3208ecb042..0bb492c879 100644 --- a/aws/core/src/test/java/org/jclouds/aws/s3/util/S3UtilsTest.java +++ b/aws/core/src/test/java/org/jclouds/aws/s3/util/S3UtilsTest.java @@ -94,7 +94,7 @@ public class S3UtilsTest { return false; } - public void changeHostAndPortTo(String host, int port) { + public void changeSchemeHostAndPortTo(String scheme, String host, int port) { } public void changeToGETRequest() { diff --git a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/StubAsyncBlobStore.java b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/StubAsyncBlobStore.java index 76f37af715..1756791034 100755 --- a/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/StubAsyncBlobStore.java +++ b/blobstore/src/test/java/org/jclouds/blobstore/integration/internal/StubAsyncBlobStore.java @@ -441,7 +441,7 @@ public class StubAsyncBlobStore extends BaseAsyncBlobStore { return false; } - public void changeHostAndPortTo(String host, int port) { + public void changeSchemeHostAndPortTo(String scheme, String host, int port) { } public void changeToGETRequest() { diff --git a/core/src/main/java/org/jclouds/http/HttpCommand.java b/core/src/main/java/org/jclouds/http/HttpCommand.java index 3ce547d4fd..c926968ce7 100644 --- a/core/src/main/java/org/jclouds/http/HttpCommand.java +++ b/core/src/main/java/org/jclouds/http/HttpCommand.java @@ -18,7 +18,6 @@ */ package org.jclouds.http; - /** * Command whose endpoint is an http service. * @@ -48,8 +47,10 @@ public interface HttpCommand { /** * change the destination of the current http command. typically used in handling redirects. + * + * @param string */ - void changeHostAndPortTo(String host, int port); + void changeSchemeHostAndPortTo(String scheme, String host, int port); /** * change method from GET to HEAD. typically used in handling redirects. diff --git a/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java b/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java index 19d4fc93d7..5746eb94ee 100644 --- a/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java +++ b/core/src/main/java/org/jclouds/http/TransformingHttpCommandImpl.java @@ -84,8 +84,9 @@ public class TransformingHttpCommandImpl implements TransformingHttpCommand request = createMock(GeneratedHttpRequest.class); + TransformingHttpCommandImpl command = new TransformingHttpCommandImpl(null, request, + null); + expect(request.getEndpoint()).andReturn(URI.create("http://localhost/mypath")); + request.setEndpoint(URI.create("https://remotehost:443/mypath")); + Multimap headers = HashMultimap.create(); + expect(request.getHeaders()).andReturn(headers); + replay(request); + command.changeSchemeHostAndPortTo("https", "remotehost", 443); + assertEquals(headers.get(HttpHeaders.HOST), Collections.singletonList("remotehost")); + } @Test diff --git a/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java b/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java index ad29976e74..2681a702d6 100644 --- a/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java +++ b/extensions/gae/src/main/java/org/jclouds/gae/GaeHttpCommandExecutorService.java @@ -160,7 +160,8 @@ public class GaeHttpCommandExecutorService extends BaseHttpCommandExecutorServic HttpRequest request = command.getRequest(); String hostHeader = request.getFirstHeaderOrNull(HttpHeaders.HOST); if (hostHeader != null) { - command.changeHostAndPortTo(hostHeader, request.getEndpoint().getPort()); + command.changeSchemeHostAndPortTo(request.getEndpoint().getScheme(), hostHeader, request + .getEndpoint().getPort()); } }