Permalink
Browse files

Fixed all bugs related to switch to httpcomponents

  • Loading branch information...
1 parent 04cbcc4 commit 0f72cdad3d7f43583b526d748343427b35f18282 @greese committed Jun 24, 2012
View
@@ -7,3 +7,4 @@
*.idea
*.iml
+target
View
13 pom.xml
@@ -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>
@@ -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("");
+ }
+
}
}
@@ -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");
}
@@ -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;
}
Oops, something went wrong.

0 comments on commit 0f72cda

Please sign in to comment.