Home » Eclipse Projects » OM2M » JSON content "con" attribute in ContentInstance
JSON content "con" attribute in ContentInstance [message #1787232] |
Tue, 22 May 2018 13:44 |
Arnaud Moncade Messages: 4 Registered: May 2018 |
Junior Member |
|
|
Hello,
I created an AE named SAMPLE_AE, with a DATA container in it. Then I want to send a JSON contentInstance under the DATA container. So I post an HTTP Request with the following content:
{
"m2m:cin": {
"cnf": "application/json",
"con": {
"appId": "SAMPLE_AE",
"category": "sample_category",
"value": "1"
}
}
}
But here is the response I get :
Status : 201 created
{
"m2m:cin": {
"rn": "cin_490476127",
"ty": 4,
"ri": "/mn-cse/cin-490476127",
"pi": "/mn-cse/cnt-644912348",
"ct": "20180522T133731",
"lt": "20180522T133731",
"st": 0,
"cnf": "application/json",
"cs": 0,
"con": ""
}
}
The JSON content is ignored. It works only if I set a single string (e.g "con":"1"). I found a workaround using oBIX :
{
"m2m:cin": {
"cnf": "application/obix:0",
"con": "<obj>
<str name=\"appId\" val=\"SAMPLE_AE\"/>
<str name=\"category\" val=\"sample_category\"/>
<int name=\"value\" val=\"1\"/>
</obj>"
}
}
This works but is less easy to integrate in my solution.
Am I doing anything wrong?
|
|
| |
Re: JSON content "con" attribute in ContentInstance [message #1787292 is a reply to message #1787271] |
Wed, 23 May 2018 08:58 |
Arnaud Moncade Messages: 4 Registered: May 2018 |
Junior Member |
|
|
Thanks for your answer. I just tried that and I get a 400 - Bad Request : Error in provided content error.
Here is the log from the MN-CSE in this case :
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Content type headers: application/json;ty=4
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Header value: application/json
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Header value: ty=4
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Accept header: application/json
[INFO] - org.eclipse.om2m.core.router.Router
Received request in Router: RequestPrimitive [operation=1,
to=/mn-cse/mn-name/SAMPLE_AE/DATA,
from=admin:admin,
resourceType=4,
content= {
"m2m:cin": {
"cnf": "application/json",
"con": {
\"appId\": \"SAMPLE_AE\",
\"category\": \"sample_category\",
\"value\": \"1\"
}
}
}
,
filterCriteria=org.eclipse.om2m.commons.resource.FilterCriteria@f4d5de,
returnContentType=application/json,
requestContentType=application/json,
queryStrings={}]
[INFO] - org.eclipse.om2m.core.router.Router
Request handling in the current CSE: /mn-cse/mn-name/SAMPLE_AE/DATA
[INFO] - org.eclipse.om2m.core.router.Router
ResourceController to be used [ContentInstanceController]
line 5:6 no viable alternative at character '\'
line 11:0 mismatched character '<EOF>' expecting '"'
line 0:-1 mismatched input '<EOF>' expecting '}'
[ERROR] - org.eclipse.om2m.datamapping.jaxb.Mapper
JAXB unmarshalling error!
javax.xml.bind.UnmarshalException
- with linked exception:
[Exception [EclipseLink-25004] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: An error occurred unmarshalling the document
|
|
|
Re: JSON content "con" attribute in ContentInstance [message #1814444 is a reply to message #1787292] |
Wed, 11 September 2019 13:52 |
Kenshi Kamiya Messages: 2 Registered: September 2019 Location: Japan |
Junior Member |
|
|
I have the same issue.
Instead of oBIX, I'd like POST nested JSON contents in "con" field to handle easily with Javascript program for AE.
Any solution?
Currently I'm posting data with Postman for testing purpose.
The following is header and body of HTTP POST message to CSE.
<Request>
POST /~/in-cse/in-name/sensor_ae/environment HTTP/1.1
X-M2M-Origin: CAE941252566
X-M2M-RI: 20000004
Content-Type: application/json;ty=4
Accept: application/json
User-Agent: PostmanRuntime/7.16.3
Cache-Control: no-cache
Postman-Token: f798ef06-bda0-47a6-9674-4248a68202e9
Host: 192.168.0.242:8080
Accept-Encoding: gzip, deflate
Content-Length: 190
Connection: keep-alive
{
"m2m:cin": {
"cnf": "application/json",
"con": {
"appId": "SAMPLE_AE",
"category": "sample_category",
"value": "1"
}
}
}
<Response>
HTTP/1.1 201 Created
Content-Location: /in-cse/cin-509864000
X-M2M-RI: 20000004
X-M2M-Origin: /in-cse
X-M2M-RSC: 2001
Content-Type: application/json;charset=UTF-8
Content-Length: 294
Server: Jetty(8.1.16.v20140903)
{
"m2m:cin" : {
"rn" : "cin_509864000",
"ty" : 4,
"ri" : "/in-cse/cin-509864000",
"pi" : "/in-cse/cnt-840362991",
"ct" : "20190911T224323",
"lt" : "20190911T224323",
"st" : 0,
"cnf" : "application/json",
"cs" : 0,
"con" : ""
}
}
Looking at in-cse log, "con" : <Object> was received by RestHttp, but ignored at RestHttpClient.
----------------------------------------------------------------------------------------------
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Built RequestPrimitive: RequestPrimitive [to=/in-cse/in-name/sensor_ae/environment,
content={
"m2m:cin": {
"cnf": "application/json",
"con": {
"appId": "SAMPLE_AE",
"category": "sample_category",
"value": "1"
}
}
}
,
filterCriteria=org.eclipse.om2m.commons.resource.FilterCriteria@ef4e5e6,
]
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Content type headers: application/json;ty=4
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Header value: application/json
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Header value: ty=4
[INFO] - org.eclipse.om2m.binding.http.RestHttpServlet
Accept header: application/json
[INFO] - org.eclipse.om2m.core.router.Router
Received request in Router: RequestPrimitive [operation=1,
to=/in-cse/in-name/sensor_ae/environment,
from=CAE941252566,
requestIdentifier=20000004,
resourceType=4,
content={
"m2m:cin": {
"cnf": "application/json",
"con": {
"appId": "SAMPLE_AE",
"category": "sample_category",
"value": "1"
}
}
}
,
filterCriteria=org.eclipse.om2m.commons.resource.FilterCriteria@ef4e5e6,
returnContentType=application/json,
requestContentType=application/json,
queryStrings={}]
[INFO] - org.eclipse.om2m.core.router.Router
Request handling in the current CSE: /in-cse/in-name/sensor_ae/environment
[INFO] - org.eclipse.om2m.core.router.Router
ResourceController to be used [ContentInstanceController]
[INFO] - org.eclipse.om2m.core.controller.Controller
Deleting oldest content instance due to container size limit
[INFO] - org.eclipse.om2m.core.notifier.Notifier
Sending notify request to: /in-cse/CAE414512124
[INFO] - org.eclipse.om2m.core.notifier.Notifier
Sending notify request...
[INFO] - org.eclipse.om2m.core.router.Router
Received request in Router: RequestPrimitive [operation=5,
to=/in-cse/CAE414512124,
from=admin:admin,
content={
"m2m:sgn" : {
"m2m:nev" : {
"m2m:rep" : {
"m2m:cin" : {
"rn" : "cin_509864000",
"ty" : 4,
"ri" : "/in-cse/cin-509864000",
"pi" : "/in-cse/cnt-840362991",
"ct" : "20190911T224323",
"lt" : "20190911T224323",
"st" : 0,
"cnf" : "application/json",
"cs" : 0,
"con" : ""
}
},
"m2m:rss" : 1
},
"m2m:sud" : false,
"m2m:sur" : "/in-cse/sub-947316430"
}
},
requestContentType=application/json,
]
[INFO] - org.eclipse.om2m.core.router.Router
No Accept parameter set, setting to default: application/xml
[INFO] - org.eclipse.om2m.core.router.Router
Request handling in the current CSE: /in-cse/CAE414512124
[INFO] - org.eclipse.om2m.core.comm.RestClient
the requestIndication RC: RequestPrimitive [operation=5,
to=http://192.168.0.242:8000/Environment,
from=admin:admin,
content={
"m2m:sgn" : {
"m2m:nev" : {
"m2m:rep" : {
"m2m:cin" : {
"rn" : "cin_509864000",
"ty" : 4,
"ri" : "/in-cse/cin-509864000",
"pi" : "/in-cse/cnt-840362991",
"ct" : "20190911T224323",
"lt" : "20190911T224323",
"st" : 0,
"cnf" : "application/json",
"cs" : 0,
"con" : ""
}
},
"m2m:rss" : 1
},
"m2m:sud" : false,
"m2m:sur" : "/in-cse/sub-947316430"
}
},
returnContentType=application/xml,
requestContentType=application/json,
]
[INFO] - org.eclipse.om2m.binding.http.RestHttpClient
Sending request: RequestPrimitive [operation=5,
to=http://192.168.0.242:8000/Environment,
from=admin:admin,
content={
"m2m:sgn" : {
"m2m:nev" : {
"m2m:rep" : {
"m2m:cin" : {
"rn" : "cin_509864000",
"ty" : 4,
"ri" : "/in-cse/cin-509864000",
"pi" : "/in-cse/cnt-840362991",
"ct" : "20190911T224323",
"lt" : "20190911T224323",
"st" : 0,
"cnf" : "application/json",
"cs" : 0,
"con" : ""
}
},
"m2m:rss" : 1
},
"m2m:sud" : false,
"m2m:sur" : "/in-cse/sub-947316430"
}
},
returnContentType=application/xml,
requestContentType=application/json,
]
[INFO] - org.eclipse.om2m.core.controller.Controller
Clear and close transaction
[INFO] - org.eclipse.om2m.core.router.Router
Response in Router= ResponsePrimitive [
responseStatusCode=2001
requestIdentifier=20000004
to=CAE941252566
from=/in-cse
location=/in-cse/cin-509864000,
contentType=application/json,
content (Only first 1000 caracters)=
{
"m2m:cin" : {
"rn" : "cin_509864000",
"ty" : 4,
"ri" : "/in-cse/cin-509864000",
"pi" : "/in-cse/cnt-840362991",
"ct" : "20190911T224323",
"lt" : "20190911T224323",
"st" : 0,
"cnf" : "application/json",
"cs" : 0,
"con" : ""
}
}
]
|
|
|
Re: JSON content "con" attribute in ContentInstance [message #1815566 is a reply to message #1814444] |
Sat, 05 October 2019 08:07 |
Kenshi Kamiya Messages: 2 Registered: September 2019 Location: Japan |
Junior Member |
|
|
Looking at previous discussion, I understood that it is necessary to parentheses JSON objet by "" like:
{
"m2m:cin": {
"cnf": "application/text",
"con": "{\"Location\": \"Outside\", \"RSSI\": -53, \"TemperatureC\": 30.34, \"Humidity\": 47.42, \"PressureHpa\": 1001.36, \"CreateDate\": \"2019-10-05T07:59:58Z\"}"
}
}
OM2M accepted this container instance as a string.
[2019-10-05 16:59:54,732 INFO] - org.eclipse.om2m.binding.http.RestHttpClient
Sending request: RequestPrimitive [operation=5,
to=http://192.168.0.242:8000/Environment,
from=admin:admin,
content={
"m2m:sgn" : {
"m2m:nev" : {
"m2m:rep" : {
"m2m:cin" : {
"rn" : "cin_727923535",
"ty" : 4,
"ri" : "/in-cse/cin-727923535",
"pi" : "/in-cse/cnt-813712573",
"ct" : "20191005T165954",
"lt" : "20191005T165954",
"st" : 0,
"cnf" : "application/text",
"cs" : 140,
"con" : "{\"Location\": \"Outside\", \"RSSI\": -53, \"TemperatureC\": 30.34, \"Humidity\": 47.42, \"PressureHpa\": 1001.36, \"CreateDate\": \"2019-10-05T07:59:58Z\"}"
}
},
"m2m:rss" : 1
},
"m2m:sud" : false,
"m2m:sur" : "/in-cse/sub-242671093"
}
},
returnContentType=application/xml,
requestContentType=application/json,
]
[Updated on: Sat, 05 October 2019 08:35] Report message to a moderator
|
|
| |
Goto Forum:
Current Time: Sun Dec 01 20:35:20 GMT 2024
Powered by FUDForum. Page generated in 0.03372 seconds
|