From 865005afd977976e98a289b744547fa287262ee5 Mon Sep 17 00:00:00 2001 From: adriancole Date: Fri, 1 Feb 2013 15:09:31 -0800 Subject: [PATCH] fix issue #1289 bug in zero length put --- .../http/internal/JavaUrlHttpCommandExecutorService.java | 4 +++- .../http/BaseHttpCommandExecutorServiceIntegrationTest.java | 5 +++++ core/src/test/java/org/jclouds/http/BaseJettyTest.java | 2 +- .../java/org/jclouds/http/IntegrationTestAsyncClient.java | 5 +++++ .../test/java/org/jclouds/http/IntegrationTestClient.java | 2 ++ 5 files changed, 16 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java index 83ffe7d9ea..21d4c9b1eb 100644 --- a/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java +++ b/core/src/main/java/org/jclouds/http/internal/JavaUrlHttpCommandExecutorService.java @@ -222,8 +222,10 @@ public class JavaUrlHttpCommandExecutorService extends BaseHttpCommandExecutorSe } else { connection.setRequestProperty(CONTENT_LENGTH, "0"); // for some reason POST/PUT undoes the content length header above. - if (ImmutableSet.of("POST", "PUT").contains(connection.getRequestMethod())) + if (ImmutableSet.of("POST", "PUT").contains(connection.getRequestMethod())) { connection.setFixedLengthStreamingMode(0); + connection.setDoOutput(true); + } } return connection; } diff --git a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java index 96f019c8b2..607dcff8b4 100644 --- a/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java +++ b/core/src/test/java/org/jclouds/http/BaseHttpCommandExecutorServiceIntegrationTest.java @@ -262,4 +262,9 @@ public abstract class BaseHttpCommandExecutorServiceIntegrationTest extends Base public void testGetAndParseSax() { assertEquals(client.downloadAndParse(""), "whoppers"); } + + @Test(invocationCount = 5, timeOut = 5000) + public void testZeroLengthPut() { + client.putNothing(""); + } } diff --git a/core/src/test/java/org/jclouds/http/BaseJettyTest.java b/core/src/test/java/org/jclouds/http/BaseJettyTest.java index 82229a2257..0c5e8b814b 100644 --- a/core/src/test/java/org/jclouds/http/BaseJettyTest.java +++ b/core/src/test/java/org/jclouds/http/BaseJettyTest.java @@ -127,7 +127,7 @@ public abstract class BaseJettyTest { response.setStatus(SC_OK); response.getWriter().println(toStringAndClose(request.getInputStream()) + "PUT"); } else { - response.sendError(500, "no content"); + response.setStatus(SC_OK); } } else if (request.getMethod().equals("POST")) { // don't redirect large objects diff --git a/core/src/test/java/org/jclouds/http/IntegrationTestAsyncClient.java b/core/src/test/java/org/jclouds/http/IntegrationTestAsyncClient.java index 44df644a27..17b9d2462f 100644 --- a/core/src/test/java/org/jclouds/http/IntegrationTestAsyncClient.java +++ b/core/src/test/java/org/jclouds/http/IntegrationTestAsyncClient.java @@ -58,6 +58,7 @@ import com.google.inject.Provides; /** * Sample test for the behaviour of our Integration Test jetty server. * + * @see IntegrationTestClient * @author Adrian Cole */ public interface IntegrationTestAsyncClient { @@ -196,6 +197,10 @@ public interface IntegrationTestAsyncClient { } + @PUT + @Path("/objects/{id}") + ListenableFuture putNothing(@PathParam("id") String id); + @Provides StringBuilder newStringBuilder(); diff --git a/core/src/test/java/org/jclouds/http/IntegrationTestClient.java b/core/src/test/java/org/jclouds/http/IntegrationTestClient.java index 559fd3ba20..551857977f 100644 --- a/core/src/test/java/org/jclouds/http/IntegrationTestClient.java +++ b/core/src/test/java/org/jclouds/http/IntegrationTestClient.java @@ -60,6 +60,8 @@ public interface IntegrationTestClient { String downloadAndParse(String id); + void putNothing(String id); + @Provides StringBuilder newStringBuilder(); }