Changed way Guard works, Sped up code
[iotcloud.git] / version2 / src / java / iotcloud / CloudComm.java
index f38756d5fea4f3b6d877828ac392030f3b09169b..2db5ad988ecf04f96c0154eef7ab7b7c722b58bd 100644 (file)
@@ -90,7 +90,7 @@ class CloudComm {
                return new URL(urlstr);
        }
 
-       public void setSalt() {
+       public void setSalt() throws ServerException{
                try {
                        salt = new byte[SALT_SIZE];
                        random.nextBytes(salt);
@@ -106,12 +106,12 @@ class CloudComm {
                        int responsecode = http.getResponseCode();
                        if (responsecode != HttpURLConnection.HTTP_OK) {
                                // TODO: Remove this print
-                               System.out.println(responsecode);
+                               // System.out.println(responsecode);
                                throw new Error("Invalid response");
                        }
                } catch (Exception e) {
                        e.printStackTrace();
-                       throw new Error("Failed setting salt");
+                       throw new ServerException("Failed setting salt");
                }
                initCrypt();
        }
@@ -137,7 +137,7 @@ class CloudComm {
         * numbers.
         */
 
-       Slot[] putSlot(Slot slot, int max) {
+       Slot[] putSlot(Slot slot, int max)  throws ServerException{
                try {
                        if (salt == null) {
                                getSalt();
@@ -172,16 +172,17 @@ class CloudComm {
                                throw new Error("Bad response to putslot");
                } catch (Exception e) {
                        e.printStackTrace();
-                       throw new Error("putSlot failed");
+                       throw new ServerException("putSlot failed");
                }
        }
 
+
        /**
         * Request the server to send all slots with the given
         * sequencenumber or newer.
         */
 
-       Slot[] getSlots(long sequencenumber) {
+       Slot[] getSlots(long sequencenumber) throws ServerException {
                try {
                        if (salt == null) {
                                getSalt();
@@ -205,7 +206,7 @@ class CloudComm {
                                return processSlots(dis);
                } catch (Exception e) {
                        e.printStackTrace();
-                       throw new Error("getSlots failed");
+                       throw new ServerException("getSlots failed");
                }
        }