Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Fixed all bugs related to switch to httpcomponents

  • Loading branch information...
commit 0f72cdad3d7f43583b526d748343427b35f18282 1 parent 04cbcc4
greese authored
1  .gitignore
View
@@ -7,3 +7,4 @@
*.idea
*.iml
+target
13 pom.xml
View
@@ -69,7 +69,7 @@
<dependency>
<groupId>org.dasein</groupId>
<artifactId>dasein-cloud-test</artifactId>
- <version>2012.04</version>
+ <version>2012.07-SNAPSHOT</version>
<scope>test</scope>
<optional>false</optional>
</dependency>
@@ -83,8 +83,15 @@
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
- <version>4.1.3</version>
+ <version>4.2</version>
</dependency>
+ <!--
+ <dependency>
+ <groupId>org.apache.httpcomponents</groupId>
+ <artifactId>httpmime</artifactId>
+ <version>4.2</version>
+ </dependency>
+ -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
@@ -250,7 +257,7 @@
</systemProperties>
<includes>
- <!-- <include>**/AWSTestSuite.java</include> -->
+ <include>**/AWSTestSuite.java</include>
</includes>
</configuration>
</plugin>
38 src/main/java/org/dasein/cloud/aws/compute/EC2Method.java
View
@@ -23,6 +23,9 @@
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
@@ -37,10 +40,13 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
+import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
@@ -395,9 +401,6 @@ public Document invoke() throws EC2Exception, CloudException, InternalException
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
- HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
Properties p = ctx.getCustomProperties();
@@ -421,6 +424,10 @@ public Document invoke(boolean debug) throws EC2Exception, CloudException, Inter
if( logger.isTraceEnabled() ) {
logger.trace("ENTER - " + EC2Method.class.getName() + ".invoke(" + debug + ")");
}
+ if( wire.isDebugEnabled() ) {
+ wire.debug("");
+ wire.debug("--------------------------------------------------------------------------------------");
+ }
try {
if( logger.isDebugEnabled() ) {
logger.debug("Talking to server at " + url);
@@ -432,20 +439,34 @@ public Document invoke(boolean debug) throws EC2Exception, CloudException, Inter
attempts++;
post.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8");
+
+ List<NameValuePair> params = new ArrayList<NameValuePair>();
+
for( Map.Entry<String, String> entry : parameters.entrySet() ) {
- post.getParams().setParameter(entry.getKey(), entry.getValue());
- //post.addParameter(entry.getKey(), entry.getValue());
+ params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
+ }
+ try {
+ post.setEntity(new UrlEncodedFormEntity(params));
+ }
+ catch( UnsupportedEncodingException e ) {
+ throw new InternalException(e);
}
if( wire.isDebugEnabled() ) {
wire.debug(post.getRequestLine().toString());
for( Header header : post.getAllHeaders() ) {
wire.debug(header.getName() + ": " + header.getValue());
}
+ wire.debug("");
+
+ try { wire.debug(EntityUtils.toString(post.getEntity())); }
+ catch( IOException ignore ) { }
+
+ wire.debug("");
}
try {
response = client.execute(post);
if( wire.isDebugEnabled() ) {
- wire.debug("HTTP STATUS: " + response.getStatusLine().getStatusCode());
+ wire.debug(response.getStatusLine().toString());
}
}
catch( IOException e ) {
@@ -659,6 +680,11 @@ else if( attr.getNodeName().equals("Message") ) {
if( logger.isTraceEnabled() ) {
logger.trace("EXIT - " + EC2Method.class.getName() + ".invoke()");
}
+ if( wire.isDebugEnabled() ) {
+ wire.debug("--------------------------------------------------------------------------------------");
+ wire.debug("");
+ }
+
}
}
17 src/main/java/org/dasein/cloud/aws/storage/S3.java
View
@@ -32,6 +32,7 @@
import java.security.NoSuchAlgorithmException;
import java.text.ParseException;
import java.text.SimpleDateFormat;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Date;
import java.util.HashMap;
@@ -43,6 +44,7 @@
import org.apache.log4j.Logger;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
+import org.dasein.cloud.ProviderContext;
import org.dasein.cloud.aws.AWSCloud;
import org.dasein.cloud.aws.storage.S3Method.S3Response;
import org.dasein.cloud.encryption.Encryption;
@@ -63,7 +65,7 @@
import javax.servlet.http.HttpServletResponse;
public class S3 implements BlobStoreSupport {
- static private final Logger logger = Logger.getLogger(S3.class);
+ static private final Logger logger = AWSCloud.getLogger(S3.class);
private AWSCloud provider = null;
@@ -176,7 +178,16 @@ private CloudStoreObject copyFile(CloudStoreObject file, CloudStoreObject toDire
}
public String createDirectory(String bucket, boolean findFreeName) throws InternalException, CloudException {
- String regionId = provider.getContext().getRegionId();
+ ProviderContext ctx = provider.getContext();
+
+ if( ctx == null ) {
+ throw new InternalException("No context was set for this request");
+ }
+ String regionId = ctx.getRegionId();
+
+ if( regionId == null ) {
+ throw new InternalException("No region ID was specified for this request");
+ }
StringBuilder body = null;
boolean success;
int idx;
@@ -1451,7 +1462,7 @@ private void setAcl(String bucket, String object, String body) throws CloudExcep
String ct = "text/xml; charset=utf-8";
S3Method method;
- method = new S3Method(provider, S3Action.SET_ACL, null, null, ct, body);
+ method = new S3Method(provider, S3Action.SET_ACL, null, null, null /* ct */, body);
try {
method.invoke(bucket, object == null ? "?acl" : object + "?acl");
}
4 src/main/java/org/dasein/cloud/aws/storage/S3Action.java
View
@@ -21,7 +21,7 @@
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead;
-import org.apache.http.client.methods.HttpPost;
+import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
public enum S3Action {
@@ -36,7 +36,7 @@ public HttpRequestBase getMethod(String url) {
case LIST_BUCKETS: case LIST_CONTENTS: case LOCATE_BUCKET: case GET_OBJECT: case GET_ACL:
return new HttpGet(url);
case CREATE_BUCKET: case COPY_OBJECT: case PUT_OBJECT: case SET_ACL:
- return new HttpPost(url);
+ return new HttpPut(url);
}
return null;
}
583 src/main/java/org/dasein/cloud/aws/storage/S3Method.java
View
@@ -31,8 +31,10 @@
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.text.SimpleDateFormat;
+import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.regex.Pattern;
@@ -49,7 +51,9 @@
import org.apache.http.HttpHost;
import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion;
+import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient;
+import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
@@ -57,10 +61,12 @@
import org.apache.http.entity.FileEntity;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.DefaultHttpClient;
+import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams;
import org.apache.http.protocol.HTTP;
+import org.apache.http.util.EntityUtils;
import org.apache.log4j.Logger;
import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException;
@@ -209,7 +215,7 @@ S3Response invoke(String bucket, String object) throws S3Exception, CloudExcepti
return invoke(bucket, object, null);
}
- protected @Nonnull HttpClient getClient(String url) throws InternalException {
+ protected @Nonnull HttpClient getClient(String url, boolean multipart) throws InternalException {
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
@@ -219,10 +225,9 @@ S3Response invoke(String bucket, String object) throws S3Exception, CloudExcepti
HttpParams params = new BasicHttpParams();
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
- HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
- HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
- HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
+ if( !multipart ) {
+ HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
+ }
HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
Properties p = ctx.getCustomProperties();
@@ -243,311 +248,354 @@ S3Response invoke(String bucket, String object) throws S3Exception, CloudExcepti
return new DefaultHttpClient(params);
}
- S3Response invoke(String bucket, String object, String temporaryEndpoint) throws S3Exception, CloudException, InternalException {
- StringBuilder url = new StringBuilder();
- boolean leaveOpen = false;
- HttpRequestBase method;
- HttpClient client;
- int status;
+ static private final Logger wire = AWSCloud.getWireLogger(S3.class);
- if( provider.isAmazon() ) {
- url.append("https://");
- if( temporaryEndpoint == null ) {
- boolean validDomainName = isValidDomainName(bucket);
- if( bucket != null && validDomainName ) {
- url.append(bucket);
- url.append(".");
- }
- url.append("s3.amazonaws.com/");
- if ( bucket != null && !validDomainName) {
- url.append(bucket);
+ S3Response invoke(String bucket, String object, String temporaryEndpoint) throws S3Exception, CloudException, InternalException {
+ if( wire.isDebugEnabled() ) {
+ wire.debug("");
+ wire.debug("----------------------------------------------------------------------------------");
+ }
+ try {
+ StringBuilder url = new StringBuilder();
+ boolean leaveOpen = false;
+ HttpRequestBase method;
+ HttpClient client;
+ int status;
+
+ if( provider.isAmazon() ) {
+ url.append("https://");
+ if( temporaryEndpoint == null ) {
+ boolean validDomainName = isValidDomainName(bucket);
+ if( bucket != null && validDomainName ) {
+ url.append(bucket);
+ url.append(".");
+ }
+ url.append("s3.amazonaws.com/");
+ if ( bucket != null && !validDomainName) {
+ url.append(bucket);
+ url.append("/");
+ }
+ }
+ else {
+ url.append(temporaryEndpoint);
url.append("/");
- }
- }
- else {
- url.append(temporaryEndpoint);
- url.append("/");
- }
- }
- else {
- int idx = 0;
-
- if( !provider.getContext().getEndpoint().startsWith("http") ) {
- url.append("https://");
- }
- else {
- idx = provider.getContext().getEndpoint().indexOf("https://");
- if( idx == -1 ) {
- idx = "http://".length();
- url.append("http://");
- }
- else {
- idx = "https://".length();
+ }
+ }
+ else {
+ int idx = 0;
+
+ if( !provider.getContext().getEndpoint().startsWith("http") ) {
url.append("https://");
- }
- }
- if( temporaryEndpoint == null ) {
- url.append(provider.getContext().getEndpoint().substring(idx));
- if( !provider.getContext().getEndpoint().endsWith("/") ) {
- url.append("/Walrus/");
- }
- else {
- url.append("Walrus/");
- }
- }
- else {
- url.append(temporaryEndpoint);
- url.append("/Walrus/");
- }
- if( bucket != null ) {
- url.append(bucket);
- url.append("/");
+ }
+ else {
+ idx = provider.getContext().getEndpoint().indexOf("https://");
+ if( idx == -1 ) {
+ idx = "http://".length();
+ url.append("http://");
+ }
+ else {
+ idx = "https://".length();
+ url.append("https://");
+ }
+ }
+ if( temporaryEndpoint == null ) {
+ url.append(provider.getContext().getEndpoint().substring(idx));
+ if( !provider.getContext().getEndpoint().endsWith("/") ) {
+ url.append("/Walrus/");
+ }
+ else {
+ url.append("Walrus/");
+ }
+ }
+ else {
+ url.append(temporaryEndpoint);
+ url.append("/Walrus/");
+ }
+ if( bucket != null ) {
+ url.append(bucket);
+ url.append("/");
+ }
}
- }
- if( object != null ) {
- url.append(object);
- }
- if( parameters != null ) {
- boolean first = true;
-
- if( object != null && object.indexOf('?') != -1 ) {
- first = false;
- }
- for( Map.Entry<String,String> entry : parameters.entrySet() ) {
- String key = entry.getKey();
- String val = entry.getValue();
+ if( object != null ) {
+ url.append(object);
+ }
+ else if( parameters != null ) {
+ boolean first = true;
- if( first ) {
- url.append("?");
- first = false;
- }
- else {
- url.append("&");
- }
- if( val != null ) {
- url.append(AWSCloud.encode(key, false));
- url.append("=");
- url.append(AWSCloud.encode(val, false));
- }
- else {
- url.append(AWSCloud.encode(key, false));
- }
- }
- }
- headers.put(AWSCloud.P_DATE, getDate());
- method = action.getMethod(url.toString());
- if( headers != null ) {
- for( Map.Entry<String, String> entry : headers.entrySet() ) {
- method.addHeader(entry.getKey(), entry.getValue());
- }
- }
- try {
- String hash = null;
- String signature;
-
- signature = provider.signS3(new String(provider.getContext().getAccessPublic(), "utf-8"), provider.getContext().getAccessPrivate(), method.getMethod(), hash, contentType, headers, bucket, object);
- method.addHeader(AWSCloud.P_CFAUTH, signature);
- }
- catch (UnsupportedEncodingException e) {
- logger.error(e);
- e.printStackTrace();
- throw new InternalException(e);
- }
- if( body != null ) {
- try {
- ((HttpEntityEnclosingRequestBase)method).setEntity(new StringEntity(body, "application/xml", "utf-8"));
+ if( object != null && object.indexOf('?') != -1 ) {
+ first = false;
+ }
+ for( Map.Entry<String,String> entry : parameters.entrySet() ) {
+ String key = entry.getKey();
+ String val = entry.getValue();
+
+ if( first ) {
+ url.append("?");
+ first = false;
+ }
+ else {
+ url.append("&");
+ }
+ if( val != null ) {
+ url.append(AWSCloud.encode(key, false));
+ url.append("=");
+ url.append(AWSCloud.encode(val, false));
+ }
+ else {
+ url.append(AWSCloud.encode(key, false));
+ }
+ }
+ }
+
+ headers.put(AWSCloud.P_DATE, getDate());
+ method = action.getMethod(url.toString());
+ if( headers != null ) {
+ for( Map.Entry<String, String> entry : headers.entrySet() ) {
+ method.addHeader(entry.getKey(), entry.getValue());
+ }
+ }
+ if( contentType == null && body != null ) {
+ contentType = "application/xml";
+ method.addHeader("Content-Type", contentType);
}
- catch( UnsupportedEncodingException e ) {
+ try {
+ String hash = null;
+ String signature;
+
+ signature = provider.signS3(new String(provider.getContext().getAccessPublic(), "utf-8"), provider.getContext().getAccessPrivate(), method.getMethod(), hash, contentType, headers, bucket, object);
+ method.addHeader(AWSCloud.P_CFAUTH, signature);
+ }
+ catch (UnsupportedEncodingException e) {
+ logger.error(e);
+ e.printStackTrace();
throw new InternalException(e);
}
- }
- else if( uploadFile != null ) {
- ((HttpEntityEnclosingRequestBase)method).setEntity(new FileEntity(uploadFile, contentType));
- }
- attempts++;
- client = getClient(url.toString());
- S3Response response = new S3Response();
- HttpResponse httpResponse;
-
- try {
- httpResponse = client.execute(method);
- status = httpResponse.getStatusLine().getStatusCode();
- }
- catch( IOException e ) {
- logger.error(url + ": " + e.getMessage());
- e.printStackTrace();
- throw new InternalException(e);
- }
- response.headers = method.getAllHeaders();
-
- HttpEntity entity = httpResponse.getEntity();
+ if( body != null ) {
+ try {
+ ((HttpEntityEnclosingRequestBase)method).setEntity(new StringEntity(body, "application/xml", "utf-8"));
+ }
+ catch( UnsupportedEncodingException e ) {
+ throw new InternalException(e);
+ }
+ }
+ else if( uploadFile != null ) {
+ ((HttpEntityEnclosingRequestBase)method).setEntity(new FileEntity(uploadFile, contentType));
+ }
+ attempts++;
+ client = getClient(url.toString(), body == null && uploadFile == null);
+
+ if( wire.isDebugEnabled() ) {
+ wire.debug("[" + url.toString() + "]");
+ wire.debug(method.getRequestLine().toString());
+ for( Header header : method.getAllHeaders() ) {
+ wire.debug(header.getName() + ": " + header.getValue());
+ }
+ wire.debug("");
+ if( body != null ) {
+ try { wire.debug(EntityUtils.toString(((HttpEntityEnclosingRequestBase)method).getEntity())); }
+ catch( IOException ignore ) { }
- if( entity == null ) {
- throw new S3Exception(status, null, "NoResponse", "No response body was specified");
- }
- InputStream input;
-
- try {
- input = entity.getContent();
- }
- catch( IOException e ) {
- throw new CloudException(e);
- }
- try {
- if( status == HttpServletResponse.SC_OK || status == HttpServletResponse.SC_CREATED || status == HttpServletResponse.SC_ACCEPTED ) {
- Header[] clen = httpResponse.getHeaders("Content-Length");
- long len = -1L;
-
- if( clen != null && clen.length > 0 ) {
- len = Long.parseLong(clen[0].getValue());
+ wire.debug("");
}
- if( len != 0L ) {
- try {
- Header[] ct = httpResponse.getHeaders("Content-Type");
+ else if( uploadFile != null ) {
+ wire.debug("-- file upload --");
+ wire.debug("");
+ }
+ }
+ S3Response response = new S3Response();
+ HttpResponse httpResponse;
+
+ try {
+ httpResponse = client.execute(method);
+ if( wire.isDebugEnabled() ) {
+ wire.debug(httpResponse.getStatusLine().toString());
+ for( Header header : httpResponse.getAllHeaders() ) {
+ wire.debug(header.getName() + ": " + header.getValue());
+ }
+ wire.debug("");
+ }
+ status = httpResponse.getStatusLine().getStatusCode();
+ }
+ catch( IOException e ) {
+ logger.error(url + ": " + e.getMessage());
+ e.printStackTrace();
+ throw new InternalException(e);
+ }
+ response.headers = httpResponse.getAllHeaders();
+
+ HttpEntity entity = httpResponse.getEntity();
+ InputStream input = null;
- if( ct != null && ct.length > 0 && (ct[0].getValue().startsWith("application/xml") || ct[0].getValue().startsWith("text/xml")) ) {
- try {
- response.document = parseResponse(input);
- return response;
+ if( entity != null ) {
+ try {
+ input = entity.getContent();
+ }
+ catch( IOException e ) {
+ throw new CloudException(e);
+ }
+ }
+ try {
+ if( status == HttpServletResponse.SC_OK || status == HttpServletResponse.SC_CREATED || status == HttpServletResponse.SC_ACCEPTED ) {
+ Header clen = httpResponse.getFirstHeader("Content-Length");
+ long len = -1L;
+
+ if( clen != null ) {
+ len = Long.parseLong(clen.getValue());
+ }
+ if( len != 0L ) {
+ try {
+ Header ct = httpResponse.getFirstHeader("Content-Type");
+
+ if( ct != null && (ct.getValue().startsWith("application/xml") || ct.getValue().startsWith("text/xml")) ) {
+ try {
+ response.document = parseResponse(input);
+ return response;
+ }
+ finally {
+ input.close();
+ }
}
- finally {
- input.close();
+ else if( ct != null && ct.getValue().startsWith("application/octet-stream") && len < 1 ) {
+ return null;
}
- }
- else if( ct != null && ct.length > 0 && ct[0].getValue().startsWith("application/octet-stream") && len < 1 ) {
- return null;
- }
- else {
- response.contentLength = len;
- if( ct != null && ct.length > 0 ) {
- response.contentType = ct[0].getValue();
+ else {
+ response.contentLength = len;
+ if( ct != null ) {
+ response.contentType = ct.getValue();
+ }
+ response.input = input;
+ response.method = method;
+ leaveOpen = true;
+ return response;
}
- response.input = input;
- response.method = method;
- leaveOpen = true;
- return response;
+ }
+ catch( IOException e ) {
+ logger.error(e);
+ e.printStackTrace();
+ throw new CloudException(e);
}
}
- catch( IOException e ) {
- logger.error(e);
- e.printStackTrace();
- throw new CloudException(e);
+ else {
+ return response;
}
}
- else {
+ else if( status == HttpServletResponse.SC_NO_CONTENT ) {
return response;
}
- }
- else if( status == HttpServletResponse.SC_NO_CONTENT ) {
- return response;
- }
- else if( status == HttpServletResponse.SC_NOT_FOUND ) {
- throw new S3Exception(status, null, null, "Object not found.");
- }
- else {
- if( status == HttpServletResponse.SC_SERVICE_UNAVAILABLE || status == HttpServletResponse.SC_INTERNAL_SERVER_ERROR ) {
- if( attempts >= 5 ) {
- String msg;
-
- if( status == HttpServletResponse.SC_SERVICE_UNAVAILABLE ) {
- msg = "Cloud service is currently unavailable.";
+ else if( status == HttpServletResponse.SC_NOT_FOUND ) {
+ throw new S3Exception(status, null, null, "Object not found.");
+ }
+ else {
+ if( status == HttpServletResponse.SC_SERVICE_UNAVAILABLE || status == HttpServletResponse.SC_INTERNAL_SERVER_ERROR ) {
+ if( attempts >= 5 ) {
+ String msg;
+
+ if( status == HttpServletResponse.SC_SERVICE_UNAVAILABLE ) {
+ msg = "Cloud service is currently unavailable.";
+ }
+ else {
+ msg = "The cloud service encountered a server error while processing your request.";
+ }
+ logger.error(msg);
+ throw new CloudException(msg);
}
else {
- msg = "The cloud service encountered a server error while processing your request.";
- }
- logger.error(msg);
- throw new CloudException(msg);
- }
- else {
- leaveOpen = true;
- if( input != null ) {
- try { input.close(); }
- catch( IOException ignore ) { }
+ leaveOpen = true;
+ if( input != null ) {
+ try { input.close(); }
+ catch( IOException ignore ) { }
+ }
+ try { Thread.sleep(5000L); }
+ catch( InterruptedException ignore ) { }
+ return invoke(bucket, object);
}
- try { Thread.sleep(5000L); }
- catch( InterruptedException ignore ) { }
- return invoke(bucket, object);
}
- }
- try {
- Document doc;
-
try {
- logger.warn("Received error code: " + status);
- doc = parseResponse(input);
- }
- finally {
- input.close();
- }
- if( doc != null ) {
- String endpoint = null, code = null, message = null, requestId = null;
- NodeList blocks = doc.getElementsByTagName("Error");
-
- if( blocks.getLength() > 0 ) {
- Node error = blocks.item(0);
- NodeList attrs;
-
- attrs = error.getChildNodes();
- for( int i=0; i<attrs.getLength(); i++ ) {
- Node attr = attrs.item(i);
+ Document doc;
+
+ try {
+ logger.warn("Received error code: " + status);
+ doc = parseResponse(input);
+ }
+ finally {
+ input.close();
+ }
+ if( doc != null ) {
+ String endpoint = null, code = null, message = null, requestId = null;
+ NodeList blocks = doc.getElementsByTagName("Error");
+
+ if( blocks.getLength() > 0 ) {
+ Node error = blocks.item(0);
+ NodeList attrs;
- if( attr.getNodeName().equals("Code") ) {
- code = attr.getFirstChild().getNodeValue().trim();
- }
- else if( attr.getNodeName().equals("Message") ) {
- message = attr.getFirstChild().getNodeValue().trim();
+ attrs = error.getChildNodes();
+ for( int i=0; i<attrs.getLength(); i++ ) {
+ Node attr = attrs.item(i);
+
+ if( attr.getNodeName().equals("Code") ) {
+ code = attr.getFirstChild().getNodeValue().trim();
+ }
+ else if( attr.getNodeName().equals("Message") ) {
+ message = attr.getFirstChild().getNodeValue().trim();
+ }
+ else if( attr.getNodeName().equals("RequestId") ) {
+ requestId = attr.getFirstChild().getNodeValue().trim();
+ }
+ else if( attr.getNodeName().equals("Endpoint") ) {
+ endpoint = attr.getFirstChild().getNodeValue().trim();
+ }
}
- else if( attr.getNodeName().equals("RequestId") ) {
- requestId = attr.getFirstChild().getNodeValue().trim();
+
+ }
+ if( endpoint != null && code.equals("TemporaryRedirect") ) {
+ if( temporaryEndpoint != null ) {
+ throw new CloudException("Too deep redirect to " + endpoint);
}
- else if( attr.getNodeName().equals("Endpoint") ) {
- endpoint = attr.getFirstChild().getNodeValue().trim();
+ else {
+ return invoke(bucket, object, endpoint);
}
}
-
- }
- if( endpoint != null && code.equals("TemporaryRedirect") ) {
- if( temporaryEndpoint != null ) {
- throw new CloudException("Too deep redirect to " + endpoint);
- }
else {
- return invoke(bucket, object, endpoint);
+ if( message == null ) {
+ throw new CloudException("Unable to identify error condition: " + status + "/" + requestId + "/" + code);
+ }
+ throw new S3Exception(status, requestId, code, message);
}
}
else {
- if( message == null ) {
- throw new CloudException("Unable to identify error condition: " + status + "/" + requestId + "/" + code);
- }
- throw new S3Exception(status, requestId, code, message);
+ throw new CloudException("Unable to parse error.");
}
}
- else {
- throw new CloudException("Unable to parse error.");
+ catch( IOException e ) {
+ if( status == HttpServletResponse.SC_FORBIDDEN ) {
+ throw new S3Exception(status, "", "AccessForbidden", "Access was denied without explanation.");
+ }
+ throw new CloudException(e);
}
+ catch( RuntimeException e ) {
+ throw new CloudException(e);
+ }
+ catch( Error e ) {
+ throw new CloudException(e);
+ }
}
- catch( IOException e ) {
- if( status == HttpServletResponse.SC_FORBIDDEN ) {
- throw new S3Exception(status, "", "AccessForbidden", "Access was denied without explanation.");
- }
- throw new CloudException(e);
- }
- catch( RuntimeException e ) {
- throw new CloudException(e);
+ }
+ finally {
+ if( !leaveOpen ) {
+ if( input != null ) {
+ try { input.close(); }
+ catch( IOException ignore ) { }
+ }
}
- catch( Error e ) {
- throw new CloudException(e);
- }
}
}
finally {
- if( !leaveOpen ) {
- if( input != null ) {
- try { input.close(); }
- catch( IOException ignore ) { }
- }
+ if( wire.isDebugEnabled() ) {
+ wire.debug("----------------------------------------------------------------------------------");
+ wire.debug("");
}
}
- }
+ }
private boolean isValidDomainName(String bucket) {
return (bucket != null && Pattern.matches("^[a-z0-9](-*[a-z0-9]){2,62}$", bucket));
@@ -564,7 +612,8 @@ private Document parseResponse(InputStream responseBodyAsStream) throws CloudExc
}
in.close();
- //System.out.println(sb);
+ wire.debug(sb.toString());
+
ByteArrayInputStream bas = new ByteArrayInputStream(sb.toString().getBytes());
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
Please sign in to comment.
Something went wrong with that request. Please try again.