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);
}
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);
}
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);
}
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;
}
Aggregations