Sending data to the server
Client can send an arbitrary data-object to server using the direct method sendData() - step 1.
Web-server will invoke REST-method /OnDataEvent - step 2. As a result, client will receive status SESSION_STATUS.SEND_DATA_STATUS ACCEPTED - step 4.
Example:
2 | 3 |
---|---|
POST /rest/my_api/OnDataEvent HTTP/1.1 Accept: application/json, application/*+json Content-Type: application/json;charset=UTF-8 User-Agent: Java/1.8.0_111 Host: 192.168.1.101 Connection: keep-alive Content-Length: 218 { "nodeId":"Hw47CFMBEchVOpBMDr29IxjudnJ1sjOY@192.168.1.101", "appKey":"defaultApp", "sessionId":"/192.168.1.102:55839/192.168.1.101:8443", "operationId":"d1999750-fde9-11e6-9f1b-913210792931", "payload":{ "message":"hello" } } | HTTP/1.1 200 OK Date: Tue, 28 Feb 2017 19:12:14 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 Content-Length: 220 Connection: close Content-Type: application/json { "nodeId":"Hw47CFMBEchVOpBMDr29IxjudnJ1sjOY@192.168.1.101", "appKey":"defaultApp", "sessionId":"\/192.168.1.102:55839\/192.168.1.101:8443", "operationId":"d1999750-fde9-11e6-9f1b-913210792931", "payload":{ "message":"hello" } } |
Error handling
To make WCS react to the error, set restOnError: FAIL in the settings of the /OnDataEvent method, in restClientConfig when establishing the connection.
Client can send an arbitrary object using the direct method sendData() - step 1.
Web-server will invoke REST-method /OnDataEvent - step 2. As a result, client will receive status SESSION_STATUS.SEND_DATA_STATUS FAILED - step 4.
Example:
2 | 3 |
---|---|
POST /rest/my_api/OnDataEvent HTTP/1.1 Accept: application/json, application/*+json Content-Type: application/json;charset=UTF-8 User-Agent: Java/1.8.0_111 Host: 192.168.1.101 Connection: keep-alive Content-Length: 218 { "nodeId":"Hw47CFMBEchVOpBMDr29IxjudnJ1sjOY@192.168.1.101", "appKey":"defaultApp", "sessionId":"/192.168.1.102:25789/192.168.1.101:8443", "operationId":"d0149310-fdeb-11e6-9b58-9509528e5d66", "payload":{ "message":"hello" } } | HTTP/1.1 403 Forbidden Date: Tue, 28 Feb 2017 19:26:30 GMT Server: Apache/2.2.15 (CentOS) X-Powered-By: PHP/5.3.3 Content-Length: 0 Connection: close Content-Type: text/html; charset=UTF-8 |
Sending data to connected client
There is a way to send a direct message to a connected client with REST API query http://host:8081/rest-api/data/send
To do this, pass the following JSON object
{ "nodeId":"", "sessionId":"/192.168.1.102:25789/192.168.1.101:8443", "operationId":"", "payload":{ "test":"test" } }
Where sessionId is connected client session identifier that is received on backend while REST hook /connect handling.
In this case, the connected client receives the custom object where you can put any data, for example {"test":"test"} as shown above.
The client receives the SESSION_STATUS.APP_DATA event.