Throw OcException for invalid (null) parameters in Java Layer of android_api
authorLarry Sachs <larry.j.sachs@intel.com>
Thu, 29 Sep 2016 17:46:19 +0000 (10:46 -0700)
committerRick Bell <richard.s.bell@intel.com>
Fri, 30 Sep 2016 04:42:19 +0000 (04:42 +0000)
[IOT-1323] -- [RI][Android] observe(with QualityOfService) API does not throw OcException while passing parameter-observeType as Null value

Change-Id: If0d7acb0f5bbfda75e2fd774b6cccc8ce21e5650
Signed-off-by: Larry Sachs <larry.j.sachs@intel.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/12571
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
Reviewed-by: jihwan seo <jihwan.seo@samsung.com>
Reviewed-by: Rick Bell <richard.s.bell@intel.com>
android/android_api/base/src/androidTest/java/org/iotivity/base/SmokeTest.java
android/android_api/base/src/main/java/org/iotivity/base/OcResource.java
android/examples/fridgeclient/src/main/java/org/iotivity/base/examples/FridgeClient.java

index 9f814d8..a3a2ba7 100644 (file)
@@ -1335,7 +1335,12 @@ public class SmokeTest extends InstrumentationTestCase {
                         headerOptionList.add(new OcHeaderOption(2885, "OptionData1"));
                         headerOptionList.add(new OcHeaderOption(2886, "OptionData2"));
 
-                        resource.setHeaderOptions(headerOptionList);
+                        try {
+                            resource.setHeaderOptions(headerOptionList);
+                        } catch (OcException e) {
+                            Log.e(TAG, "onResourceFound, error in setHeaderOptions -- " + e.getMessage());
+                        }
+
                         resource.unsetHeaderOptions();
 
                         OcResourceIdentifier resourceIdentifier = resource.getUniqueIdentifier();
index c0fd090..f9cc04f 100644 (file)
@@ -65,6 +65,11 @@ public class OcResource {
     public void get(Map<String, String> queryParamsMap,
                     OnGetListener onGetListener,
                     QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.get1(queryParamsMap, onGetListener, qualityOfService.getValue());
     }
 
@@ -116,6 +121,11 @@ public class OcResource {
                     Map<String, String> queryParamsMap,
                     OnGetListener onGetListener,
                     QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.get3(
                 resourceType,
                 resourceInterface,
@@ -157,6 +167,11 @@ public class OcResource {
                     Map<String, String> queryParamsMap,
                     OnPutListener onPutListener,
                     QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.put1(
                 ocRepresentation,
                 queryParamsMap,
@@ -217,6 +232,11 @@ public class OcResource {
                     Map<String, String> queryParamsMap,
                     OnPutListener onPutListener,
                     QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.put3(
                 resourceType,
                 resourceInterface,
@@ -260,6 +280,11 @@ public class OcResource {
                      Map<String, String> queryParamsMap,
                      OnPostListener onPostListener,
                      QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.post1(
                 ocRepresentation,
                 queryParamsMap,
@@ -320,6 +345,11 @@ public class OcResource {
                      Map<String, String> queryParamsMap,
                      OnPostListener onPostListener,
                      QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.post3(
                 resourceType,
                 resourceInterface,
@@ -351,6 +381,11 @@ public class OcResource {
      */
     public void deleteResource(OnDeleteListener onDeleteListener,
                                QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.deleteResource1(onDeleteListener,
                 qualityOfService.getValue());
     }
@@ -399,6 +434,15 @@ public class OcResource {
                         Map<String, String> queryParamsMap,
                         OnObserveListener onObserveListener,
                         QualityOfService qualityOfService) throws OcException {
+
+        if (observeType == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "observeType cannot be null");
+        }
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.observe1(
                 observeType.getValue(),
                 queryParamsMap,
@@ -427,6 +471,11 @@ public class OcResource {
      * @throws OcException
      */
     public void cancelObserve(QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.cancelObserve1(qualityOfService.getValue());
     }
 
@@ -437,8 +486,14 @@ public class OcResource {
      *
      * @param headerOptionList List<OcHeaderOption> where header information(header optionID and
      *                         optionData is passed
+     * @throws OcException
      */
-    public void setHeaderOptions(List<OcHeaderOption> headerOptionList) {
+    public void setHeaderOptions(List<OcHeaderOption> headerOptionList) throws OcException {
+
+        if (headerOptionList == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "headerOptionList cannot be null");
+        }
+
         this.setHeaderOptions(headerOptionList.toArray(
                         new OcHeaderOption[headerOptionList.size()])
         );
@@ -609,6 +664,11 @@ public class OcResource {
     public void discoveryMQTopics(Map<String, String> queryParamsMap,
                                   OnMQTopicFoundListener onTopicFoundListener,
                                   QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.discoveryMQTopicsImpl(queryParamsMap, onTopicFoundListener,
                                    qualityOfService.getValue());
     }
@@ -634,6 +694,11 @@ public class OcResource {
                               Map<String, String> queryParamsMap,
                               OnMQTopicCreatedListener onTopicCreatedListener,
                               QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.createMQTopicImpl(ocRepresentation, uri, queryParamsMap,
                                onTopicCreatedListener, qualityOfService.getValue());
     }
@@ -657,6 +722,11 @@ public class OcResource {
     public void subscribeMQTopic(Map<String, String> queryParamsMap,
                                  OnObserveListener onObserveListener,
                                  QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.subscribeMQTopicImpl(queryParamsMap,
                                   onObserveListener,
                                   qualityOfService.getValue());
@@ -673,6 +743,11 @@ public class OcResource {
      * @throws OcException
      */
     public void unsubscribeMQTopic(QualityOfService qualityOfService) throws OcException{
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.unsubscribeMQTopicImpl(qualityOfService.getValue());
     }
 
@@ -691,6 +766,11 @@ public class OcResource {
     public void requestMQPublish(Map<String, String> queryParamsMap,
                      OnPostListener onPostListener,
                      QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.requestMQPublishImpl(queryParamsMap,
                                   onPostListener,
                                   qualityOfService.getValue());
@@ -714,6 +794,11 @@ public class OcResource {
                      Map<String, String> queryParamsMap,
                      OnPostListener onPostListener,
                      QualityOfService qualityOfService) throws OcException {
+
+        if (qualityOfService == null) {
+            throw new OcException(ErrorCode.INVALID_PARAM, "qualityOfService cannot be null");
+        }
+
         this.publishMQTopicImpl(ocRepresentation,
                                 queryParamsMap,
                                 onPostListener,
index 736e219..73c69a9 100755 (executable)
@@ -163,7 +163,12 @@ public class FridgeClient extends Activity implements
         OcHeaderOption clientToken = new OcHeaderOption(CLIENT_TOKEN_KEY, CLIENT_TOKEN);
         headerOptions.add(apiVersion);
         headerOptions.add(clientToken);
-        mFridgeResource.setHeaderOptions(headerOptions);
+        try {
+            mFridgeResource.setHeaderOptions(headerOptions);
+        } catch (OcException e) {
+            logMessage("Error in setHeaderOptions");
+            Log.e(TAG, e.getMessage());
+        }
 
         logMessage("Calling GET api on mFridgeResource and other component resources");
         try {