Permalink
Browse files

Revert "Half-assed non-sense"

This reverts commit f238cef.
  • Loading branch information...
1 parent f238cef commit 3ad21910022c16ef982c4ab4937b612ae9014be0 @timf committed Mar 1, 2013
View
16 pom.xml
@@ -181,22 +181,10 @@
<configuration>
<systemProperties>
<property>
- <name>providerClass</name>
- <value>${providerClass}</value>
- </property>
- <property>
<name>endpoint</name>
<value>${endpoint}</value>
</property>
<property>
- <name>accessPublic</name>
- <value>${accountNumber}</value>
- </property>
- <property>
- <name>accessPrivate</name>
- <value>${apiSharedKey}</value>
- </property>
- <property>
<name>accountNumber</name>
<value>${accountNumber}</value>
</property>
@@ -222,7 +210,7 @@
</property>
<property>
<name>test.region</name>
- <value>${regionId}</value>
+ <value>${test.region}</value>
</property>
<property>
<name>test.dataCenter</name>
@@ -238,7 +226,7 @@
</property>
</systemProperties>
<includes>
- <include>**/TestSuite.java</include>
+ <include>**/JoyentTestSuite.java</include>
</includes>
</configuration>
</plugin>
@@ -31,7 +31,6 @@
import javax.annotation.Nullable;
import javax.servlet.http.HttpServletResponse;
-import org.apache.commons.codec.binary.Base64;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpHost;
@@ -44,8 +43,6 @@
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
-import org.apache.http.client.params.ClientPNames;
-import org.apache.http.client.params.CookiePolicy;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.InputStreamEntity;
@@ -81,25 +78,11 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
wire.debug(">>> [DELETE (" + (new Date()) + ")] -> " + endpoint + "/my/" + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpDelete delete = new HttpDelete(endpoint + "/my/" + resource);
delete.addHeader("Accept", "application/json");
delete.addHeader("X-Api-Version", "~6.5");
-
- String auth;
-
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
-
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- delete.addHeader("Authorization", "Basic " + auth);
-
if( wire.isDebugEnabled() ) {
wire.debug(delete.getRequestLine().toString());
for( Header header : delete.getAllHeaders() ) {
@@ -185,26 +168,12 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
wire.debug(">>> [GET (" + (new Date()) + ")] -> " + endpoint + "/my/" + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpGet get = new HttpGet(endpoint + "/my/" + resource);
-
-
get.addHeader("Accept", "application/json");
get.addHeader("X-Api-Version", "~6.5");
- String auth;
-
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
-
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- get.addHeader("Authorization", "Basic " + auth);
if( wire.isDebugEnabled() ) {
wire.debug(get.getRequestLine().toString());
for( Header header : get.getAllHeaders() ) {
@@ -308,23 +277,12 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
wire.debug(">>> [GET (" + (new Date()) + ")] -> " + endpoint + "/my/" + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpGet get = new HttpGet(endpoint + "/my/" + resource);
get.addHeader("Accept", "application/json");
get.addHeader("X-Api-Version", "~6.5");
- String auth;
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
-
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- get.addHeader("Authorization", "Basic " + auth);
if( wire.isDebugEnabled() ) {
wire.debug(get.getRequestLine().toString());
for( Header header : get.getAllHeaders() ) {
@@ -418,17 +376,17 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
}
}
- protected @Nonnull HttpClient getClient(@Nonnull String endpoint) throws CloudException, InternalException {
+ protected @Nonnull HttpClient getClient() throws CloudException, InternalException {
ProviderContext ctx = provider.getContext();
if( ctx == null ) {
throw new CloudException("No context was defined for this request");
}
- //String endpoint = ctx.getEndpoint();
+ String endpoint = ctx.getEndpoint();
- //if( endpoint == null ) {
- // throw new CloudException("No cloud endpoint was defined");
- //}
+ if( endpoint == null ) {
+ throw new CloudException("No cloud endpoint was defined");
+ }
boolean ssl = endpoint.startsWith("https");
int targetPort;
URI uri;
@@ -449,7 +407,7 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
//noinspection deprecation
HttpProtocolParams.setContentCharset(params, HTTP.UTF_8);
- HttpProtocolParams.setUserAgent(params, "Dasein Cloud");
+ HttpProtocolParams.setUserAgent(params, "");
Properties p = ctx.getCustomProperties();
@@ -466,20 +424,17 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(proxyHost, port, ssl ? "https" : "http"));
}
}
-
- params.setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
DefaultHttpClient client = new DefaultHttpClient(params);
- /*
+
try {
String userName = new String(ctx.getAccessPublic(), "utf-8");
String password = new String(ctx.getAccessPrivate(), "utf-8");
- client.getCredentialsProvider().setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(userName, password));
+ client.getCredentialsProvider().setCredentials(new AuthScope(targetHost.getHostName(), targetHost.getPort()), new UsernamePasswordCredentials(userName, password));
}
catch( UnsupportedEncodingException e ) {
throw new InternalException(e);
}
- */
return client;
}
@@ -493,7 +448,7 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
wire.debug(">>> [POST (" + (new Date()) + ")] -> " + endpoint + "/my/" + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpPost post = new HttpPost(endpoint + "/my/" + resource);
post.addHeader("Accept", "application/json");
@@ -619,7 +574,7 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
wire.debug(">>> [POST (" + (new Date()) + ")] -> " + endpoint + "/my/" + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpPost post = new HttpPost(endpoint + "/my/" + resource);
if( payload != null && payload.startsWith("action") ) {
@@ -630,18 +585,7 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
}
post.addHeader("Accept", "application/json");
post.addHeader("X-Api-Version", VERSION);
- String auth;
-
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- post.addHeader("Authorization", "Basic " + auth);
try {
if( payload != null && payload.startsWith("action") ) {
//noinspection deprecation
@@ -769,24 +713,12 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
wire.debug(">>> [POST (" + (new Date()) + ")] -> " + endpoint + "/" + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpPost post = new HttpPost(endpoint + resource);
post.addHeader("Content-Type", "application/octet-stream");
post.addHeader("Accept", "application/json");
post.addHeader("X-Api-Version", VERSION);
- String auth;
-
- try {
- String userName = new String(provider.getContext().getAccessPublic(), "utf-8");
- String password = new String(provider.getContext().getAccessPrivate(), "utf-8");
-
- auth = new String(Base64.encodeBase64((userName + ":" + password).getBytes()));
- }
- catch( UnsupportedEncodingException e ) {
- throw new InternalException(e);
- }
- post.addHeader("Authorization", "Basic " + auth);
post.setEntity(new InputStreamEntity(stream, -1L, ContentType.APPLICATION_OCTET_STREAM));
if( wire.isDebugEnabled() ) {
@@ -911,13 +843,12 @@ public void doDelete(@Nonnull String endpoint, @Nonnull String resource) throws
wire.debug(">>> [PUT (" + (new Date()) + ")] -> " + endpoint + "/" + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpPut put = new HttpPut(endpoint + resource);
put.addHeader("Content-Type", "application/json");
put.addHeader("Accept", "application/json");
put.addHeader("X-Auth-Token", authToken);
-
if( customHeaders != null ) {
for( Map.Entry<String, String> entry : customHeaders.entrySet() ) {
String val = (entry.getValue() == null ? "" : entry.getValue());
@@ -1038,7 +969,7 @@ protected String putString(@Nonnull String authToken, @Nonnull String endpoint,
wire.debug(">>> [PUT (" + (new Date()) + ")] -> " + endpoint + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpPut put = new HttpPut(endpoint + resource);
put.addHeader("Content-Type", "application/json");
@@ -1166,7 +1097,7 @@ protected String putString(@Nonnull String authToken, @Nonnull String endpoint,
wire.debug(">>> [PUT (" + (new Date()) + ")] -> " + endpoint + resource + " >--------------------------------------------------------------------------------------");
}
try {
- HttpClient client = getClient(endpoint);
+ HttpClient client = getClient();
HttpPut put = new HttpPut(endpoint + resource);
put.addHeader("Content-Type", "application/octet-stream");
@@ -18,8 +18,13 @@
package org.dasein.cloud.joyent;
-import org.dasein.cloud.test.GlobalTestSuite;
+import junit.framework.Test;
-public class TestSuite extends GlobalTestSuite {
+import org.dasein.cloud.test.ComprehensiveTestSuite;
+import org.dasein.cloud.test.TestConfigurationException;
+public class JoyentTestSuite {
+ static public Test suite() throws TestConfigurationException {
+ return new ComprehensiveTestSuite(SmartDataCenter.class);
+ }
}
@@ -8,7 +8,7 @@
<param name="DatePattern" value="'.'yyyy-MM-dd" />
<param name="Threshold" value="TRACE" />
<layout class="org.apache.log4j.PatternLayout">
- <param name="ConversionPattern" value="[%d] %m%n" />
+ <param name="ConversionPattern" value="%d %-5p [%c] (%t) %m%n" />
</layout>
</appender>

0 comments on commit 3ad2191

Please sign in to comment.