Callback: onResourceDiscoveryRequest

Last modified: Jul 5, 2019 @ 06:41

This callback notifies the gateway implementation that DDM wants to discover what resources exists for a smart object instance.

The implementation is expected to respond with a DeviceRegisterResponse containing the resources discovered.

The following is an example implementation of the callback. This example needs to be complemented with code for getting the device by the endpoint value.

Path allows you to easily query the resource link for object ID, instance ID, etc.

@Override 
2.public void onResourceDiscoveryRequest(String correlationId, String endpoint, ResourceLink resourceLink) { 
3.  // Get the device by the endpoint value and do the following 
4.  Path path = new Path(resourceLink.getUrl()); 
5.  if(path.getObjectId() == 3303 && path.getObjectInstanceId() == 0) { 
6.    List<ResourceLink> resourceLinks = new ArrayList<>(); 
7.    resourceLinks.add(new ResourceLink("/3303/0/5700")); 
8.    resourceLinks.add(new ResourceLink("/3303/0/5701")); 
9.    resourceLinks.add(new ResourceLink("/3303/0/5601")); 
10.    resourceLinks.add(new ResourceLink("/3303/0/5602")); 
11.    resourceLinks.add(new ResourceLink("/3303/0/5605")); 
12. 
13.    ResourceDiscoveryResponse resourceDiscoveryResponse = new ResourceDiscoveryResponse(); 
14.    resourceDiscoveryResponse.setResourceLinks(resourceLinks); 
15.    resourceDiscoveryResponse.setResponseCode(new ResponseCode(ResponseCode.CONTENT, "")); 
16. 
17.    try { 
18.      gateway.sendResourceDiscoveryResponse(correlationId, endpoint, resourceDiscoveryResponse); 
19.    } catch (GatewayException e) { 
20.      logger.log(Level.WARNING, "Failed to send response to DDM", e); 
21.    } 
22.  } 
23.}

The following message sequence chart shows the resource discovery process.