Search in sources :

Example 1 with ResponseCode

use of org.eclipse.californium.core.coap.CoAP.ResponseCode in project leshan by eclipse.

the class ResponseCodeUtilTest method unknown_lwm2m_code_to_unknown_coap_code.

@Test
public void unknown_lwm2m_code_to_unknown_coap_code() {
    // californium behavior is not really consistent
    // for success : code value is lost but we know we use an unknown code
    ResponseCode coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(206));
    Assert.assertEquals(ResponseCode._UNKNOWN_SUCCESS_CODE, coapResponseCode);
    // for client error,: unknown code is replace by BAD REQUEST ...
    coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(425));
    Assert.assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode);
    // for server error : unknown code is replace by INTERNAL SERVER ERROR ...
    coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(509));
    Assert.assertEquals(ResponseCode.INTERNAL_SERVER_ERROR, coapResponseCode);
}
Also used : ResponseCode(org.eclipse.californium.core.coap.CoAP.ResponseCode) Test(org.junit.Test)

Example 2 with ResponseCode

use of org.eclipse.californium.core.coap.CoAP.ResponseCode in project leshan by eclipse.

the class ResponseCodeUtilTest method known_lwm2m_code_to_known_coap_code.

@Test
public void known_lwm2m_code_to_known_coap_code() {
    ResponseCode coapResponseCode = ResponseCodeUtil.toCoapResponseCode(org.eclipse.leshan.ResponseCode.BAD_REQUEST);
    Assert.assertEquals(ResponseCode.BAD_REQUEST, coapResponseCode);
}
Also used : ResponseCode(org.eclipse.californium.core.coap.CoAP.ResponseCode) Test(org.junit.Test)

Example 3 with ResponseCode

use of org.eclipse.californium.core.coap.CoAP.ResponseCode in project leshan by eclipse.

the class ResponseCodeUtilTest method unknown_lwm2m_code_to_known_coap_code.

@Test
public void unknown_lwm2m_code_to_known_coap_code() {
    ResponseCode coapResponseCode = ResponseCodeUtil.toCoapResponseCode(new org.eclipse.leshan.ResponseCode(503));
    Assert.assertEquals(ResponseCode.SERVICE_UNAVAILABLE, coapResponseCode);
}
Also used : ResponseCode(org.eclipse.californium.core.coap.CoAP.ResponseCode) Test(org.junit.Test)

Example 4 with ResponseCode

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

the class JsonCoapAdaptor method convertToRuleEngineErrorResponse.

private Response convertToRuleEngineErrorResponse(CoapSessionCtx ctx, RuleEngineErrorMsg msg) {
    ResponseCode status = ResponseCode.INTERNAL_SERVER_ERROR;
    switch(msg.getError()) {
        case PLUGIN_TIMEOUT:
            status = ResponseCode.GATEWAY_TIMEOUT;
            break;
        default:
            if (msg.getInMsgType() == MsgType.TO_SERVER_RPC_REQUEST) {
                status = ResponseCode.BAD_REQUEST;
            }
            break;
    }
    Response response = new Response(status);
    response.setPayload(JsonConverter.toErrorJson(msg.getErrorMsg()).toString());
    return response;
}
Also used : Response(org.eclipse.californium.core.coap.Response) ResponseCode(org.eclipse.californium.core.coap.CoAP.ResponseCode)

Aggregations

ResponseCode (org.eclipse.californium.core.coap.CoAP.ResponseCode)4 Test (org.junit.Test)3 Response (org.eclipse.californium.core.coap.Response)1