2016-07-06 10 views
0

동적으로 URL을 CoAP 서버에 추가하는 데 사용할 수있는 방법을 만들었습니다. 현재 구현 한 방법입니다. 그러나 이것이 CoAP 서버에 리소스를 추가하는 적절한 방법이라는 것을 알아야합니다. coapendpoints/home/room1/sensor1을 추가해야한다고 가정 해 봅니다.CoAP 서버에 리소스를 동적으로 추가하는 적절한 방법

// endpoint--> coapendpoints/home/room1/sensor1 
    String[] resources = endpoint.split("/"); 
    Resource childResource = coapServer.getRoot().getChild(resources[0]); 
    Resource parentResource = childResource; 
    if (parentResource == null && (resources.length > 1)) { 
     coapServer.add(new CoAPResourcePath(resources)); 
    } 
    if (parentResource == null && (resources.length == 1)) { 
     coapServer.add(new CoAPResourceServlet(resources[0])); 
    } else if (parentResource != null && resources.length > 1) { 
     int j = 1; 
     for (; j < resources.length; j++) { 
      if (childResource != null) { 
       parentResource = childResource; 
       childResource = childResource.getChild(resources[j]); 
      } else { 
       break; 
      } 
     } 
     String[] coapEndpoint = Arrays.copyOfRange(resources, j - 1, resources.length); 
     if (coapEndpoint.length > 1) { 
      parentResource.add(new CoAPResourcePath(coapEndpoint)); 
     } else if (coapEndpoint.length == 1) { 
      parentResource.add(new CoAPResourceServlet(coapEndpoint[0])); 
     } 
    } else if (parentResource != null && resources.length == 1) { 
     parentResource.add(new CoAPResourceServlet(resources[0])); 
    } 

여기서 CoAPResourcePath 및 CoAPResourceServlet 클래스는 CoapResource에서 확장됩니다.

이 방법으로 리소스를 추가 한 후의 출력입니다.
enter image description here

답변

0

비슷한 접근 방식으로 끝났습니다. 현재 Californium에는 편리한 방법으로 중첩 된 리소스를 만들 수있는 옵션이 없습니다.