[ARVADOS] updated: a998a520deb859216271567f1bf3623f310cf2d6

git at public.curoverse.com git at public.curoverse.com
Sun May 4 17:54:00 EDT 2014


Summary of changes:
 .../main/java/org/arvados/sdk/java/Arvados.java    |   90 +++++++++-----------
 .../java/org/arvados/sdk/java/ArvadosTest.java     |    8 +--
 2 files changed, 44 insertions(+), 54 deletions(-)

       via  a998a520deb859216271567f1bf3623f310cf2d6 (commit)
      from  51928265eaf8ca6b6319dd231d74604ceb3af287 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.


commit a998a520deb859216271567f1bf3623f310cf2d6
Author: radhika <radhika at curoverse.com>
Date:   Sun May 4 17:53:23 2014 -0400

    2525: Better handling of unsupported api name and version

diff --git a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
index fb71493..bb5aac9 100644
--- a/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
+++ b/sdk/java/src/main/java/org/arvados/sdk/java/Arvados.java
@@ -50,58 +50,57 @@ public class Arvados {
 
   private static final Logger logger = Logger.getLogger(Arvados.class);
 
-  // Get it on a discover call and reuse on the call requests
+  // Get it once and reuse on the call requests
   RestDescription restDescription = null;
   String apiName = null;
   String apiVersion = null;
 
-  public Arvados (String apiName, String apiVersion){
+  public Arvados (String apiName, String apiVersion) throws Exception {
     this (apiName, apiVersion, null, null, null);
   }
 
   public Arvados (String apiName, String apiVersion, String token,
-            String host, String hostInsecure){
-    try {
-      this.apiName = apiName;
-      this.apiVersion = apiVersion;
-
-      // Read needed environmental variables if they are not passed
-      if (token != null) {
-        arvadosApiToken = token;
-      } else {
-        arvadosApiToken = System.getenv().get("ARVADOS_API_TOKEN");
-        if (arvadosApiToken == null) {
-          throw new Exception("Missing environment variable: ARVADOS_API_TOKEN");
-        }
+      String host, String hostInsecure) throws Exception {
+    this.apiName = apiName;
+    this.apiVersion = apiVersion;
+
+    // Read needed environmental variables if they are not passed
+    if (token != null) {
+      arvadosApiToken = token;
+    } else {
+      arvadosApiToken = System.getenv().get("ARVADOS_API_TOKEN");
+      if (arvadosApiToken == null) {
+        throw new Exception("Missing environment variable: ARVADOS_API_TOKEN");
       }
+    }
 
-      if (host != null) {
-        arvadosApiHost = host;
-      } else {
-        arvadosApiHost = System.getenv().get("ARVADOS_API_HOST");      
-        if (arvadosApiHost == null) {
-          throw new Exception("Missing environment variable: ARVADOS_API_HOST");
-        }
-      }
-      arvadosRootUrl = "https://" + arvadosApiHost;
-      arvadosRootUrl += (arvadosApiHost.endsWith("/")) ? "" : "/";
-
-      if (hostInsecure != null) {
-        arvadosApiHostInsecure = Boolean.valueOf(hostInsecure);
-      } else {
-        arvadosApiHostInsecure =
-            "true".equals(System.getenv().get("ARVADOS_API_HOST_INSECURE")) ? true : false;
+    if (host != null) {
+      arvadosApiHost = host;
+    } else {
+      arvadosApiHost = System.getenv().get("ARVADOS_API_HOST");      
+      if (arvadosApiHost == null) {
+        throw new Exception("Missing environment variable: ARVADOS_API_HOST");
       }
+    }
+    arvadosRootUrl = "https://" + arvadosApiHost;
+    arvadosRootUrl += (arvadosApiHost.endsWith("/")) ? "" : "/";
+
+    if (hostInsecure != null) {
+      arvadosApiHostInsecure = Boolean.valueOf(hostInsecure);
+    } else {
+      arvadosApiHostInsecure =
+          "true".equals(System.getenv().get("ARVADOS_API_HOST_INSECURE")) ? true : false;
+    }
 
-      // Create HTTP_TRANSPORT object
-      NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
-      if (arvadosApiHostInsecure) {
-        builder.doNotValidateCertificate();
-      }
-      httpTransport = builder.build();
-    } catch (Throwable t) {
-      t.printStackTrace();
+    // Create HTTP_TRANSPORT object
+    NetHttpTransport.Builder builder = new NetHttpTransport.Builder();
+    if (arvadosApiHostInsecure) {
+      builder.doNotValidateCertificate();
     }
+    httpTransport = builder.build();
+
+    // initialize rest description
+    restDescription = loadArvadosApi();
   }
 
   /**
@@ -109,7 +108,7 @@ public class Arvados {
    * @param resourceName
    * @param methodName
    * @param paramsMap
-   * @return Object
+   * @return Map
    * @throws Exception
    */
   public Map call(String resourceName, String methodName,
@@ -212,11 +211,6 @@ public class Arvados {
       error("missing method name");      
     }
 
-    // initialize rest description if not already
-    if (restDescription == null) {
-      restDescription = loadArvadosApi();
-    }
-
     Map<String, RestMethod> methodMap = null;
     Map<String, RestResource> resources = restDescription.getResources();
     RestResource resource = resources.get(resourceName);
@@ -274,14 +268,14 @@ public class Arvados {
       } else if ("float".equals(parameter.getType())) {
         value = new BigDecimal(parameterValue.toString());
       } else if (("array".equals(parameter.getType())) ||
-                 ("Array".equals(parameter.getType()))) {
+          ("Array".equals(parameter.getType()))) {
         if (parameterValue.getClass().isArray()){
           value = getJsonValueFromArrayType(parameterValue);
         } else if (List.class.isAssignableFrom(parameterValue.getClass())) {
           value = getJsonValueFromListType(parameterValue);
         }
       } else if (("Hash".equals(parameter.getType())) ||
-                 ("hash".equals(parameter.getType()))) {
+          ("hash".equals(parameter.getType()))) {
         value = getJsonValueFromMapType(parameterValue);
       } else {
         if (parameterValue.getClass().isArray()){
@@ -293,7 +287,7 @@ public class Arvados {
         }
       }
     }
-    
+
     parameters.put(parameterName, value);
   }
 
diff --git a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
index 110114e..35b78f4 100644
--- a/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
+++ b/sdk/java/src/test/java/org/arvados/sdk/java/ArvadosTest.java
@@ -165,11 +165,9 @@ public class ArvadosTest {
    */
   @Test
   public void testUnsupportedApiName() throws Exception {
-    Arvados arv = new Arvados("not_arvados", "v1");
-
     Exception caught = null;
     try {
-      arv.call("users", "list", null);
+      Arvados arv = new Arvados("not_arvados", "v1");
     } catch (Exception e) {
       caught = e;
     }
@@ -184,11 +182,9 @@ public class ArvadosTest {
    */
   @Test
   public void testUnsupportedVersion() throws Exception {
-    Arvados arv = new Arvados("arvados", "v2");
-
     Exception caught = null;
     try {
-      arv.call("users", "list", null);
+      Arvados arv = new Arvados("arvados", "v2");
     } catch (Exception e) {
       caught = e;
     }

-----------------------------------------------------------------------


hooks/post-receive
-- 




More information about the arvados-commits mailing list