Skip to content

Commit

Permalink
Remove CoapClient creation, use coapServer.clientService() instead
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jan 26, 2023
1 parent 7dd76f0 commit 556c46f
Showing 1 changed file with 2 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,6 @@
import org.eclipse.leshan.server.request.LowerLayerConfig;
import org.eclipse.leshan.transport.javacoap.observation.ObservationUtil;

import com.mbed.coap.client.CoapClient;
import com.mbed.coap.client.CoapClientBuilder;
import com.mbed.coap.client.ObservationConsumer;
import com.mbed.coap.packet.CoapRequest;
import com.mbed.coap.packet.CoapResponse;
Expand Down Expand Up @@ -132,11 +130,8 @@ protected <T extends LwM2mResponse> CompletableFuture<T> sendLwM2mRequest(Client
// Create Coap Request to send from LWM2M Request
CoapRequest coapRequest = translator.createCoapRequest(destination, lwm2mRequest, toolbox);

// Create a Coap Client to send request
CoapClient coapClient = CoapClientBuilder.clientFor(destination.getIdentity().getPeerAddress(), coapServer);

// Send CoAP Request
CompletableFuture<CoapResponse> coapResponseFuture = coapClient.send(coapRequest);
CompletableFuture<CoapResponse> coapResponseFuture = coapServer.clientService().apply(coapRequest);

// On response, create LWM2M Response from CoAP response
CompletableFuture<T> lwm2mResponseFuture = coapResponseFuture.thenApply(coapResponse -> translator
Expand All @@ -156,11 +151,8 @@ protected <T extends LwM2mResponse> CompletableFuture<T> sendObserveRequest(Clie
Opaque token = translator.getTokenGenerator().createToken();
final CoapRequest hackedCoapRequest = coapRequest.token(token);

// Create a Coap Client to send request
CoapClient coapClient = CoapClientBuilder.clientFor(destination.getIdentity().getPeerAddress(), coapServer);

// Send CoAP Request
CompletableFuture<CoapResponse> coapResponseFuture = coapClient.send(hackedCoapRequest);
CompletableFuture<CoapResponse> coapResponseFuture = coapServer.clientService().apply(hackedCoapRequest);

// Handle Notifications
// --------------------
Expand Down

0 comments on commit 556c46f

Please sign in to comment.