Modify /oic/res response
authorJee Hyeok Kim <jihyeok13.kim@samsung.com>
Mon, 17 Oct 2016 06:34:17 +0000 (15:34 +0900)
committerJee Hyeok Kim <jihyeok13.kim@samsung.com>
Mon, 17 Oct 2016 08:23:08 +0000 (08:23 +0000)
1. Modify /oic/res response from cloud side.
   Return 4.04 Not found if no resources found.

Change-Id: I5a8bf56ff5a3c07c2dc489dc2721b76716d9f6fd
Signed-off-by: Jee Hyeok Kim <jihyeok13.kim@samsung.com>
Reviewed-on: https://gerrit.iotivity.org/gerrit/13335
Reviewed-by: Jaehong Jo <jaehong.jo@samsung.com>
Reviewed-by: Glen Youngjin Kim <glen.kim@samsung.com>
Tested-by: jenkins-iotivity <jenkins-iotivity@opendaylight.org>
cloud/resourcedirectory/src/main/java/org/iotivity/cloud/rdserver/resources/directory/res/DiscoveryResource.java
cloud/resourcedirectory/src/test/java/org/iotivity/cloud/testrdserver/DiscoveryResourceTest.java
cloud/samples/client/airconditioner/aircon_controller.cpp

index 3a1da17..1f7199f 100644 (file)
@@ -83,6 +83,11 @@ public class DiscoveryResource extends Resource {
         ArrayList<Object> response = mRdManager.discoverResource(diList, rtList,
                 ifList);
 
+        if (response.size() == 0) {
+            return MessageBuilder.createResponse(request,
+                    ResponseStatus.NOT_FOUND);
+        }
+
         return MessageBuilder.createResponse(request, ResponseStatus.CONTENT,
                 ContentFormat.APPLICATION_CBOR,
                 mCbor.encodingPayloadToCbor(response));
index b3709b5..1881f90 100644 (file)
@@ -85,11 +85,9 @@ public class DiscoveryResourceTest {
                 RDServerTestUtils.DISCOVERY_REQ_URI,
                 "rt=core.light;di=" + RDServerTestUtils.DI);
         mDiscoveryResource.onDefaultRequestReceived(mockDevice, request);
-        // assertion: if the response status is "CONTENT"
-        // assertion : if the payload is null
+        // assertion: if the response status is "NOT_FOUND"
         assertTrue(mLatch.await(2L, SECONDS));
-        assertTrue(methodCheck(mResponse, ResponseStatus.CONTENT));
-        assertTrue(nullPayloadCheck(mResponse));
+        assertTrue(methodCheck(mResponse, ResponseStatus.NOT_FOUND));
     }
 
     @Test
index 344ac22..bc9a929 100644 (file)
@@ -217,6 +217,8 @@ void foundAirconditionerResource(shared_ptr<OC::OCResource> resource)
 
 void foundDevice(shared_ptr<OC::OCResource> resource)
 {
+    cout << "Found device called!" << endl;
+
     vector<string> rt = resource->getResourceTypes();
 
     cout << "Device found: " << resource->uri() << endl;
@@ -248,6 +250,12 @@ void foundDevice(shared_ptr<OC::OCResource> resource)
     }
 }
 
+void errorFoundDevice(const std::string &uri, const int ecode)
+{
+    cout << "Found device error on " << uri << " code " << ecode << endl;
+    g_callbackLock.notify_all();
+}
+
 void presenceDevice(OCStackResult , const unsigned int i, const string &str)
 {
     cout << "Presence received, i=" << i << " str=" << str << endl;
@@ -325,7 +333,7 @@ int main(int argc, char *argv[])
 
     result = OCPlatform::findResource(g_host, "/oic/res?rt=oic.wk.d",
                                       static_cast<OCConnectivityType>(CT_ADAPTER_TCP | CT_IP_USE_V4),
-                                      &foundDevice);
+                                      &foundDevice, &errorFoundDevice);
 
     cout << " result: " << result << endl;