use of org.eclipse.californium.core.coap.Request in project leshan by eclipse.
the class CoapRequestBuilderTest method build_read_request_with_root_path.
@Test
public void build_read_request_with_root_path() throws Exception {
Registration reg = newRegistration("/");
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
ReadRequest request = new ReadRequest(3);
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals("coap://127.0.0.1:12354/3", coapRequest.getURI());
}
use of org.eclipse.californium.core.coap.Request in project leshan by eclipse.
the class CoapRequestBuilderTest method build_read_request_with_non_default_object_path.
@Test
public void build_read_request_with_non_default_object_path() throws Exception {
Registration reg = newRegistration("/lwm2m");
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
ReadRequest request = new ReadRequest(3, 0, 1);
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals("coap://127.0.0.1:12354/lwm2m/3/0/1", coapRequest.getURI());
}
use of org.eclipse.californium.core.coap.Request in project leshan by eclipse.
the class CoapRequestBuilderTest method build_execute_request.
@Test
public void build_execute_request() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
ExecuteRequest request = new ExecuteRequest(3, 0, 12, "params");
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.POST, coapRequest.getCode());
assertEquals("127.0.0.1", coapRequest.getDestinationContext().getPeerAddress().getAddress().getHostAddress());
assertEquals(12354, coapRequest.getDestinationContext().getPeerAddress().getPort());
assertEquals("coap://127.0.0.1:12354/3/0/12", coapRequest.getURI());
assertEquals("params", coapRequest.getPayloadString());
}
use of org.eclipse.californium.core.coap.Request in project leshan by eclipse.
the class CoapRequestBuilderTest method build_write_request_replace.
@Test
public void build_write_request_replace() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
WriteRequest request = new WriteRequest(3, 0, 14, "value");
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.PUT, coapRequest.getCode());
}
use of org.eclipse.californium.core.coap.Request in project leshan by eclipse.
the class ObservationSerDes method deserialize.
public static Observation deserialize(byte[] data) {
JsonObject v = (JsonObject) Json.parse(new String(data));
EndpointContext endpointContext = EndpointContextSerDes.deserialize(v.get("peer").asObject());
byte[] req = Hex.decodeHex(v.getString("request", null).toCharArray());
RawData rawData = RawData.outbound(req, endpointContext, null, false);
Request request = (Request) parser.parseMessage(rawData);
request.setDestinationContext(endpointContext);
JsonValue ctxValue = v.get("context");
if (ctxValue != null) {
Map<String, String> context = new HashMap<>();
JsonObject ctxObject = (JsonObject) ctxValue;
for (String name : ctxObject.names()) {
context.put(name, ctxObject.getString(name, null));
}
request.setUserContext(context);
}
return new Observation(request, endpointContext);
}
Aggregations