Issue 319: updated to new rackspace url

This commit is contained in:
Adrian Cole 2010-07-21 15:26:29 -07:00
parent 13fa341a0e
commit 5f486566b9
6 changed files with 92 additions and 38 deletions

View File

@ -39,7 +39,7 @@
<appengine.applicationid>jclouds-tweetstore</appengine.applicationid>
<devappserver.address>localhost</devappserver.address>
<devappserver.port>8088</devappserver.port>
<jclouds.tweetstore.blobstores>googlestorage,s3,azureblob</jclouds.tweetstore.blobstores>
<jclouds.tweetstore.blobstores>cloudfiles,googlestorage,s3,azureblob</jclouds.tweetstore.blobstores>
<jclouds.tweetstore.container>jclouds-tweetstore</jclouds.tweetstore.container>
</properties>

View File

@ -34,10 +34,14 @@ import com.google.common.util.concurrent.ListenableFuture;
* Provides access to Rackspace resources via their REST API.
* <p/>
*
* @see <a href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf" />
* @see <a
* href="http://docs.rackspacecloud.com/servers/api/cs-devguide-latest.pdf"
* />
* @author Adrian Cole
*/
@Path("v" + RackspaceAuthAsyncClient.VERSION)
public interface RackspaceAuthAsyncClient {
public static final String VERSION = "1.0";
public interface AuthenticationResponse {
@CloudFiles
@ -55,8 +59,6 @@ public interface RackspaceAuthAsyncClient {
@GET
@ResponseParser(ParseAuthenticationResponseFromHeaders.class)
@Path("/auth")
ListenableFuture<AuthenticationResponse> authenticate(
@HeaderParam(RackspaceHeaders.AUTH_USER) String user,
@HeaderParam(RackspaceHeaders.AUTH_KEY) String key);
ListenableFuture<AuthenticationResponse> authenticate(@HeaderParam(RackspaceHeaders.AUTH_USER) String user,
@HeaderParam(RackspaceHeaders.AUTH_KEY) String key);
}

View File

@ -34,8 +34,8 @@ public class RackspacePropertiesBuilder extends PropertiesBuilder {
@Override
protected Properties defaultProperties() {
Properties properties = super.defaultProperties();
properties.setProperty(PROPERTY_ENDPOINT, "https://api.mosso.com");
properties.setProperty(PROPERTY_API_VERSION, "TODO");
properties.setProperty(PROPERTY_ENDPOINT, "https://auth.api.rackspacecloud.com");
properties.setProperty(PROPERTY_API_VERSION, RackspaceAuthAsyncClient.VERSION);
return properties;
}

View File

@ -35,27 +35,25 @@ public class ParseCloudFilesErrorFromHttpResponse implements HttpErrorHandler {
Exception exception = new HttpResponseException(command, response);
try {
String content = parseErrorFromContentOrNull(command, response);
exception = content != null ? new HttpResponseException(command, response, content) : exception;
switch (response.getStatusCode()) {
case 401:
exception = new AuthorizationException(command.getRequest(), content);
break;
case 404:
if (!command.getRequest().getMethod().equals("DELETE")) {
String path = command.getRequest().getEndpoint().getPath();
Matcher matcher = CONTAINER_PATH.matcher(path);
case 401:
exception = new AuthorizationException(command.getRequest(), content, exception);
break;
case 404:
if (!command.getRequest().getMethod().equals("DELETE")) {
String path = command.getRequest().getEndpoint().getPath();
Matcher matcher = CONTAINER_PATH.matcher(path);
if (matcher.find()) {
exception = new ContainerNotFoundException(matcher.group(1), content);
} else {
matcher = CONTAINER_KEY_PATH.matcher(path);
if (matcher.find()) {
exception = new ContainerNotFoundException(matcher.group(1), content);
} else {
matcher = CONTAINER_KEY_PATH.matcher(path);
if (matcher.find()) {
exception = new KeyNotFoundException(matcher.group(1), matcher.group(2),
content);
}
exception = new KeyNotFoundException(matcher.group(1), matcher.group(2), content);
}
}
break;
default:
exception = new HttpResponseException(command, response, content);
}
break;
}
} finally {
releasePayload(response);

View File

@ -27,9 +27,11 @@ import static org.jclouds.rackspace.reference.RackspaceHeaders.STORAGE_URL;
import java.net.URI;
import javax.annotation.Resource;
import javax.inject.Singleton;
import org.jclouds.http.HttpResponse;
import org.jclouds.logging.Logger;
import org.jclouds.rackspace.RackspaceAuthAsyncClient.AuthenticationResponse;
import com.google.common.base.Function;
@ -40,24 +42,72 @@ import com.google.common.base.Function;
* @author Adrian Cole
*/
@Singleton
public class ParseAuthenticationResponseFromHeaders implements
Function<HttpResponse, AuthenticationResponse> {
public class ParseAuthenticationResponseFromHeaders implements Function<HttpResponse, AuthenticationResponse> {
public static final class AuthenticationResponseImpl implements AuthenticationResponse {
@Override
public int hashCode() {
final int prime = 31;
int result = 1;
result = prime * result + ((CDNManagementUrl == null) ? 0 : CDNManagementUrl.hashCode());
result = prime * result + ((authToken == null) ? 0 : authToken.hashCode());
result = prime * result + ((serverManagementUrl == null) ? 0 : serverManagementUrl.hashCode());
result = prime * result + ((storageUrl == null) ? 0 : storageUrl.hashCode());
return result;
}
@Override
public boolean equals(Object obj) {
if (this == obj)
return true;
if (obj == null)
return false;
if (getClass() != obj.getClass())
return false;
AuthenticationResponseImpl other = (AuthenticationResponseImpl) obj;
if (CDNManagementUrl == null) {
if (other.CDNManagementUrl != null)
return false;
} else if (!CDNManagementUrl.equals(other.CDNManagementUrl))
return false;
if (authToken == null) {
if (other.authToken != null)
return false;
} else if (!authToken.equals(other.authToken))
return false;
if (serverManagementUrl == null) {
if (other.serverManagementUrl != null)
return false;
} else if (!serverManagementUrl.equals(other.serverManagementUrl))
return false;
if (storageUrl == null) {
if (other.storageUrl != null)
return false;
} else if (!storageUrl.equals(other.storageUrl))
return false;
return true;
}
private final String authToken;
private final String CDNManagementUrl;
private final String serverManagementUrl;
private final String storageUrl;
public AuthenticationResponseImpl(String authToken, String CDNManagementUrl,
String serverManagementUrl, String storageUrl) {
public AuthenticationResponseImpl(String authToken, String CDNManagementUrl, String serverManagementUrl,
String storageUrl) {
this.authToken = authToken;
this.CDNManagementUrl = CDNManagementUrl;
this.serverManagementUrl = serverManagementUrl;
this.storageUrl = storageUrl;
}
@Override
public String toString() {
return "[CDNManagementUrl=" + CDNManagementUrl + ", serverManagementUrl=" + serverManagementUrl
+ ", storageUrl=" + storageUrl + "]";
}
public String getAuthToken() {
return authToken;
}
@ -75,17 +125,21 @@ public class ParseAuthenticationResponseFromHeaders implements
}
}
@Resource
protected Logger logger = Logger.NULL;
/**
* parses the http response headers to create a new {@link AuthenticationResponse} object.
* parses the http response headers to create a new
* {@link AuthenticationResponse} object.
*/
public AuthenticationResponse apply(HttpResponse from) {
releasePayload(from);
return new AuthenticationResponseImpl(checkNotNull(from.getFirstHeaderOrNull(AUTH_TOKEN),
AUTH_TOKEN), checkNotNull(from.getFirstHeaderOrNull(CDN_MANAGEMENT_URL),
CDN_MANAGEMENT_URL), checkNotNull(from.getFirstHeaderOrNull(SERVER_MANAGEMENT_URL),
SERVER_MANAGEMENT_URL), checkNotNull(from.getFirstHeaderOrNull(STORAGE_URL),
STORAGE_URL + " not found in headers:" + from.getStatusLine() + " - "
+ from.getHeaders()));
AuthenticationResponse response = new AuthenticationResponseImpl(checkNotNull(from
.getFirstHeaderOrNull(AUTH_TOKEN), AUTH_TOKEN), checkNotNull(from.getFirstHeaderOrNull(CDN_MANAGEMENT_URL),
CDN_MANAGEMENT_URL), checkNotNull(from.getFirstHeaderOrNull(SERVER_MANAGEMENT_URL), SERVER_MANAGEMENT_URL),
checkNotNull(from.getFirstHeaderOrNull(STORAGE_URL), STORAGE_URL + " not found in headers:"
+ from.getStatusLine() + " - " + from.getHeaders()));
logger.debug("will connect to: ", response);
return response;
}
}

View File

@ -46,7 +46,7 @@ public class RackspaceAuthAsyncClientTest extends RestClientTest<RackspaceAuthAs
Method method = RackspaceAuthAsyncClient.class.getMethod("authenticate", String.class, String.class);
HttpRequest httpRequest = processor.createRequest(method, "foo", "bar");
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/auth HTTP/1.1");
assertRequestLineEquals(httpRequest, "GET http://localhost:8080/v1.0 HTTP/1.1");
assertNonPayloadHeadersEqual(httpRequest, "X-Auth-Key: bar\nX-Auth-User: foo\n");
assertPayloadEquals(httpRequest, null, null, false);