mirror of https://github.com/apache/jclouds.git
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:
parent
01ad08dfc2
commit
2b3d2b0c48
|
@ -64,6 +64,8 @@ public class AtmosStorageClientErrorRetryHandler implements HttpRetryHandler {
|
|||
return true;
|
||||
} else if (response.getStatusCode() == 409 || response.getStatusCode() == 400) {
|
||||
byte[] content = HttpUtils.closeClientButKeepContentStream(response);
|
||||
// Content can be null in the case of HEAD requests
|
||||
if (content != null) {
|
||||
try {
|
||||
AtmosStorageError error = utils.parseAtmosStorageErrorFromContent(command, response,
|
||||
new String(content));
|
||||
|
@ -75,6 +77,9 @@ public class AtmosStorageClientErrorRetryHandler implements HttpRetryHandler {
|
|||
} catch (HttpException e) {
|
||||
logger.warn(e, "error parsing response: %s", new String(content));
|
||||
}
|
||||
} else {
|
||||
command.incrementFailureCount();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
|
|
|
@ -61,8 +61,11 @@ public class AWSClientErrorRetryHandler implements HttpRetryHandler {
|
|||
|| response.getStatusCode() == 409) {
|
||||
byte[] content = HttpUtils.closeClientButKeepContentStream(response);
|
||||
command.incrementFailureCount();
|
||||
// Content can be null in the case of HEAD requests
|
||||
if (content != null) {
|
||||
try {
|
||||
AWSError error = utils.parseAWSErrorFromContent(command, response, new String(content));
|
||||
AWSError error = utils.parseAWSErrorFromContent(command, response, new String(
|
||||
content));
|
||||
if ("RequestTimeout".equals(error.getCode())
|
||||
|| "OperationAborted".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));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -72,6 +72,8 @@ public class AzureBlobClientErrorRetryHandler implements HttpRetryHandler {
|
|||
retryCountLimit, command);
|
||||
return false;
|
||||
} else if (response.getStatusCode() == 409) {
|
||||
// Content can be null in the case of HEAD requests
|
||||
if (content != null) {
|
||||
try {
|
||||
AzureStorageError error = utils.parseAzureStorageErrorFromContent(command, response,
|
||||
new ByteArrayInputStream(content));
|
||||
|
@ -84,6 +86,7 @@ public class AzureBlobClientErrorRetryHandler implements HttpRetryHandler {
|
|||
logger.warn(e, "error parsing response: %s", new String(content));
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
|
|
@ -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.
|
||||
* @param method
|
||||
* 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.setEndpoint(checkNotNull(endPoint, "endPoint"));
|
||||
checkArgument(endPoint.getHost() != null, String.format("endPoint.getHost() is null for %s",
|
||||
endPoint));
|
||||
this.setEndpoint(checkNotNull(endpoint, "endpoint"));
|
||||
checkArgument(endpoint.getHost() != null, String.format("endpoint.getHost() is null for %s",
|
||||
endpoint));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param endPoint
|
||||
* @param endpoint
|
||||
* This may change over the life of the request due to redirects.
|
||||
* @param method
|
||||
* If the request is HEAD, this may change to GET due to redirects
|
||||
*/
|
||||
public HttpRequest(String method, URI endPoint, Multimap<String, String> headers) {
|
||||
this(method, endPoint);
|
||||
public HttpRequest(String method, URI endpoint, Multimap<String, String> headers) {
|
||||
this(method, endpoint);
|
||||
getHeaders().putAll(checkNotNull(headers, "headers"));
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* @param endPoint
|
||||
* @param endpoint
|
||||
* This may change over the life of the request due to redirects.
|
||||
* @param method
|
||||
* 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) {
|
||||
this(method, endPoint);
|
||||
this(method, endpoint);
|
||||
getHeaders().putAll(checkNotNull(headers, "headers"));
|
||||
setPayload(payload);
|
||||
}
|
||||
|
|
|
@ -40,9 +40,9 @@ public class GeneratedHttpRequest<T> extends HttpRequest {
|
|||
private final Object[] args;
|
||||
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) {
|
||||
super(method, endPoint);
|
||||
super(method, endpoint);
|
||||
this.processor = processor;
|
||||
this.declaring = declaring;
|
||||
this.javaMethod = javaMethod;
|
||||
|
|
|
@ -61,12 +61,12 @@ import org.jclouds.http.HttpRequest;
|
|||
import org.jclouds.http.HttpRequestFilter;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.http.HttpUtils;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax;
|
||||
import org.jclouds.http.functions.ParseURIFromListOrLocationHeaderIf20x;
|
||||
import org.jclouds.http.functions.ReturnInputStream;
|
||||
import org.jclouds.http.functions.ReturnStringIf200;
|
||||
import org.jclouds.http.functions.ReturnTrueIf2xx;
|
||||
import org.jclouds.http.functions.CloseContentAndReturn;
|
||||
import org.jclouds.http.functions.ParseSax.HandlerWithResult;
|
||||
import org.jclouds.http.options.HttpRequestOptions;
|
||||
import org.jclouds.logging.Logger;
|
||||
|
@ -360,16 +360,15 @@ public class RestAnnotationProcessor<T> {
|
|||
builder.replaceQuery(makeQueryLine(queryParams, null, skips));
|
||||
}
|
||||
|
||||
URI endPoint;
|
||||
try {
|
||||
endPoint = builder.buildFromEncodedMap(convertUnsafe(tokenValues));
|
||||
endpoint = builder.buildFromEncodedMap(convertUnsafe(tokenValues));
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new IllegalStateException(e);
|
||||
} catch (UriBuilderException 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);
|
||||
addHostHeaderIfAnnotatedWithVirtualHost(headers, request.getEndpoint().getHost(), method);
|
||||
addFiltersIfAnnotated(method, request);
|
||||
|
|
Loading…
Reference in New Issue