public synchronized SendableResponse<BootstrapFinishResponse> finished(ServerIdentity identity, BootstrapFinishRequest finishedRequest) { if (bootstrapping) { // only if the request is from the bootstrap server if (!isBootstrapServer(identity)) { return new SendableResponse<>(BootstrapFinishResponse.badRequest("not from a bootstrap server")); } // TODO delete bootstrap server (see 5.2.5.2 Bootstrap Delete) Runnable whenSent = new Runnable() { @Override public void run() { bootstrappingLatch.countDown(); } }; return new SendableResponse<>(BootstrapFinishResponse.success(), whenSent); } else { return new SendableResponse<>(BootstrapFinishResponse.badRequest("no pending bootstrap session")); } }
@Override public void onAcknowledgement() { // we wait the response is acknowledged. // TODO should we modify SendableResponse by adding an acknowledged method ? sendableResponse.sent(); } });
final SendableResponse<RegisterResponse> sendableResponse = registrationHandler.register(sender, registerRequest, serverEndpoint); RegisterResponse response = sendableResponse.getResponse(); exchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage()); sendableResponse.sent();
Response coapResponse = new Response(toCoapResponseCode(sendableResponse.getResponse().getCode())); if (sendableResponse.getResponse().getCode().isError()) { coapResponse.setPayload(sendableResponse.getResponse().getErrorMessage()); coapResponse.getOptions().setContentFormat(MediaTypeRegistry.TEXT_PLAIN);
UpdateResponse updateResponse = sendableResponse.getResponse(); exchange.respond(toCoapResponseCode(updateResponse.getCode())); sendableResponse.sent();
private void handleDeregister(CoapExchange exchange, String registrationId) { // Get identity Identity sender = extractIdentity(exchange.advanced().getRequest().getSourceContext()); // Create request DeregisterRequest deregisterRequest = new DeregisterRequest(registrationId); // Handle request final SendableResponse<DeregisterResponse> sendableResponse = registrationHandler.deregister(sender, deregisterRequest); DeregisterResponse deregisterResponse = sendableResponse.getResponse(); // Create CoAP Response from LwM2m request if (deregisterResponse.getCode().isError()) { exchange.respond(toCoapResponseCode(deregisterResponse.getCode()), deregisterResponse.getErrorMessage()); } else { exchange.respond(toCoapResponseCode(deregisterResponse.getCode())); } sendableResponse.sent(); }
public SendableResponse<DeregisterResponse> deregister(Identity sender, DeregisterRequest deregisterRequest) { // We must check if the client is using the right identity. Registration registration = registrationService.getById(deregisterRequest.getRegistrationId()); if (registration == null) { return new SendableResponse<>(DeregisterResponse.notFound()); } if (authorizer.isAuthorized(deregisterRequest, registration, sender) == null) { // TODO replace by Forbidden if https://github.com/OpenMobileAlliance/OMA_LwM2M_for_Developers/issues/181 is // closed. return new SendableResponse<>(DeregisterResponse.badRequest("forbidden")); } final Deregistration deregistration = registrationService.getStore() .removeRegistration(deregisterRequest.getRegistrationId()); if (deregistration != null) { LOG.debug("Deregistered client: {}", deregistration.getRegistration()); // Create callback to notify new de-registration Runnable whenSent = new Runnable() { @Override public void run() { registrationService.fireUnregistered(deregistration.getRegistration(), deregistration.getObservations(), null); }; }; return new SendableResponse<>(DeregisterResponse.success(), whenSent); } else { LOG.debug("Invalid deregistration : registration {} not found", registration.getId()); return new SendableResponse<>(DeregisterResponse.notFound()); } }
return new SendableResponse<>(UpdateResponse.notFound()); return new SendableResponse<>(UpdateResponse.badRequest("forbidden")); if (updatedRegistration == null) { LOG.debug("Invalid update: registration {} not found", registration.getId()); return new SendableResponse<>(UpdateResponse.notFound()); } else { LOG.debug("Updated registration {} by {}", updatedRegistration, update); }; }; return new SendableResponse<>(UpdateResponse.success(), whenSent);
return new SendableResponse<>(RegisterResponse.forbidden(null)); return new SendableResponse<>(RegisterResponse.success(registration.getId()), whenSent);