Search in sources :

Example 21 with Request

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());
}
Also used : Registration(org.eclipse.leshan.server.registration.Registration) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 22 with Request

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());
}
Also used : Registration(org.eclipse.leshan.server.registration.Registration) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 23 with Request

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());
}
Also used : ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) Registration(org.eclipse.leshan.server.registration.Registration) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) Test(org.junit.Test)

Example 24 with Request

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());
}
Also used : Registration(org.eclipse.leshan.server.registration.Registration) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) Test(org.junit.Test)

Example 25 with Request

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);
}
Also used : RawData(org.eclipse.californium.elements.RawData) EndpointContext(org.eclipse.californium.elements.EndpointContext) HashMap(java.util.HashMap) Request(org.eclipse.californium.core.coap.Request) JsonValue(com.eclipsesource.json.JsonValue) Observation(org.eclipse.californium.core.observe.Observation) JsonObject(com.eclipsesource.json.JsonObject)

Aggregations

Request (org.eclipse.californium.core.coap.Request)26 Registration (org.eclipse.leshan.server.registration.Registration)14 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)13 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)13 Test (org.junit.Test)13 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)12 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)12 DiscoverRequest (org.eclipse.leshan.core.request.DiscoverRequest)12 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)12 WriteAttributesRequest (org.eclipse.leshan.core.request.WriteAttributesRequest)12 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)12 Response (org.eclipse.californium.core.coap.Response)7 LwM2mResponse (org.eclipse.leshan.core.response.LwM2mResponse)6 DownlinkRequest (org.eclipse.leshan.core.request.DownlinkRequest)5 MessageObserver (org.eclipse.californium.core.coap.MessageObserver)3 AsyncRequestObserver (org.eclipse.leshan.core.californium.AsyncRequestObserver)3 SyncRequestObserver (org.eclipse.leshan.core.californium.SyncRequestObserver)3 DeregisterRequest (org.eclipse.leshan.core.request.DeregisterRequest)3 RegisterRequest (org.eclipse.leshan.core.request.RegisterRequest)3 UplinkRequest (org.eclipse.leshan.core.request.UplinkRequest)3