Skip to main content

Notice: This Wiki is now read only and edits are no longer possible. Please see: https://gitlab.eclipse.org/eclipsefdn/helpdesk/-/wikis/Wiki-shutdown-plan for the plan.

Jump to: navigation, search

Difference between revisions of "OM2M/one/FlexContainers"

< OM2M‎ | one
(Created page with "This section describes how to create/retrieve/delete/update a FlexContainer resource. Complete description will be added soon after moderator validation for page creation.")
 
Line 1: Line 1:
This section describes how to create/retrieve/delete/update a FlexContainer resource.
+
== 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.
 +
[[File:FlexContainerObject.png]]
  
Complete description will be added soon after moderator validation for page creation.
+
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.6.0
 +
 
 +
 
 +
== FlexContainer creation ==
 +
=== Through HTTP binding ===
 +
==== Request ====
 +
{| class="wikitable"
 +
! HTTP method
 +
| POST
 +
|-
 +
! URL
 +
| http://<ip_cse>:<port_cse>/~/in-cse/in-name
 +
|-
 +
! Headers
 +
|
 +
{| class="wikitable"
 +
! Name
 +
! Value
 +
! Comments
 +
|-
 +
| X-M2M-Origin
 +
| admin:admin
 +
| Login:password
 +
|-
 +
| X-M2M-NM
 +
| myFlexContainer
 +
| Name of the to-be-created FlexContainer
 +
|-
 +
| Content-Type
 +
| ty=24
 +
| Type of the resource to be created
 +
|-
 +
|}
 +
|-
 +
! Body
 +
|
 +
<pre>
 +
<?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>
 +
</pre>
 +
|}
 +
 
 +
An example:
 +
<pre>
 +
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=24
 +
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>
 +
 
 +
</pre>
 +
 
 +
==== Response ====
 +
 
 +
{| class="wikitable"
 +
! 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 : resource type (24 = flexContainer) -->
 +
    <ty>24</ty>
 +
 +
    <!-- ri = resource identifier -->
 +
    <ri>/in-cse/fcnt-953225660</ri>
 +
 +
    <!-- pi = parent identifier -->
 +
    <pi>/in-cse</pi>
 +
 +
    <!-- ct = creation time -->
 +
    <ct>20161221T100447</ct>
 +
 +
    <!-- lt = last modified time -->
 +
    <lt>20161221T100447</lt>
 +
 +
    <!-- acpi = Access Control Policy identifiers -->
 +
    <acpi>/in-cse/acp-34501615</acpi>
 +
 +
    <!-- et = expiration time -->
 +
    <et>20171221T100447</et>
 +
 +
    <!--cntDef = container definition -->
 +
    <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 ===
 +
 
 +
<source lang="java" enclose="div" line>
 +
// create a FlexContainer object
 +
FlexContainer flexContainer = new FlexContainer();
 +
flexContainer.setContainerDefinition("org.eclipse.om2m.mydef");
 +
flexContainer.setCreator("Orange");
 +
 
 +
// myStringCustomAttribute
 +
CustomAttribute myStringCustomAttribute = new CustomAttribute();
 +
myStringCustomAttribute.setCustomAttributeName("myStringCustomAttribute");
 +
myStringCustomAttribute.setCustomAttributeType("xs:string");
 +
myStringCustomAttribute.setCustomAttributeValue("stringValue");
 +
flexContainer.getCustomAttributes().add(myStringCustomAttribute);
 +
 
 +
// myIntegerCustomAttribute
 +
CustomAttribute myIntegerCustomAttribute = new CustomAttribute();
 +
myIntegerCustomAttribute.setCustomAttributeName("myIntegerCustomAttribute");
 +
myIntegerCustomAttribute.setCustomAttributeType("xs:integer");
 +
myIntegerCustomAttribute.setCustomAttributeValue("123");
 +
flexContainer.getCustomAttributes().add(myIntegerCustomAttribute);
 +
 
 +
// prepare request
 +
RequestPrimitive request = new RequestPrimitive();
 +
request.setContent(flexContainer);
 +
request.setFrom(“admin:admin”);
 +
request.setTargetId(“/in-cse/in-name”);
 +
request.setTo(“/in-cse/in-name”);
 +
request.setResourceType(ResourceType.FLEXCONTAINER);
 +
request.setRequestContentType(MimeMediaType.OBJ);
 +
request.setReturnContentType(MimeMediaType.OBJ);
 +
request.setName(“myFlexContainer”);
 +
request.setOperation(Operation.CREATE);
 +
 
 +
// execute request
 +
// cseService is an OSGi service registered by the CSE
 +
// cseService implements org.eclipse.om2m.core.service.CseService
 +
ResponsePrimitive response = cseService.doRequest(request);
 +
 
 +
// check response
 +
if (response.getResponseStatusCode().equals(ResponseStatusCode.CREATED)) {
 +
        // OK
 +
FlexContainer responseCreatedFlexContainer = (FlexContainer) response.getContent();
 +
 
 +
        // use getters of FlexContainer to retrieve FlexContainer fields
 +
}
 +
</source>
 +
 
 +
 
 +
== FlexContainer retrieving ==
 +
=== Through HTTP binding ===
 +
==== Request ====
 +
{| class="wikitable"
 +
! HTTP method
 +
| GET
 +
|-
 +
! URL
 +
| http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer <br/>
 +
or <br/>
 +
http://<ip_cse>:<port_cse>/~/in-cse/fcnt-953225660
 +
|-
 +
! Headers
 +
|
 +
{| class="wikitable"
 +
! Name
 +
! Value
 +
! Comments
 +
|-
 +
| X-M2M-Origin
 +
| admin:admin
 +
| Login:password
 +
|}
 +
|}
 +
 
 +
An example:
 +
<pre>
 +
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
 +
</pre>
 +
 
 +
==== Response ====
 +
 
 +
{| class="wikitable"
 +
! 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 : resource type (24 = flexContainer) -->
 +
    <ty>24</ty>
 +
 +
    <!-- ri = resource identifier -->
 +
    <ri>/in-cse/fcnt-491936033</ri>
 +
 +
    <!-- pi = parent identifier -->
 +
    <pi>/in-cse</pi>
 +
 +
    <!-- ct = creation time -->
 +
    <ct>20161221T102226</ct>
 +
 +
    <!-- lt = last modified time -->
 +
    <lt>20161221T102226</lt>
 +
    <!-- acpi = Access Control Policy identifiers -->
 +
    <acpi>/in-cse/acp-34501615</acpi>
 +
 +
    <!-- et = expiration time -->
 +
    <et>20171221T102226</et>
 +
 +
    <!--cntDef = container definition -->
 +
    <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 ===
 +
 
 +
<source lang="java" enclose="div" line>
 +
// prepare request
 +
RequestPrimitive request = new RequestPrimitive();
 +
request.setFrom(“admin:admin”);
 +
 
 +
request.setTargetId(“/in-cse/in-name/myFlexContainer”);
 +
// targetId could also be “/in-cse/fcnt-491936033”
 +
request.setTo(“/in-cse/in-name/myFlexContainer”););
 +
request.setRequestContentType(MimeMediaType.OBJ);
 +
request.setReturnContentType(MimeMediaType.OBJ);
 +
request.setOperation(Operation.RETRIEVE);
 +
 
 +
// several ResultContent type possibles
 +
request.setResultContent(ResultContent.ATTRIBUTES_AND_CHILD_REF);
 +
 
 +
// execute request
 +
ResponsePrimitive response = cseService.doRequest(request);
 +
 
 +
if (response.getResponseStatusCode().equals(ResponseStatusCode.OK)) {
 +
        // OK
 +
FlexContainer responseCreatedFlexContainer = (FlexContainer) response.getContent();
 +
 
 +
        // use getters of FlexContainer to retrieve FlexContainer fields
 +
        responseCreatedFlexContainer.getName();
 +
        responseCreatedFlexContainer.getContainerDefinition();
 +
        …
 +
}
 +
 
 +
</source>
 +
 
 +
 
 +
 
 +
== FlexContainer update ==
 +
=== Through HTTP binding ===
 +
==== Request ====
 +
{| class="wikitable"
 +
! HTTP method
 +
| PUT
 +
|-
 +
! URL
 +
| http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer <br/>
 +
or <br/>
 +
http://<ip_cse>:<port_cse>/~/in-cse/fcnt-953225660
 +
|-
 +
! Headers
 +
|
 +
{| class="wikitable"
 +
! Name
 +
! Value
 +
! Comments
 +
|-
 +
| X-M2M-Origin
 +
| admin:admin
 +
| Login:password
 +
|}
 +
|-
 +
! Body
 +
|
 +
<pre>
 +
<?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>
 +
 
 +
</pre>
 +
|}
 +
 
 +
An example:
 +
<pre>
 +
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>
 +
 
 +
</pre>
 +
 
 +
==== Response ====
 +
 
 +
{| class="wikitable"
 +
! 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 = last modified time -->
 +
    <lt>20161221T113042</lt>
 +
 +
    <!-- custom Attributes -->
 +
    <myStringCustomAttribute
 +
            type="xs:string">newStringValue</myStringCustomAttribute>
 +
    <myIntegerCustomAttribute
 +
            type="xs:integer">1234567</myIntegerCustomAttribute>
 +
 +
</m2m:fcnt>
 +
|}
 +
 
 +
 
 +
=== Through CSEService OSGi service ===
 +
 
 +
<source lang="java" enclose="div" line>
 +
// prepare FlexContainer object
 +
FlexContainer toBeUpdated = new FlexContainer();
 +
 
 +
CustomAttribute myStringCustomAttribute = new CustomAttribute();
 +
myStringCustomAttribute.setCustomAttributeValue("newStringValue");
 +
myStringCustomAttribute.setCustomAttributeName("myStringCustomAttribute");
 +
myStringCustomAttribute.setCustomAttributeType("xs:string");
 +
toBeUpdated.getCustomAttributes().add(myStringCustomAttribute);
 +
 
 +
CustomAttribute myIntegerCustomAttribute = new CustomAttribute();
 +
myIntegerCustomAttribute.setCustomAttributeName("myIntegerCustomAttribute");
 +
myIntegerCustomAttribute.setCustomAttributeType("xs:integer");
 +
myIntegerCustomAttribute.setCustomAttributeValue("1234567");
 +
toBeUpdated.getCustomAttributes().add(myIntegerCustomAttribute);
 +
 
 +
// prepare request
 +
RequestPrimitive request = new RequestPrimitive();
 +
request.setContent(toBeUpdated);
 +
request.setFrom(“admin:admin”);
 +
request.setTargetId(“/in-cse/in-name/myFlexContainer”);
 +
// targetId & to parameter could also be “/in-cse/fcnt-953225660”
 +
request.setTo(“/in-cse/in-name/myFlexContainer”);
 +
request.setResourceType(ResourceType.FLEXCONTAINER);
 +
request.setRequestContentType(MimeMediaType.OBJ);
 +
request.setReturnContentType(MimeMediaType.OBJ);
 +
request.setOperation(Operation.UPDATE);
 +
 
 +
// execute request
 +
// cseService is an OSGi service retrieved through the OSGi registry
 +
ResponsePrimitive response = cseService.doRequest(request);
 +
 
 +
if (response.getResponseStatusCode().equals(ResponseStatusCode.UPDATED)) {
 +
// OK
 +
FlexContainer updatedFlexContainer = (FlexContainer)
 +
                                              response.getContent();
 +
 
 +
        // use getters of FlexContainer to retrieve FlexContainer fields
 +
 
 +
}
 +
 
 +
</source>
 +
 
 +
 
 +
 
 +
== FlexContainer deletion ==
 +
=== Through HTTP binding ===
 +
==== Request ====
 +
{| class="wikitable"
 +
! HTTP method
 +
| DELETE
 +
|-
 +
! URL
 +
| http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer <br/>
 +
or <br/>
 +
http://<ip_cse>:<port_cse>/~/in-cse/fcnt-953225660
 +
|-
 +
! Headers
 +
|
 +
{| class="wikitable"
 +
! Name
 +
! Value
 +
! Comments
 +
|-
 +
| X-M2M-Origin
 +
| admin:admin
 +
| Login:password
 +
|}
 +
|}
 +
 
 +
An example:
 +
<pre>
 +
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
 +
</pre>
 +
 
 +
==== Response ====
 +
 
 +
{| class="wikitable"
 +
! HTTP response code
 +
| 200 OK
 +
|-
 +
! Response body
 +
| No body
 +
|}
 +
 
 +
=== Through CSEService OSGi service ===
 +
 
 +
<source lang="java" enclose="div" line>
 +
// prepare request
 +
RequestPrimitive request = new RequestPrimitive();
 +
request.setTargetId(“/in-cse/in-name/myFlexContainer”);
 +
// targetId & to parameter could also be “/in-cse/fcnt-953225660”
 +
request.setTo(“/in-cse/in-name/myFlexContainer”);
 +
request.setRequestContentType(MimeMediaType.OBJ);
 +
request.setReturnContentType(MimeMediaType.OBJ);
 +
request.setOperation(Operation.DELETE);
 +
 
 +
// execute request
 +
ResponsePrimitive response = cseService.doRequest(request);
 +
 
 +
// check response
 +
if (response.getResponseStatusCode().equals(ResponseStatusCode.DELETED)) {
 +
// OK
 +
}
 +
</source>
 +
 
 +
== 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:
 +
<source lang="java" enclose="div" line>
 +
// create a flexContainerService
 +
FlexContainerService fcs = new FlexContainerService() {
 +
 
 +
@Override
 +
public void setCustomAttributeValues(List<CustomAttribute> customAttributes,
 +
                      RequestPrimitive requestPrimitive
 +
                    ) throws Om2mException {
 +
        // this method is called when the FlexContainer
 +
                // associated to this FlexContainerService
 +
                // instance is updated.
 +
                // put here the business code
 +
          // that take into account the new customAttribute
 +
                // values
 +
}
 +
 
 +
@Override
 +
public String getFlexContainerLocation() {
 +
  // this method MUST return the resourceId of the
 +
                // attached FlexContainer
 +
return flexContainer.getResourceID();
 +
}
 +
 
 +
@Override
 +
public String getCustomAttributeValue(String customAttributeName) throws Om2mException {
 +
// this method is called by the CSE when it
 +
                // receive a RETRIEVE request for the attached
 +
                // FlexContainer
 +
                // this method has to return the value of the
 +
                // customAttribute specified by
 +
                // customAttributeName argument
 +
return customAttributeValue;
 +
}
 +
 
 +
};
 +
 
 +
// register FlexContainerService as an OSGi service
 +
flexContainerServiceRegistration = bundleContext.registerService(FlexContainerService.class, fcs, null);
 +
</source>

Revision as of 11:23, 18 January 2017

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.6.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=24 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=24
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>24</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>24</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);

Back to the top