mirror of https://github.com/apache/jclouds.git
Issue 429: adjusted regex to accept both mosso and swift syntax
This commit is contained in:
parent
fa736f3467
commit
a4501eb9ca
|
@ -46,9 +46,9 @@ import org.jclouds.util.Utils;
|
|||
public class ParseCloudFilesErrorFromHttpResponse implements HttpErrorHandler {
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
public static final String MOSSO_PREFIX = "^/v1[^/]*/MossoCloudFS_[^/]+/";
|
||||
public static final Pattern CONTAINER_PATH = Pattern.compile(MOSSO_PREFIX + "([^/]+)$");
|
||||
public static final Pattern CONTAINER_KEY_PATH = Pattern.compile(MOSSO_PREFIX + "([^/]+)/(.*)");
|
||||
public static final String PREFIX = "^/v[0-9][^/]*/[a-zA-Z]+_[^/]+/";
|
||||
public static final Pattern CONTAINER_PATH = Pattern.compile(PREFIX + "([^/]+)$");
|
||||
public static final Pattern CONTAINER_KEY_PATH = Pattern.compile(PREFIX + "([^/]+)/(.*)");
|
||||
|
||||
public void handleError(HttpCommand command, HttpResponse response) {
|
||||
Exception exception = new HttpResponseException(command, response);
|
||||
|
|
|
@ -29,118 +29,116 @@ import static org.jclouds.rackspace.reference.RackspaceHeaders.STORAGE_URL;
|
|||
import java.net.URI;
|
||||
|
||||
import javax.annotation.Resource;
|
||||
import javax.inject.Singleton;
|
||||
import javax.inject.Inject;
|
||||
import javax.inject.Provider;
|
||||
import javax.ws.rs.core.UriBuilder;
|
||||
|
||||
import org.jclouds.http.HttpRequest;
|
||||
import org.jclouds.http.HttpResponse;
|
||||
import org.jclouds.logging.Logger;
|
||||
import org.jclouds.rackspace.RackspaceAuthAsyncClient.AuthenticationResponse;
|
||||
import org.jclouds.rest.InvocationContext;
|
||||
|
||||
import com.google.common.base.Function;
|
||||
import com.google.common.base.Objects;
|
||||
|
||||
/**
|
||||
* This parses {@link AuthenticationResponse} from HTTP headers.
|
||||
*
|
||||
* @author Adrian Cole
|
||||
*/
|
||||
@Singleton
|
||||
public class ParseAuthenticationResponseFromHeaders implements Function<HttpResponse, AuthenticationResponse> {
|
||||
|
||||
public class ParseAuthenticationResponseFromHeaders implements Function<HttpResponse, AuthenticationResponse>,
|
||||
InvocationContext {
|
||||
|
||||
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;
|
||||
private final URI CDNManagementUrl;
|
||||
private final URI serverManagementUrl;
|
||||
private final URI storageUrl;
|
||||
|
||||
public AuthenticationResponseImpl(String authToken, String CDNManagementUrl, String serverManagementUrl,
|
||||
String storageUrl) {
|
||||
public AuthenticationResponseImpl(String authToken, URI CDNManagementUrl, URI serverManagementUrl, URI 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;
|
||||
}
|
||||
|
||||
public URI getCDNManagementUrl() {
|
||||
return URI.create(CDNManagementUrl);
|
||||
return CDNManagementUrl;
|
||||
}
|
||||
|
||||
public URI getServerManagementUrl() {
|
||||
return URI.create(serverManagementUrl);
|
||||
return serverManagementUrl;
|
||||
}
|
||||
|
||||
public URI getStorageUrl() {
|
||||
return URI.create(storageUrl);
|
||||
return storageUrl;
|
||||
}
|
||||
|
||||
// performance isn't a concern on a infrequent object like this, so using shortcuts;
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(CDNManagementUrl, authToken, serverManagementUrl, storageUrl);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object that) {
|
||||
if (that == null)
|
||||
return false;
|
||||
return Objects.equal(this.toString(), that.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return Objects.toStringHelper(this).add("CDNManagementUrl", CDNManagementUrl)
|
||||
.add("serverManagementUrl", serverManagementUrl).add("storageUrl", storageUrl).toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Resource
|
||||
protected Logger logger = Logger.NULL;
|
||||
|
||||
private final Provider<UriBuilder> uriBuilderProvider;
|
||||
private String hostToReplace;
|
||||
|
||||
@Inject
|
||||
public ParseAuthenticationResponseFromHeaders(Provider<UriBuilder> uriBuilderProvider) {
|
||||
this.uriBuilderProvider = uriBuilderProvider;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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);
|
||||
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()));
|
||||
AuthenticationResponse response = new AuthenticationResponseImpl(checkNotNull(
|
||||
from.getFirstHeaderOrNull(AUTH_TOKEN), AUTH_TOKEN), getURI(from, CDN_MANAGEMENT_URL), getURI(from,
|
||||
SERVER_MANAGEMENT_URL), getURI(from, STORAGE_URL));
|
||||
logger.debug("will connect to: ", response);
|
||||
return response;
|
||||
}
|
||||
|
||||
protected URI getURI(HttpResponse from, String header) {
|
||||
String headerValue = from.getFirstHeaderOrNull(header);
|
||||
if (headerValue == null)
|
||||
return null;
|
||||
URI toReturn = URI.create(headerValue);
|
||||
if (!"127.0.0.1".equals(toReturn.getHost()))
|
||||
return toReturn;
|
||||
return uriBuilderProvider.get().uri(toReturn).host(hostToReplace).build();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object setContext(HttpRequest request) {
|
||||
hostToReplace = request.getEndpoint().getHost();
|
||||
return this;
|
||||
}
|
||||
}
|
|
@ -19,6 +19,7 @@
|
|||
|
||||
package org.jclouds.rackspace.cloudservers;
|
||||
|
||||
import java.net.URI;
|
||||
import java.util.Date;
|
||||
|
||||
import org.jclouds.http.RequiresHttp;
|
||||
|
@ -39,8 +40,8 @@ public class TestRackspaceAuthenticationRestClientModule extends RackspaceAuthen
|
|||
|
||||
@Override
|
||||
protected AuthenticationResponse provideAuthenticationResponse(Supplier<AuthenticationResponse> supplier) {
|
||||
return new AuthenticationResponseImpl("authToken", "http://CDNManagementUrl", "http://serverManagementUrl",
|
||||
"http://storageUrl");
|
||||
return new AuthenticationResponseImpl("authToken", URI.create("http://CDNManagementUrl"),
|
||||
URI.create("http://serverManagementUrl"), URI.create("http://storageUrl"));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Loading…
Reference in New Issue