mirror of https://github.com/apache/jclouds.git
Issue 199: updated to latest ning
This commit is contained in:
parent
f9a233274f
commit
cfa9f7f7da
|
@ -42,7 +42,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>com.ning</groupId>
|
<groupId>com.ning</groupId>
|
||||||
<artifactId>async-http-client</artifactId>
|
<artifactId>async-http-client</artifactId>
|
||||||
<version>1.1.0</version>
|
<version>1.3.1</version>
|
||||||
<exclusions>
|
<exclusions>
|
||||||
<exclusion> <!-- we use guava -->
|
<exclusion> <!-- we use guava -->
|
||||||
<groupId>com.google.collections</groupId>
|
<groupId>com.google.collections</groupId>
|
||||||
|
|
|
@ -31,7 +31,6 @@ import java.util.concurrent.ExecutionException;
|
||||||
import java.util.concurrent.Future;
|
import java.util.concurrent.Future;
|
||||||
|
|
||||||
import javax.inject.Singleton;
|
import javax.inject.Singleton;
|
||||||
import javax.ws.rs.HttpMethod;
|
|
||||||
import javax.ws.rs.core.HttpHeaders;
|
import javax.ws.rs.core.HttpHeaders;
|
||||||
|
|
||||||
import org.jclouds.crypto.CryptoStreams;
|
import org.jclouds.crypto.CryptoStreams;
|
||||||
|
@ -58,6 +57,7 @@ import com.google.common.util.concurrent.ListenableFuture;
|
||||||
import com.google.inject.Inject;
|
import com.google.inject.Inject;
|
||||||
import com.ning.http.client.AsyncHttpClient;
|
import com.ning.http.client.AsyncHttpClient;
|
||||||
import com.ning.http.client.Request;
|
import com.ning.http.client.Request;
|
||||||
|
import com.ning.http.client.RequestBuilder;
|
||||||
import com.ning.http.client.Response;
|
import com.ning.http.client.Response;
|
||||||
import com.ning.http.client.Request.EntityWriter;
|
import com.ning.http.client.Request.EntityWriter;
|
||||||
|
|
||||||
|
@ -148,51 +148,47 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
|
||||||
filter.filter(request);
|
filter.filter(request);
|
||||||
}
|
}
|
||||||
|
|
||||||
AsyncHttpClient client = new AsyncHttpClient();
|
RequestBuilder builder = new RequestBuilder(request.getMethod());
|
||||||
AsyncHttpClient.BoundRequestBuilder nativeRequestBuilder;
|
builder.setUrl(request.getEndpoint().toASCIIString());
|
||||||
String endpoint = request.getEndpoint().toASCIIString();
|
|
||||||
if (request.getMethod().equals(HttpMethod.HEAD)) {
|
|
||||||
nativeRequestBuilder = client.prepareHead(endpoint);
|
|
||||||
} else if (request.getMethod().equals(HttpMethod.GET)) {
|
|
||||||
nativeRequestBuilder = client.prepareGet(endpoint);
|
|
||||||
} else if (request.getMethod().equals(HttpMethod.DELETE)) {
|
|
||||||
nativeRequestBuilder = client.prepareDelete(endpoint);
|
|
||||||
} else if (request.getMethod().equals(HttpMethod.PUT)) {
|
|
||||||
nativeRequestBuilder = client.preparePut(endpoint);
|
|
||||||
} else if (request.getMethod().equals(HttpMethod.POST)) {
|
|
||||||
nativeRequestBuilder = client.preparePost(endpoint);
|
|
||||||
} else {
|
|
||||||
throw new UnsupportedOperationException(request.getMethod());
|
|
||||||
}
|
|
||||||
Payload payload = request.getPayload();
|
Payload payload = request.getPayload();
|
||||||
if (payload != null) {
|
if (payload != null) {
|
||||||
boolean chunked = "chunked".equals(request.getFirstHeaderOrNull("Transfer-Encoding"));
|
boolean chunked = "chunked".equals(request.getFirstHeaderOrNull("Transfer-Encoding"));
|
||||||
|
|
||||||
if (request.getPayload().getContentMD5() != null)
|
if (request.getPayload().getContentMetadata().getContentMD5() != null)
|
||||||
nativeRequestBuilder
|
builder.addHeader("Content-MD5", CryptoStreams.base64(request.getPayload().getContentMetadata()
|
||||||
.addHeader("Content-MD5", CryptoStreams.base64(request.getPayload().getContentMD5()));
|
.getContentMD5()));
|
||||||
if (request.getPayload().getContentType() != null)
|
if (request.getPayload().getContentMetadata().getContentType() != null)
|
||||||
nativeRequestBuilder.addHeader(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentType());
|
builder.addHeader(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentMetadata().getContentType());
|
||||||
|
if (request.getPayload().getContentMetadata().getContentLanguage() != null)
|
||||||
|
builder.addHeader(HttpHeaders.CONTENT_LANGUAGE, request.getPayload().getContentMetadata()
|
||||||
|
.getContentLanguage());
|
||||||
|
if (request.getPayload().getContentMetadata().getContentEncoding() != null)
|
||||||
|
builder.addHeader(HttpHeaders.CONTENT_ENCODING, request.getPayload().getContentMetadata()
|
||||||
|
.getContentEncoding());
|
||||||
|
if (request.getPayload().getContentMetadata().getContentDisposition() != null)
|
||||||
|
builder.addHeader("Content-Disposition", request.getPayload().getContentMetadata()
|
||||||
|
.getContentDisposition());
|
||||||
if (!chunked) {
|
if (!chunked) {
|
||||||
Long length = checkNotNull(request.getPayload().getContentLength(), "payload.getContentLength");
|
Long length = checkNotNull(request.getPayload().getContentMetadata().getContentLength(),
|
||||||
nativeRequestBuilder.addHeader(HttpHeaders.CONTENT_LENGTH, length.toString());
|
"payload.getContentLength");
|
||||||
|
builder.addHeader(HttpHeaders.CONTENT_LENGTH, length.toString());
|
||||||
}
|
}
|
||||||
setPayload(nativeRequestBuilder, payload);
|
setPayload(builder, payload);
|
||||||
} else {
|
} else {
|
||||||
nativeRequestBuilder.addHeader(HttpHeaders.CONTENT_LENGTH, "0");
|
builder.addHeader(HttpHeaders.CONTENT_LENGTH, "0");
|
||||||
}
|
}
|
||||||
|
|
||||||
nativeRequestBuilder.addHeader(HttpHeaders.USER_AGENT, USER_AGENT);
|
builder.addHeader(HttpHeaders.USER_AGENT, USER_AGENT);
|
||||||
for (String header : request.getHeaders().keySet()) {
|
for (String header : request.getHeaders().keySet()) {
|
||||||
for (String value : request.getHeaders().get(header)) {
|
for (String value : request.getHeaders().get(header)) {
|
||||||
nativeRequestBuilder.addHeader(header, value);
|
builder.addHeader(header, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return nativeRequestBuilder.build();
|
return builder.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
void setPayload(AsyncHttpClient.BoundRequestBuilder requestBuilder, Payload payload) {
|
void setPayload(RequestBuilder requestBuilder, Payload payload) {
|
||||||
requestBuilder.setBody(new PayloadEntityWriter(payload));
|
requestBuilder.setBody(new PayloadEntityWriter(payload));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -45,19 +45,11 @@ import com.google.inject.Module;
|
||||||
*
|
*
|
||||||
* @author Adrian Cole
|
* @author Adrian Cole
|
||||||
*/
|
*/
|
||||||
public class NingHttpCommandExecutorServiceTest extends
|
public class NingHttpCommandExecutorServiceTest extends BaseHttpCommandExecutorServiceIntegrationTest {
|
||||||
BaseHttpCommandExecutorServiceIntegrationTest {
|
|
||||||
static {
|
static {
|
||||||
System.setProperty("http.conn-manager.timeout", 1000 + "");
|
System.setProperty("http.conn-manager.timeout", 1000 + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
@DataProvider(name = "gets")
|
|
||||||
@Override
|
|
||||||
// ning doesn't support spaces
|
|
||||||
public Object[][] createData() {
|
|
||||||
return new Object[][] { { "object" }, { "/path" }, { "unic₪de" }, { "qu?stion" } };
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Module createConnectionModule() {
|
protected Module createConnectionModule() {
|
||||||
return new NingHttpCommandExecutorServiceModule();
|
return new NingHttpCommandExecutorServiceModule();
|
||||||
}
|
}
|
||||||
|
@ -71,17 +63,9 @@ public class NingHttpCommandExecutorServiceTest extends
|
||||||
props.setProperty(PROPERTY_USER_THREADS, 0 + "");
|
props.setProperty(PROPERTY_USER_THREADS, 0 + "");
|
||||||
}
|
}
|
||||||
|
|
||||||
// ning doesn't support spaces
|
|
||||||
@Test(invocationCount = 1, expectedExceptions = RuntimeException.class)
|
|
||||||
public void testSpaceInUri() throws MalformedURLException, ExecutionException,
|
|
||||||
InterruptedException, TimeoutException {
|
|
||||||
assertEquals(client.synch("sp ace").trim(), XML);
|
|
||||||
}
|
|
||||||
|
|
||||||
// OOM
|
// OOM
|
||||||
@Test(enabled = false, invocationCount = 1, timeOut = 5000)
|
@Test(enabled = false, invocationCount = 1, timeOut = 5000)
|
||||||
public void testGetBigFile() throws ExecutionException, InterruptedException, TimeoutException,
|
public void testGetBigFile() throws ExecutionException, InterruptedException, TimeoutException, IOException {
|
||||||
IOException {
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
Reference in New Issue