updated ning to 1.6.1

This commit is contained in:
Adrian Cole 2011-02-22 23:40:34 -08:00
parent 5075032edd
commit cc37ac1847
2 changed files with 13 additions and 12 deletions

View File

@ -61,7 +61,7 @@
<dependency> <dependency>
<groupId>com.ning</groupId> <groupId>com.ning</groupId>
<artifactId>async-http-client</artifactId> <artifactId>async-http-client</artifactId>
<version>1.4.1</version> <version>1.6.1</version>
</dependency> </dependency>
<dependency> <dependency>
<groupId>org.mortbay.jetty</groupId> <groupId>org.mortbay.jetty</groupId>

View File

@ -59,6 +59,7 @@ 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.RequestBuilder;
import com.ning.http.client.Response; import com.ning.http.client.Response;
import com.ning.http.client.generators.InputStreamBodyGenerator;
/** /**
* Todo Write me * Todo Write me
@ -78,8 +79,8 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
@Inject @Inject
public NingHttpCommandExecutorService(AsyncHttpClient client, ConvertToNingRequest convertToNingRequest, public NingHttpCommandExecutorService(AsyncHttpClient client, ConvertToNingRequest convertToNingRequest,
ConvertToJCloudsResponse convertToJCloudsResponse, DelegatingRetryHandler retryHandler, ConvertToJCloudsResponse convertToJCloudsResponse, DelegatingRetryHandler retryHandler,
DelegatingErrorHandler errorHandler) { DelegatingErrorHandler errorHandler) {
this.client = client; this.client = client;
this.convertToNingRequest = convertToNingRequest; this.convertToNingRequest = convertToNingRequest;
this.convertToJCloudsResponse = convertToJCloudsResponse; this.convertToJCloudsResponse = convertToJCloudsResponse;
@ -130,7 +131,7 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
public Request apply(HttpRequest request) { public Request apply(HttpRequest request) {
for (HttpRequestFilter filter : request.getFilters()) { for (HttpRequestFilter filter : request.getFilters()) {
filter.filter(request); request = filter.filter(request);
} }
RequestBuilder builder = new RequestBuilder(request.getMethod()); RequestBuilder builder = new RequestBuilder(request.getMethod());
@ -140,22 +141,22 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
boolean chunked = "chunked".equals(request.getFirstHeaderOrNull("Transfer-Encoding")); boolean chunked = "chunked".equals(request.getFirstHeaderOrNull("Transfer-Encoding"));
if (request.getPayload().getContentMetadata().getContentMD5() != null) if (request.getPayload().getContentMetadata().getContentMD5() != null)
builder.addHeader("Content-MD5", builder.addHeader("Content-MD5", CryptoStreams.base64(request.getPayload().getContentMetadata()
CryptoStreams.base64(request.getPayload().getContentMetadata().getContentMD5())); .getContentMD5()));
if (request.getPayload().getContentMetadata().getContentType() != null) if (request.getPayload().getContentMetadata().getContentType() != null)
builder.addHeader(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentMetadata().getContentType()); builder.addHeader(HttpHeaders.CONTENT_TYPE, request.getPayload().getContentMetadata().getContentType());
if (request.getPayload().getContentMetadata().getContentLanguage() != null) if (request.getPayload().getContentMetadata().getContentLanguage() != null)
builder.addHeader(HttpHeaders.CONTENT_LANGUAGE, request.getPayload().getContentMetadata() builder.addHeader(HttpHeaders.CONTENT_LANGUAGE, request.getPayload().getContentMetadata()
.getContentLanguage()); .getContentLanguage());
if (request.getPayload().getContentMetadata().getContentEncoding() != null) if (request.getPayload().getContentMetadata().getContentEncoding() != null)
builder.addHeader(HttpHeaders.CONTENT_ENCODING, request.getPayload().getContentMetadata() builder.addHeader(HttpHeaders.CONTENT_ENCODING, request.getPayload().getContentMetadata()
.getContentEncoding()); .getContentEncoding());
if (request.getPayload().getContentMetadata().getContentDisposition() != null) if (request.getPayload().getContentMetadata().getContentDisposition() != null)
builder.addHeader("Content-Disposition", request.getPayload().getContentMetadata() builder.addHeader("Content-Disposition", request.getPayload().getContentMetadata()
.getContentDisposition()); .getContentDisposition());
if (!chunked) { if (!chunked) {
Long length = checkNotNull(request.getPayload().getContentMetadata().getContentLength(), Long length = checkNotNull(request.getPayload().getContentMetadata().getContentLength(),
"payload.getContentLength"); "payload.getContentLength");
builder.addHeader(HttpHeaders.CONTENT_LENGTH, length.toString()); builder.addHeader(HttpHeaders.CONTENT_LENGTH, length.toString());
} }
setPayload(builder, payload); setPayload(builder, payload);
@ -177,7 +178,7 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
if (payload instanceof FilePayload) { if (payload instanceof FilePayload) {
requestBuilder.setBody(((FilePayload) payload).getRawContent()); requestBuilder.setBody(((FilePayload) payload).getRawContent());
} else { } else {
requestBuilder.setBody(payload.getInput()); requestBuilder.setBody(new InputStreamBodyGenerator(payload.getInput()));
} }
} }
} }
@ -204,7 +205,7 @@ public class NingHttpCommandExecutorService implements HttpCommandExecutorServic
if (payload != null) if (payload != null)
payload.getContentMetadata().setPropertiesFromHttpHeaders(headers); payload.getContentMetadata().setPropertiesFromHttpHeaders(headers);
return new HttpResponse(nativeResponse.getStatusCode(), nativeResponse.getStatusText(), payload, return new HttpResponse(nativeResponse.getStatusCode(), nativeResponse.getStatusText(), payload,
RestAnnotationProcessor.filterOutContentHeaders(headers)); RestAnnotationProcessor.filterOutContentHeaders(headers));
} }
} }
} }