Skip to content

Commit

Permalink
Fixed all bugs related to switch to httpcomponents
Browse files Browse the repository at this point in the history
  • Loading branch information
greese committed Jun 24, 2012
1 parent 04cbcc4 commit 0f72cda
Show file tree
Hide file tree
Showing 6 changed files with 375 additions and 281 deletions.
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -7,3 +7,4 @@


*.idea *.idea
*.iml *.iml
target
13 changes: 10 additions & 3 deletions pom.xml
Expand Up @@ -69,7 +69,7 @@
<dependency> <dependency>
<groupId>org.dasein</groupId> <groupId>org.dasein</groupId>
<artifactId>dasein-cloud-test</artifactId> <artifactId>dasein-cloud-test</artifactId>
<version>2012.04</version> <version>2012.07-SNAPSHOT</version>
<scope>test</scope> <scope>test</scope>
<optional>false</optional> <optional>false</optional>
</dependency> </dependency>
Expand All @@ -83,8 +83,15 @@
<dependency> <dependency>
<groupId>org.apache.httpcomponents</groupId> <groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId> <artifactId>httpclient</artifactId>
<version>4.1.3</version> <version>4.2</version>
</dependency> </dependency>
<!--
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpmime</artifactId>
<version>4.2</version>
</dependency>
-->
<dependency> <dependency>
<groupId>junit</groupId> <groupId>junit</groupId>
<artifactId>junit</artifactId> <artifactId>junit</artifactId>
Expand Down Expand Up @@ -250,7 +257,7 @@


</systemProperties> </systemProperties>
<includes> <includes>
<!-- <include>**/AWSTestSuite.java</include> --> <include>**/AWSTestSuite.java</include>
</includes> </includes>
</configuration> </configuration>
</plugin> </plugin>
Expand Down
38 changes: 32 additions & 6 deletions src/main/java/org/dasein/cloud/aws/compute/EC2Method.java
Expand Up @@ -23,6 +23,9 @@
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.io.InputStreamReader; import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties; import java.util.Properties;


Expand All @@ -37,10 +40,13 @@
import org.apache.http.HttpHost; import org.apache.http.HttpHost;
import org.apache.http.HttpResponse; import org.apache.http.HttpResponse;
import org.apache.http.HttpVersion; import org.apache.http.HttpVersion;
import org.apache.http.NameValuePair;
import org.apache.http.client.HttpClient; import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost; import org.apache.http.client.methods.HttpPost;
import org.apache.http.conn.params.ConnRoutePNames; import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient; import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;
import org.apache.http.params.BasicHttpParams; import org.apache.http.params.BasicHttpParams;
import org.apache.http.params.HttpParams; import org.apache.http.params.HttpParams;
import org.apache.http.params.HttpProtocolParams; import org.apache.http.params.HttpProtocolParams;
Expand Down Expand Up @@ -392,9 +398,6 @@ public Document invoke() throws EC2Exception, CloudException, InternalException
boolean ssl = url.startsWith("https"); boolean ssl = url.startsWith("https");
HttpParams params = new BasicHttpParams(); 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.setVersion(params, HttpVersion.HTTP_1_1);
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8); HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
HttpProtocolParams.setUserAgent(params, "Dasein Cloud"); HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
Expand All @@ -421,6 +424,10 @@ public Document invoke(boolean debug) throws EC2Exception, CloudException, Inter
if( logger.isTraceEnabled() ) { if( logger.isTraceEnabled() ) {
logger.trace("ENTER - " + EC2Method.class.getName() + ".invoke(" + debug + ")"); logger.trace("ENTER - " + EC2Method.class.getName() + ".invoke(" + debug + ")");
} }
if( wire.isDebugEnabled() ) {
wire.debug("");
wire.debug("--------------------------------------------------------------------------------------");
}
try { try {
if( logger.isDebugEnabled() ) { if( logger.isDebugEnabled() ) {
logger.debug("Talking to server at " + url); logger.debug("Talking to server at " + url);
Expand All @@ -432,20 +439,34 @@ public Document invoke(boolean debug) throws EC2Exception, CloudException, Inter


attempts++; attempts++;
post.addHeader("Content-Type", "application/x-www-form-urlencoded; charset=utf-8"); 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() ) { for( Map.Entry<String, String> entry : parameters.entrySet() ) {
post.getParams().setParameter(entry.getKey(), entry.getValue()); params.add(new BasicNameValuePair(entry.getKey(), entry.getValue()));
//post.addParameter(entry.getKey(), entry.getValue()); }
try {
post.setEntity(new UrlEncodedFormEntity(params));
}
catch( UnsupportedEncodingException e ) {
throw new InternalException(e);
} }
if( wire.isDebugEnabled() ) { if( wire.isDebugEnabled() ) {
wire.debug(post.getRequestLine().toString()); wire.debug(post.getRequestLine().toString());
for( Header header : post.getAllHeaders() ) { for( Header header : post.getAllHeaders() ) {
wire.debug(header.getName() + ": " + header.getValue()); wire.debug(header.getName() + ": " + header.getValue());
} }
wire.debug("");

try { wire.debug(EntityUtils.toString(post.getEntity())); }
catch( IOException ignore ) { }

wire.debug("");
} }
try { try {
response = client.execute(post); response = client.execute(post);
if( wire.isDebugEnabled() ) { if( wire.isDebugEnabled() ) {
wire.debug("HTTP STATUS: " + response.getStatusLine().getStatusCode()); wire.debug(response.getStatusLine().toString());
} }
} }
catch( IOException e ) { catch( IOException e ) {
Expand Down Expand Up @@ -659,6 +680,11 @@ else if( attr.getNodeName().equals("Message") ) {
if( logger.isTraceEnabled() ) { if( logger.isTraceEnabled() ) {
logger.trace("EXIT - " + EC2Method.class.getName() + ".invoke()"); logger.trace("EXIT - " + EC2Method.class.getName() + ".invoke()");
} }
if( wire.isDebugEnabled() ) {
wire.debug("--------------------------------------------------------------------------------------");
wire.debug("");
}

} }
} }


Expand Down
17 changes: 14 additions & 3 deletions src/main/java/org/dasein/cloud/aws/storage/S3.java
Expand Up @@ -32,6 +32,7 @@
import java.security.NoSuchAlgorithmException; import java.security.NoSuchAlgorithmException;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collection; import java.util.Collection;
import java.util.Date; import java.util.Date;
import java.util.HashMap; import java.util.HashMap;
Expand All @@ -43,6 +44,7 @@
import org.apache.log4j.Logger; import org.apache.log4j.Logger;
import org.dasein.cloud.CloudException; import org.dasein.cloud.CloudException;
import org.dasein.cloud.InternalException; import org.dasein.cloud.InternalException;
import org.dasein.cloud.ProviderContext;
import org.dasein.cloud.aws.AWSCloud; import org.dasein.cloud.aws.AWSCloud;
import org.dasein.cloud.aws.storage.S3Method.S3Response; import org.dasein.cloud.aws.storage.S3Method.S3Response;
import org.dasein.cloud.encryption.Encryption; import org.dasein.cloud.encryption.Encryption;
Expand All @@ -63,7 +65,7 @@
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;


public class S3 implements BlobStoreSupport { 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; private AWSCloud provider = null;


Expand Down Expand Up @@ -176,7 +178,16 @@ private CloudStoreObject copyFile(CloudStoreObject file, CloudStoreObject toDire
} }


public String createDirectory(String bucket, boolean findFreeName) throws InternalException, CloudException { 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; StringBuilder body = null;
boolean success; boolean success;
int idx; int idx;
Expand Down Expand Up @@ -1451,7 +1462,7 @@ private void setAcl(String bucket, String object, String body) throws CloudExcep
String ct = "text/xml; charset=utf-8"; String ct = "text/xml; charset=utf-8";
S3Method method; 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 { try {
method.invoke(bucket, object == null ? "?acl" : object + "?acl"); method.invoke(bucket, object == null ? "?acl" : object + "?acl");
} }
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/dasein/cloud/aws/storage/S3Action.java
Expand Up @@ -21,7 +21,7 @@
import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpHead; 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; import org.apache.http.client.methods.HttpRequestBase;


public enum S3Action { public enum S3Action {
Expand All @@ -36,7 +36,7 @@ public HttpRequestBase getMethod(String url) {
case LIST_BUCKETS: case LIST_CONTENTS: case LOCATE_BUCKET: case GET_OBJECT: case GET_ACL: case LIST_BUCKETS: case LIST_CONTENTS: case LOCATE_BUCKET: case GET_OBJECT: case GET_ACL:
return new HttpGet(url); return new HttpGet(url);
case CREATE_BUCKET: case COPY_OBJECT: case PUT_OBJECT: case SET_ACL: case CREATE_BUCKET: case COPY_OBJECT: case PUT_OBJECT: case SET_ACL:
return new HttpPost(url); return new HttpPut(url);
} }
return null; return null;
} }
Expand Down

0 comments on commit 0f72cda

Please sign in to comment.