OM2M/one/FlexContainers
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.10.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" > <rn>myFlexContainer</rn> <!-- container Definition is mandatory --> <cnd>org.eclipse.om2m.mydef</cnd> <!-- 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:adminContent-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" > <rn>myFlexContainer</rn> <cnd>org.eclipse.om2m.mydef</cnd> </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> <cnd>org.eclipse.om2m.mydef</cnd> < !-- 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>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> <cnd>org.eclipse.om2m.mydef</cnd> <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);