use of org.eclipse.leshan.core.request.BootstrapDeleteRequest in project leshan by eclipse.
the class BootstrapHandler method sendDelete.
private void sendDelete(final BootstrapSession session, final BootstrapConfig cfg) {
final BootstrapDeleteRequest deleteRequest = new BootstrapDeleteRequest();
send(session, deleteRequest, new ResponseCallback<BootstrapDeleteResponse>() {
@Override
public void onResponse(BootstrapDeleteResponse response) {
LOG.trace("Bootstrap delete {} return code {}", session.getEndpoint(), response.getCode());
List<Integer> toSend = new ArrayList<>(cfg.security.keySet());
sendBootstrap(session, cfg, toSend);
}
}, new ErrorCallback() {
@Override
public void onError(Exception e) {
LOG.debug(String.format("Error during bootstrap delete '/' on %s", session.getEndpoint()), e);
sessionManager.failed(session, DELETE_FAILED, deleteRequest);
}
});
}
use of org.eclipse.leshan.core.request.BootstrapDeleteRequest in project leshan by eclipse.
the class BootstrapHandler method delete.
public synchronized BootstrapDeleteResponse delete(ServerIdentity identity, BootstrapDeleteRequest deleteRequest) {
if (bootstrapping) {
// Only if the request is from the bootstrap server
if (!isBootstrapServer(identity)) {
return BootstrapDeleteResponse.badRequest("not from a bootstrap server");
}
// The spec say that delete on "/" should delete all the existing Object Instances - except LWM2M
// Bootstrap Server Account, (see 5.2.5.2 Bootstrap Delete)
// For now we only remove security and server object.
// Delete all device management server
LwM2mObjectEnabler serverObject = objects.get(SERVER);
for (Integer instanceId : serverObject.getAvailableInstanceIds()) {
serverObject.delete(identity, new DeleteRequest(SERVER, instanceId));
}
// Delete all security instance (except bootstrap one)
// TODO do not delete bootstrap server (see 5.2.5.2 Bootstrap Delete)
LwM2mObjectEnabler securityObject = objects.get(SECURITY);
for (Integer instanceId : securityObject.getAvailableInstanceIds()) {
securityObject.delete(identity, new DeleteRequest(SECURITY, instanceId));
}
return BootstrapDeleteResponse.success();
} else {
return BootstrapDeleteResponse.badRequest("no pending bootstrap session");
}
}
use of org.eclipse.leshan.core.request.BootstrapDeleteRequest in project leshan by eclipse.
the class RootResource method handleDELETE.
@Override
public void handleDELETE(CoapExchange exchange) {
if (!StringUtils.isEmpty(exchange.getRequestOptions().getUriPathString())) {
exchange.respond(ResponseCode.METHOD_NOT_ALLOWED);
return;
}
ServerIdentity identity = ResourceUtil.extractServerIdentity(exchange, bootstrapHandler);
BootstrapDeleteResponse response = bootstrapHandler.delete(identity, new BootstrapDeleteRequest());
exchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage());
}
Aggregations