fix bugs found by pvdyck blind usage of content on HEAD requests and throwing away data on generation of uri

git-svn-id: http://jclouds.googlecode.com/svn/trunk@2738 3d8758e0-26b5-11de-8745-db77d3ebf521
This commit is contained in:
adrian.f.cole 2010-01-29 23:39:47 +00:00
parent 01ad08dfc2
commit 2b3d2b0c48
6 changed files with 53 additions and 42 deletions

View File

@ -64,6 +64,8 @@ public class AtmosStorageClientErrorRetryHandler implements HttpRetryHandler {
return true; return true;
} else if (response.getStatusCode() == 409 || response.getStatusCode() == 400) { } else if (response.getStatusCode() == 409 || response.getStatusCode() == 400) {
byte[] content = HttpUtils.closeClientButKeepContentStream(response); byte[] content = HttpUtils.closeClientButKeepContentStream(response);
// Content can be null in the case of HEAD requests
if (content != null) {
try { try {
AtmosStorageError error = utils.parseAtmosStorageErrorFromContent(command, response, AtmosStorageError error = utils.parseAtmosStorageErrorFromContent(command, response,
new String(content)); new String(content));
@ -75,6 +77,9 @@ public class AtmosStorageClientErrorRetryHandler implements HttpRetryHandler {
} catch (HttpException e) { } catch (HttpException e) {
logger.warn(e, "error parsing response: %s", new String(content)); logger.warn(e, "error parsing response: %s", new String(content));
} }
} else {
command.incrementFailureCount();
}
return true; return true;
} }
return false; return false;

View File

@ -61,8 +61,11 @@ public class AWSClientErrorRetryHandler implements HttpRetryHandler {
|| response.getStatusCode() == 409) { || response.getStatusCode() == 409) {
byte[] content = HttpUtils.closeClientButKeepContentStream(response); byte[] content = HttpUtils.closeClientButKeepContentStream(response);
command.incrementFailureCount(); command.incrementFailureCount();
// Content can be null in the case of HEAD requests
if (content != null) {
try { try {
AWSError error = utils.parseAWSErrorFromContent(command, response, new String(content)); AWSError error = utils.parseAWSErrorFromContent(command, response, new String(
content));
if ("RequestTimeout".equals(error.getCode()) if ("RequestTimeout".equals(error.getCode())
|| "OperationAborted".equals(error.getCode()) || "OperationAborted".equals(error.getCode())
|| "SignatureDoesNotMatch".equals(error.getCode())) { || "SignatureDoesNotMatch".equals(error.getCode())) {
@ -72,6 +75,7 @@ public class AWSClientErrorRetryHandler implements HttpRetryHandler {
logger.warn(e, "error parsing response: %s", new String(content)); logger.warn(e, "error parsing response: %s", new String(content));
} }
} }
}
return false; return false;
} }

View File

@ -72,6 +72,8 @@ public class AzureBlobClientErrorRetryHandler implements HttpRetryHandler {
retryCountLimit, command); retryCountLimit, command);
return false; return false;
} else if (response.getStatusCode() == 409) { } else if (response.getStatusCode() == 409) {
// Content can be null in the case of HEAD requests
if (content != null) {
try { try {
AzureStorageError error = utils.parseAzureStorageErrorFromContent(command, response, AzureStorageError error = utils.parseAzureStorageErrorFromContent(command, response,
new ByteArrayInputStream(content)); new ByteArrayInputStream(content));
@ -84,6 +86,7 @@ public class AzureBlobClientErrorRetryHandler implements HttpRetryHandler {
logger.warn(e, "error parsing response: %s", new String(content)); logger.warn(e, "error parsing response: %s", new String(content));
} }
} }
}
return false; return false;
} }

View File

@ -46,40 +46,40 @@ public class HttpRequest extends HttpMessage {
/** /**
* *
* @param endPoint * @param endpoint
* This may change over the life of the request due to redirects. * This may change over the life of the request due to redirects.
* @param method * @param method
* If the request is HEAD, this may change to GET due to redirects * If the request is HEAD, this may change to GET due to redirects
*/ */
public HttpRequest(String method, URI endPoint) { public HttpRequest(String method, URI endpoint) {
this.setMethod(checkNotNull(method, "method")); this.setMethod(checkNotNull(method, "method"));
this.setEndpoint(checkNotNull(endPoint, "endPoint")); this.setEndpoint(checkNotNull(endpoint, "endpoint"));
checkArgument(endPoint.getHost() != null, String.format("endPoint.getHost() is null for %s", checkArgument(endpoint.getHost() != null, String.format("endpoint.getHost() is null for %s",
endPoint)); endpoint));
} }
/** /**
* *
* @param endPoint * @param endpoint
* This may change over the life of the request due to redirects. * This may change over the life of the request due to redirects.
* @param method * @param method
* If the request is HEAD, this may change to GET due to redirects * If the request is HEAD, this may change to GET due to redirects
*/ */
public HttpRequest(String method, URI endPoint, Multimap<String, String> headers) { public HttpRequest(String method, URI endpoint, Multimap<String, String> headers) {
this(method, endPoint); this(method, endpoint);
getHeaders().putAll(checkNotNull(headers, "headers")); getHeaders().putAll(checkNotNull(headers, "headers"));
} }
/** /**
* *
* @param endPoint * @param endpoint
* This may change over the life of the request due to redirects. * This may change over the life of the request due to redirects.
* @param method * @param method
* If the request is HEAD, this may change to GET due to redirects * If the request is HEAD, this may change to GET due to redirects
*/ */
protected HttpRequest(String method, URI endPoint, Multimap<String, String> headers, protected HttpRequest(String method, URI endpoint, Multimap<String, String> headers,
@Nullable Payload payload) { @Nullable Payload payload) {
this(method, endPoint); this(method, endpoint);
getHeaders().putAll(checkNotNull(headers, "headers")); getHeaders().putAll(checkNotNull(headers, "headers"));
setPayload(payload); setPayload(payload);
} }

View File

@ -40,9 +40,9 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
private final Object[] args; private final Object[] args;
private final RestAnnotationProcessor<T> processor; private final RestAnnotationProcessor<T> processor;
GeneratedHttpRequest(String method, URI endPoint, RestAnnotationProcessor<T> processor, GeneratedHttpRequest(String method, URI endpoint, RestAnnotationProcessor<T> processor,
Class<T> declaring, Method javaMethod, Object... args) { Class<T> declaring, Method javaMethod, Object... args) {
super(method, endPoint); super(method, endpoint);
this.processor = processor; this.processor = processor;
this.declaring = declaring; this.declaring = declaring;
this.javaMethod = javaMethod; this.javaMethod = javaMethod;

View File

@ -61,12 +61,12 @@ import org.jclouds.http.HttpRequest;
import org.jclouds.http.HttpRequestFilter; import org.jclouds.http.HttpRequestFilter;
import org.jclouds.http.HttpResponse; import org.jclouds.http.HttpResponse;
import org.jclouds.http.HttpUtils; import org.jclouds.http.HttpUtils;
import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax; import org.jclouds.http.functions.ParseSax;
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x; import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
import org.jclouds.http.functions.ReturnInputStream; import org.jclouds.http.functions.ReturnInputStream;
import org.jclouds.http.functions.ReturnStringIf200; import org.jclouds.http.functions.ReturnStringIf200;
import org.jclouds.http.functions.ReturnTrueIf2xx; import org.jclouds.http.functions.ReturnTrueIf2xx;
import org.jclouds.http.functions.CloseContentAndReturn;
import org.jclouds.http.functions.ParseSax.HandlerWithResult; import org.jclouds.http.functions.ParseSax.HandlerWithResult;
import org.jclouds.http.options.HttpRequestOptions; import org.jclouds.http.options.HttpRequestOptions;
import org.jclouds.logging.Logger; import org.jclouds.logging.Logger;
@ -360,16 +360,15 @@ public class RestAnnotationProcessor<T> {
builder.replaceQuery(makeQueryLine(queryParams, null, skips)); builder.replaceQuery(makeQueryLine(queryParams, null, skips));
} }
URI endPoint;
try { try {
endPoint = builder.buildFromEncodedMap(convertUnsafe(tokenValues)); endpoint = builder.buildFromEncodedMap(convertUnsafe(tokenValues));
} catch (IllegalArgumentException e) { } catch (IllegalArgumentException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} catch (UriBuilderException e) { } catch (UriBuilderException e) {
throw new IllegalStateException(e); throw new IllegalStateException(e);
} }
GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(httpMethod, endPoint, this, GeneratedHttpRequest<T> request = new GeneratedHttpRequest<T>(httpMethod, endpoint, this,
declaring, method, args); declaring, method, args);
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method); addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
addFiltersIfAnnotated(method, request); addFiltersIfAnnotated(method, request);