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.
Difference between revisions of "OM2M/one/FlexContainers"
(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: | ||
− | + | == 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]] | ||
− | + | 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
Contents
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.
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 |
| ||||||||||||
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
- // 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
- }
FlexContainer retrieving
Through HTTP binding
Request
HTTP method | GET | ||||||
---|---|---|---|---|---|---|---|
URL | http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer or | ||||||
Headers |
|
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
- // 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();
- …
- }
FlexContainer update
Through HTTP binding
Request
HTTP method | PUT | ||||||
---|---|---|---|---|---|---|---|
URL | http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer or | ||||||
Headers |
| ||||||
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
- // 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
- }
FlexContainer deletion
Through HTTP binding
Request
HTTP method | DELETE | ||||||
---|---|---|---|---|---|---|---|
URL | http://<ip_cse>:<port_cse>/~/in-cse/in-name/myFlexContainer or | ||||||
Headers |
|
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
- // 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
- }
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:
- // 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);