From 3d633b1768517c26631b174d7b98f0b55c3960db Mon Sep 17 00:00:00 2001 From: Hubert Iwaniuk Date: Mon, 29 Nov 2010 17:41:24 +0100 Subject: [PATCH] Big file upload and download fixes --- sandbox/ning/pom.xml | 8 +- .../ning/NingHttpCommandExecutorService.java | 79 ++++++++----------- .../NingHttpCommandExecutorServiceTest.java | 8 +- 3 files changed, 35 insertions(+), 60 deletions(-) diff --git a/sandbox/ning/pom.xml b/sandbox/ning/pom.xml index 0cd3b31c10..d24559668c 100644 --- a/sandbox/ning/pom.xml +++ b/sandbox/ning/pom.xml @@ -42,13 +42,7 @@ com.ning async-http-client - 1.3.1 - - - com.google.collections - google-collections - - + 1.4.0 org.mortbay.jetty diff --git a/sandbox/ning/src/main/java/org/jclouds/http/ning/NingHttpCommandExecutorService.java b/sandbox/ning/src/main/java/org/jclouds/http/ning/NingHttpCommandExecutorService.java index fef934692f..a99212590b 100644 --- a/sandbox/ning/src/main/java/org/jclouds/http/ning/NingHttpCommandExecutorService.java +++ b/sandbox/ning/src/main/java/org/jclouds/http/ning/NingHttpCommandExecutorService.java @@ -19,33 +19,6 @@ package org.jclouds.http.ning; -import static com.google.common.base.Preconditions.checkNotNull; -import static com.google.common.base.Throwables.propagate; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.util.List; -import java.util.Map.Entry; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; - -import javax.inject.Singleton; -import javax.ws.rs.core.HttpHeaders; - -import org.jclouds.crypto.CryptoStreams; -import org.jclouds.http.HttpCommand; -import org.jclouds.http.HttpCommandExecutorService; -import org.jclouds.http.HttpRequest; -import org.jclouds.http.HttpRequestFilter; -import org.jclouds.http.HttpResponse; -import org.jclouds.http.HttpUtils; -import org.jclouds.http.handlers.DelegatingErrorHandler; -import org.jclouds.http.handlers.DelegatingRetryHandler; -import org.jclouds.http.internal.BaseHttpCommandExecutorService; -import org.jclouds.io.Payload; -import org.jclouds.io.Payloads; - import com.google.common.base.Function; import com.google.common.base.Throwables; import com.google.common.collect.LinkedHashMultimap; @@ -59,7 +32,31 @@ import com.ning.http.client.AsyncHttpClient; import com.ning.http.client.Request; import com.ning.http.client.RequestBuilder; import com.ning.http.client.Response; -import com.ning.http.client.Request.EntityWriter; +import org.jclouds.crypto.CryptoStreams; +import org.jclouds.http.HttpCommand; +import org.jclouds.http.HttpCommandExecutorService; +import org.jclouds.http.HttpRequest; +import org.jclouds.http.HttpRequestFilter; +import org.jclouds.http.HttpResponse; +import org.jclouds.http.HttpUtils; +import org.jclouds.http.handlers.DelegatingErrorHandler; +import org.jclouds.http.handlers.DelegatingRetryHandler; +import org.jclouds.http.internal.BaseHttpCommandExecutorService; +import org.jclouds.io.Payload; +import org.jclouds.io.Payloads; +import org.jclouds.io.payloads.FilePayload; + +import javax.inject.Singleton; +import javax.ws.rs.core.HttpHeaders; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Map.Entry; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.Future; + +import static com.google.common.base.Preconditions.checkNotNull; +import static com.google.common.base.Throwables.propagate; /** * Todo Write me @@ -128,21 +125,7 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic @Singleton public static class ConvertToNingRequest implements Function { - private static class PayloadEntityWriter implements EntityWriter { - private final Payload payload; - - public PayloadEntityWriter(Payload payload) { - this.payload = payload; - } - - @Override - public void writeEntity(OutputStream out) throws IOException { - payload.writeTo(out); - - } - } - - public Request apply(HttpRequest request) { + public Request apply(HttpRequest request) { for (HttpRequestFilter filter : request.getFilters()) { filter.filter(request); @@ -188,9 +171,13 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic return builder.build(); } - void setPayload(RequestBuilder requestBuilder, Payload payload) { - requestBuilder.setBody(new PayloadEntityWriter(payload)); - } + void setPayload(RequestBuilder requestBuilder, Payload payload) { + if (payload instanceof FilePayload) { + requestBuilder.setBody(((FilePayload) payload).getRawContent()); + } else { + requestBuilder.setBody(payload.getInput()); + } + } } @Singleton diff --git a/sandbox/ning/src/test/java/org/jclouds/http/ning/NingHttpCommandExecutorServiceTest.java b/sandbox/ning/src/test/java/org/jclouds/http/ning/NingHttpCommandExecutorServiceTest.java index 527c301cc7..7fe8eb1774 100644 --- a/sandbox/ning/src/test/java/org/jclouds/http/ning/NingHttpCommandExecutorServiceTest.java +++ b/sandbox/ning/src/test/java/org/jclouds/http/ning/NingHttpCommandExecutorServiceTest.java @@ -62,10 +62,4 @@ public class NingHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorS props.setProperty(PROPERTY_IO_WORKER_THREADS, 3 + ""); props.setProperty(PROPERTY_USER_THREADS, 0 + ""); } - - // OOM - @Test(enabled = false, invocationCount = 1, timeOut = 5000) - public void testGetBigFile() throws ExecutionException, InterruptedException, TimeoutException, IOException { - } - -} \ No newline at end of file +}