diff options
| author | Shireesh Anjal <shireesh@gluster.com> | 2011-07-05 13:16:45 +0530 |
|---|---|---|
| committer | Shireesh Anjal <shireesh@gluster.com> | 2011-07-05 13:24:31 +0530 |
| commit | 429d3149d5cf042f1aabc5836d7df451c7da06bd (patch) | |
| tree | f911faaa91cd87cbd26d864c12ecc6ed53a5df20 /src/com.gluster.storage.management.client | |
| parent | 70e5b09bba0a5d035bc7fd37db707cd041db9580 (diff) | |
Changed base URI of REST resources to include the API version
Diffstat (limited to 'src/com.gluster.storage.management.client')
3 files changed, 24 insertions, 21 deletions
diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/UsersClient.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/UsersClient.java index c839a15a..6dc251dc 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/UsersClient.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/UsersClient.java @@ -22,6 +22,8 @@ import java.net.ConnectException; import javax.ws.rs.core.Response; +import org.apache.log4j.Logger; + import com.gluster.storage.management.core.exceptions.GlusterRuntimeException; import com.gluster.storage.management.core.model.Status; import com.sun.jersey.api.client.UniformInterfaceException; @@ -32,6 +34,7 @@ public class UsersClient extends AbstractClient { private static final String RESOURCE_NAME = "users"; private static final String FORM_PARAM_OLD_PASSWORD = "oldpassword"; private static final String FORM_PARAM_NEW_PASSWORD = "newpassword"; + private static final Logger logger = Logger.getLogger(UsersClient.class); private String generateSecurityToken(String user, String password) { return new String(Base64.encode(user + ":" + password)); @@ -44,7 +47,7 @@ public class UsersClient extends AbstractClient { public void authenticate(String user, String password) { setSecurityToken(generateSecurityToken(user, password)); try { - fetchSubResource(user, String.class); + fetchSubResource(user, Status.class); } catch (RuntimeException e) { Throwable cause = e.getCause(); if(cause == null) { @@ -58,14 +61,16 @@ public class UsersClient extends AbstractClient { setSecurityToken(null); throw new GlusterRuntimeException("Invalid user id or password!"); } else { - // TODO: Log the exception - throw new GlusterRuntimeException("Exception during authentication: [" - + e1.getResponse().getStatus() + "]"); + String errMsg = "Exception during authentication: [" + e1.getResponse().getStatus() + "]"; + logger.error(errMsg); + throw new GlusterRuntimeException(errMsg); } } else if(cause instanceof ConnectException) { throw new GlusterRuntimeException("Couldn't connect to Gluster Management Gateway!"); } else { - throw new GlusterRuntimeException("Exception during authentication: [" + e.getMessage() + "]"); + String errMsg = "Exception during authentication: [" + e.getMessage() + "]"; + logger.error(errMsg); + throw new GlusterRuntimeException(errMsg); } } } @@ -80,20 +85,18 @@ public class UsersClient extends AbstractClient { } public static void main(String[] args) { -// UsersClient authClient = new UsersClient(); -// -// // authenticate user -// authClient.authenticate("gluster", "gluster"); -// -// // change password to gluster1 -// authClient.changePassword("gluster", "gluster", "gluster1"); -// -// // change it back to gluster -// authClient.changePassword("gluster", "gluster1", "gluster"); -// -// System.out.println("success"); - System.out.println(new String(Base64.encode("abcdefghijklmnopqrstuvwxyz"))); - System.out.println(new String(Base64.decode("YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXo="))); + UsersClient authClient = new UsersClient(); + + // authenticate user + authClient.authenticate("gluster", "gluster"); + + // change password to gluster1 + authClient.changePassword("gluster", "gluster", "gluster1"); + + // change it back to gluster + authClient.changePassword("gluster", "gluster1", "gluster"); + + System.out.println("success"); } /* diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java index 4726fc36..765735fb 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/constants/ClientConstants.java @@ -27,7 +27,7 @@ public class ClientConstants { public static final String SYS_PROP_SERVER_URL = "gluster.server.url"; public static final String DEFAULT_SERVER_URL = "https://localhost:8443/glustermg/linux.gtk.x86_64"; public static final String CONTEXT_ROOT = "glustermg"; - public static final String WEB_RESOURCE_BASE_PATH = "resources"; + public static final String REST_API_VERSION = "1.0"; // SSL related public static final String TRUSTED_KEYSTORE = "gmc-trusted.keystore"; diff --git a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java index 4f7ea64e..3f87fd27 100644 --- a/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java +++ b/src/com.gluster.storage.management.client/src/com/gluster/storage/management/client/utils/ClientUtil.java @@ -9,7 +9,7 @@ import com.gluster.storage.management.client.constants.ClientConstants; public class ClientUtil { public static URI getServerBaseURI() { - return UriBuilder.fromUri(getBaseURL()).path(ClientConstants.WEB_RESOURCE_BASE_PATH).build(); + return UriBuilder.fromUri(getBaseURL()).path(ClientConstants.REST_API_VERSION).build(); } private static String getBaseURL() { |
