Skip to main content
Jump to: navigation, search

OM2M/one/FlexContainers

< OM2M‎ | one

FlexContainer description

A FlexContainer is a resource similar to a Container. The main difference is the capability of a Flexcontainer to have an extensible set of custom attributes. FlexContainerObject.png

A FlexContainer has a containerDefinition attribute that defines the set of custom attributes a Flexcontainer holds.

More information in section 9.6.35 of TS0001 version 2.10.0


FlexContainer creation

Through HTTP binding

Request

HTTP method POST
URL http://<ip_cse>:<port_cse>/~/in-cse/in-name
Headers
Name Value Comments
X-M2M-Origin admin:admin Login:password
X-M2M-NM myFlexContainer Name of the to-be-created FlexContainer
Content-Type ty=28 Type of the resource to be created
Body
<?xml version="1.0" encoding="UTF-8"?> 
<m2m:fcnt xmlns:m2m="http://www.onem2m.org/xml/protocols" >
    <!-- cntDef is mandatory -->
    <cntDef>org.eclipse.om2m.mydef</cntDef> <br>

    <!-- some custom attributes -->    
    <myStringCustomAttribute  
                type="xs:string">stringValue</myStringCustomAttribute><br>
    <myIntegerCustomAttribute 
                type="xs:integer">123</myIntegerCustomAttribute><br>
</m2m:fcnt> 

An example:

POST /~/in-cse/in-name HTTP/1.1
Host: 127.0.0.1:8080
X-M2M-Origin: admin:admin
X-M2M-NM: myFlexContainer
Content-Type: ty=28
Cache-Control: no-cache
Postman-Token: 965301cf-ade2-a4f2-2b4e-a7b2d8758dca

<?xml version="1.0" encoding="UTF-8"?>
<m2m:fcnt xmlns:m2m="http://www.onem2m.org/xml/protocols" >
   
    <cntDef>org.eclipse.om2m.mydef</cntDef>
    
</m2m:fcnt>

Response

HTTP response code 201 CREATED
Response body
<?xml version="1.0" encoding="UTF-8"?>
<m2m:fcnt xmlns:m2m="http://www.onem2m.org/xml/protocols" rn="myFlexContainer">
   <ty>28</ty>

   <ri>/in-cse/fcnt-953225660</ri> 

   <pi>/in-cse</pi>

   <ct>20161221T100447</ct>

   <lt>20161221T100447</lt>

   <acpi>/in-cse/acp-34501615</acpi>

   <et>20171221T100447</et>

   <cntDef>org.eclipse.om2m.mydef</cntDef>

   < !-- custom attributes -->
   <myStringCustomAttribute 
          type="xs:string">stringValue</myStringCustomAttribute>
   <myIntegerCustomAttribute 
         type="xs:integer">123</myIntegerCustomAttribute>
</m2m:fcnt>


Through CSEService OSGi service

  1. // create a FlexContainer object
  2. FlexContainer flexContainer = new FlexContainer();
  3. flexContainer.setContainerDefinition("org.eclipse.om2m.mydef");
  4. flexContainer.setCreator("Orange");
  5.  
  6. // myStringCustomAttribute
  7. CustomAttribute myStringCustomAttribute = new CustomAttribute();
  8. myStringCustomAttribute.setCustomAttributeName("myStringCustomAttribute");
  9. myStringCustomAttribute.setCustomAttributeType("xs:string");
  10. myStringCustomAttribute.setCustomAttributeValue("stringValue");
  11. flexContainer.getCustomAttributes().add(myStringCustomAttribute);
  12.  
  13. // myIntegerCustomAttribute
  14. CustomAttribute myIntegerCustomAttribute = new CustomAttribute();
  15. myIntegerCustomAttribute.setCustomAttributeName("myIntegerCustomAttribute");
  16. myIntegerCustomAttribute.setCustomAttributeType("xs:integer");
  17. myIntegerCustomAttribute.setCustomAttributeValue("123");
  18. flexContainer.getCustomAttributes().add(myIntegerCustomAttribute);
  19.  
  20. // prepare request
  21. RequestPrimitive request = new RequestPrimitive();
  22. request.setContent(flexContainer);
  23. request.setFrom(“admin:admin”);
  24. request.setTargetId(/in-cse/in-name”);
  25. request.setTo(/in-cse/in-name”);
  26. request.setResourceType(ResourceType.FLEXCONTAINER);
  27. request.setRequestContentType(MimeMediaType.OBJ);
  28. request.setReturnContentType(MimeMediaType.OBJ);
  29. request.setName(“myFlexContainer”);
  30. request.setOperation(Operation.CREATE);
  31.  
  32. // execute request
  33. // cseService is an OSGi service registered by the CSE
  34. // cseService implements org.eclipse.om2m.core.service.CseService
  35. ResponsePrimitive response = cseService.doRequest(request);
  36.  
  37. // check response
  38. if (response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) {
  39.         // OK
  40.         FlexContainer responseCreatedFlexContainer = (FlexContainer) response.getContent();
  41.  
  42.         // use getters of FlexContainer to retrieve FlexContainer fields
  43. }


FlexContainer retrieving

Through HTTP binding

Request

HTTP method GET
URL http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer

or
http://<ip_cse>:<port_cse>/~/in-cse/fcnt-953225660

Headers
Name Value Comments
X-M2M-Origin admin:admin Login:password

An example:

GET /~/in-cse/in-name/myFlexContainer HTTP/1.1
Host: 127.0.0.1:8080
X-M2M-Origin: admin:admin
Cache-Control: no-cache
Postman-Token: 51dc4ccf-72df-a479-880b-891118112665

Response

HTTP response code 200 OK
Response body
<?xml version="1.0" encoding="UTF-8"?>
<m2m:fcnt xmlns:m2m="http://www.onem2m.org/xml/protocols" rn="myFlexContainer">

   <ty>28</ty>

   <ri>/in-cse/fcnt-491936033</ri>

   <pi>/in-cse</pi>

   <ct>20161221T102226</ct>

   <lt>20161221T102226</lt>
   <acpi>/in-cse/acp-34501615</acpi>

   <et>20171221T102226</et>

   <cntDef>org.eclipse.om2m.mydef</cntDef>

   <myStringCustomAttribute 
               type="xs:string">stringValue</myStringCustomAttribute>
   <myIntegerCustomAttribute 
               type="xs:integer">123</myIntegerCustomAttribute>
</m2m:fcnt>


Through CSEService OSGi service

  1. // prepare request
  2. RequestPrimitive request = new RequestPrimitive();
  3. request.setFrom(“admin:admin”);
  4.  
  5. request.setTargetId(/in-cse/in-name/myFlexContainer”);
  6. // targetId could also be “/in-cse/fcnt-491936033”
  7. request.setTo(/in-cse/in-name/myFlexContainer”););
  8. request.setRequestContentType(MimeMediaType.OBJ);
  9. request.setReturnContentType(MimeMediaType.OBJ);
  10. request.setOperation(Operation.RETRIEVE);
  11.  
  12. // several ResultContent type possibles
  13. request.setResultContent(ResultContent.ATTRIBUTES_AND_CHILD_REF);
  14.  
  15. // execute request
  16. ResponsePrimitive response = cseService.doRequest(request);
  17.  
  18. if (response.getResponseStatusCode().equals(ResponseStatusCode.OK)) {
  19.         // OK
  20.         FlexContainer responseCreatedFlexContainer = (FlexContainer) response.getContent();
  21.  
  22.         // use getters of FlexContainer to retrieve FlexContainer fields
  23.         responseCreatedFlexContainer.getName();
  24.         responseCreatedFlexContainer.getContainerDefinition();
  25.         …
  26. }


FlexContainer update

Through HTTP binding

Request

HTTP method PUT
URL http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer

or
http://<ip_cse>:<port_cse>/~/in-cse/fcnt-953225660

Headers
Name Value Comments
X-M2M-Origin admin:admin Login:password
Body
<?xml version="1.0" encoding="UTF-8"?>
<m2m:fcnt xmlns:m2m="http://www.onem2m.org/xml/protocols" >

    <!-- acpi field is updatable -->
    <!-- other fields except custom attribute fields are not updatable -->

    <!-- custom attribute fields are updatable -->
    <myStringCustomAttribute  
                type="xs:string">newStringValue</myStringCustomAttribute>
    <myIntegerCustomAttribute 
                type="xs:integer">1234567</myIntegerCustomAttribute>
</m2m:fcnt>

An example:

PUT /~/in-cse/in-name/myFlexContainer HTTP/1.1
Host: 127.0.0.1:8080
X-M2M-Origin: admin:admin
Cache-Control: no-cache
Postman-Token: d05b77ed-f1bd-4edc-fc26-c79a49f9c7de

<?xml version="1.0" encoding="UTF-8"?>
<m2m:fcnt xmlns:m2m="http://www.onem2m.org/xml/protocols" >
    <!-- only custom attribute fields are updatable -->
    <myStringCustomAttribute  
                type="xs:string">newStringValue</myStringCustomAttribute>
    <myIntegerCustomAttribute 
                type="xs:integer">1234567</myIntegerCustomAttribute>
</m2m:fcnt>

Response

HTTP response code 200 OK
Response body
<?xml version="1.0" encoding="UTF-8"?>
<m2m:fcnt xmlns:m2m="http://www.onem2m.org/xml/protocols">

   <lt>20161221T113042</lt>

   <myStringCustomAttribute 
            type="xs:string">newStringValue</myStringCustomAttribute>
   <myIntegerCustomAttribute 
           type="xs:integer">1234567</myIntegerCustomAttribute>

</m2m:fcnt>


Through CSEService OSGi service

  1. // prepare FlexContainer object
  2. FlexContainer toBeUpdated = new FlexContainer();
  3.  
  4. CustomAttribute myStringCustomAttribute = new CustomAttribute();
  5. myStringCustomAttribute.setCustomAttributeValue("newStringValue");
  6. myStringCustomAttribute.setCustomAttributeName("myStringCustomAttribute");
  7. myStringCustomAttribute.setCustomAttributeType("xs:string");
  8. toBeUpdated.getCustomAttributes().add(myStringCustomAttribute);
  9.  
  10. CustomAttribute myIntegerCustomAttribute = new CustomAttribute();
  11. myIntegerCustomAttribute.setCustomAttributeName("myIntegerCustomAttribute");
  12. myIntegerCustomAttribute.setCustomAttributeType("xs:integer");
  13. myIntegerCustomAttribute.setCustomAttributeValue("1234567");
  14. toBeUpdated.getCustomAttributes().add(myIntegerCustomAttribute);
  15.  
  16. // prepare request
  17. RequestPrimitive request = new RequestPrimitive();
  18. request.setContent(toBeUpdated);
  19. request.setFrom(“admin:admin”);
  20. request.setTargetId(/in-cse/in-name/myFlexContainer”);
  21. // targetId & to parameter could also be “/in-cse/fcnt-953225660”
  22. request.setTo(/in-cse/in-name/myFlexContainer”);
  23. request.setResourceType(ResourceType.FLEXCONTAINER);
  24. request.setRequestContentType(MimeMediaType.OBJ);
  25. request.setReturnContentType(MimeMediaType.OBJ);
  26. request.setOperation(Operation.UPDATE);
  27.  
  28. // execute request
  29. // cseService is an OSGi service retrieved through the OSGi registry
  30. ResponsePrimitive response = cseService.doRequest(request);
  31.  
  32. if (response.getResponseStatusCode().equals(ResponseStatusCode.UPDATED)) {
  33.         // OK
  34.         FlexContainer updatedFlexContainer = (FlexContainer)
  35.                                               response.getContent();
  36.  
  37.         // use getters of FlexContainer to retrieve FlexContainer fields
  38.  
  39. }


FlexContainer deletion

Through HTTP binding

Request

HTTP method DELETE
URL http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer

or
http://<ip_cse>:<port_cse>/~/in-cse/fcnt-953225660

Headers
Name Value Comments
X-M2M-Origin admin:admin Login:password

An example:

DELETE /~/in-cse/in-name/myFlexContainer HTTP/1.1
Host: 127.0.0.1:8080
X-M2M-Origin: admin:admin
Cache-Control: no-cache
Postman-Token: 6ff80941-5b77-f0c3-5103-df064bc06b5d
Content-Type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW

Response

HTTP response code 200 OK
Response body No body

Through CSEService OSGi service

  1. // prepare request
  2. RequestPrimitive request = new RequestPrimitive();
  3. request.setTargetId(/in-cse/in-name/myFlexContainer”);
  4. // targetId & to parameter could also be “/in-cse/fcnt-953225660”
  5. request.setTo(/in-cse/in-name/myFlexContainer”);
  6. request.setRequestContentType(MimeMediaType.OBJ);
  7. request.setReturnContentType(MimeMediaType.OBJ);
  8. request.setOperation(Operation.DELETE);
  9.  
  10. // execute request
  11. ResponsePrimitive response = cseService.doRequest(request);
  12.  
  13. // check response
  14. if (response.getResponseStatusCode().equals(ResponseStatusCode.DELETED)) {
  15.         // OK
  16. }

FlexContainerService

A FlexContainerService is an OSGi service attached to a single FlexContainer resource. It is used to retrieve and set value of the custom attributes belonging to a particular FlexContainer.

If a FlexContainer has no FlexContainerService instance, the customAttribute values are read and set in the database.

A FlexContainerService has to be registered into the OSGi registry in order to be available to the CSE.

Example:

  1. // create a flexContainerService
  2. FlexContainerService fcs = new FlexContainerService() {
  3.  
  4.         @Override
  5.         public void setCustomAttributeValues(List<CustomAttribute> customAttributes,   
  6.                       RequestPrimitive requestPrimitive
  7.                      ) throws Om2mException {
  8.                 // this method is called when the FlexContainer
  9.                 // associated to this FlexContainerService
  10.                 // instance is updated.
  11.                 // put here the business code
  12.                 // that take into account the new customAttribute
  13.                 // values
  14.         }
  15.  
  16.         @Override
  17.         public String getFlexContainerLocation() {
  18.                 // this method MUST return the resourceId of the
  19.                 // attached FlexContainer      
  20.                 return flexContainer.getResourceID();
  21.         }
  22.  
  23.         @Override
  24.         public String getCustomAttributeValue(String customAttributeName) throws Om2mException {
  25.                 // this method is called by the CSE when it
  26.                 // receive a RETRIEVE request for the attached
  27.                 // FlexContainer
  28.                 // this method has to return the value of the
  29.                 // customAttribute specified by
  30.                 // customAttributeName argument
  31.                 return customAttributeValue;
  32.         }
  33.  
  34. };
  35.  
  36. // register FlexContainerService as an OSGi service
  37. flexContainerServiceRegistration = bundleContext.registerService(FlexContainerService.class, fcs, null);

Copyright © Eclipse Foundation, Inc. All Rights Reserved.