Big file upload and download fixes

This commit is contained in:
Hubert Iwaniuk 2010-11-29 17:41:24 +01:00
parent fa0ed8664d
commit 3d633b1768
3 changed files with 35 additions and 60 deletions

View File

@ -42,13 +42,7 @@
<dependency>
<groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId>
<version>1.3.1</version>
<exclusions>
<exclusion> <!-- we use guava -->
<groupId>com.google.collections</groupId>
<artifactId>google-collections</artifactId>
</exclusion>
</exclusions>
<version>1.4.0</version>
</dependency>
<dependency>
<groupId>org.mortbay.jetty</groupId>

View File

@ -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,20 +125,6 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
@Singleton
public static class ConvertToNingRequest implements Function<HttpRequest, Request> {
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) {
for (HttpRequestFilter filter : request.getFilters()) {
@ -189,7 +172,11 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
}
void setPayload(RequestBuilder requestBuilder, Payload payload) {
requestBuilder.setBody(new PayloadEntityWriter(payload));
if (payload instanceof FilePayload) {
requestBuilder.setBody(((FilePayload) payload).getRawContent());
} else {
requestBuilder.setBody(payload.getInput());
}
}
}

View File

@ -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 {
}
}