Search in sources :

Example 16 with Response

use of org.eclipse.californium.core.coap.Response in project thingsboard by thingsboard.

the class JsonCoapAdaptor method convertToServerRpcResponse.

private Response convertToServerRpcResponse(SessionContext ctx, ToServerRpcResponseMsg msg) {
    if (msg.isSuccess()) {
        Response response = new Response(ResponseCode.CONTENT);
        JsonElement result = JsonConverter.toJson(msg);
        response.setPayload(result.toString());
        return response;
    } else {
        return convertError(Optional.of(new RuntimeException("Server RPC response is empty!")));
    }
}
Also used : Response(org.eclipse.californium.core.coap.Response) JsonElement(com.google.gson.JsonElement)

Aggregations

Response (org.eclipse.californium.core.coap.Response)16 LwM2mResponse (org.eclipse.leshan.core.response.LwM2mResponse)11 Request (org.eclipse.californium.core.coap.Request)7 LwM2mModel (org.eclipse.leshan.core.model.LwM2mModel)6 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)6 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)6 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)5 Test (org.junit.Test)5 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)4 DefaultLwM2mValueConverter (org.eclipse.leshan.core.node.codec.DefaultLwM2mValueConverter)4 Observation (org.eclipse.leshan.core.observation.Observation)4 DownlinkRequest (org.eclipse.leshan.core.request.DownlinkRequest)4 ArrayList (java.util.ArrayList)3 MessageObserver (org.eclipse.californium.core.coap.MessageObserver)3 AsyncRequestObserver (org.eclipse.leshan.core.californium.AsyncRequestObserver)3 SyncRequestObserver (org.eclipse.leshan.core.californium.SyncRequestObserver)3 TimestampedLwM2mNode (org.eclipse.leshan.core.node.TimestampedLwM2mNode)3 Endpoint (org.eclipse.californium.core.network.Endpoint)2 AddressEndpointContext (org.eclipse.californium.elements.AddressEndpointContext)2 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)2