Search in sources :

Example 1 with BootstrapDeleteRequest

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);
        }
    });
}
Also used : BootstrapDeleteRequest(org.eclipse.leshan.core.request.BootstrapDeleteRequest) BootstrapDeleteResponse(org.eclipse.leshan.core.response.BootstrapDeleteResponse) ErrorCallback(org.eclipse.leshan.core.response.ErrorCallback) ArrayList(java.util.ArrayList) List(java.util.List)

Example 2 with BootstrapDeleteRequest

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");
    }
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) BootstrapDeleteRequest(org.eclipse.leshan.core.request.BootstrapDeleteRequest)

Example 3 with BootstrapDeleteRequest

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());
}
Also used : BootstrapDeleteRequest(org.eclipse.leshan.core.request.BootstrapDeleteRequest) BootstrapDeleteResponse(org.eclipse.leshan.core.response.BootstrapDeleteResponse) ServerIdentity(org.eclipse.leshan.client.request.ServerIdentity)

Aggregations

BootstrapDeleteRequest (org.eclipse.leshan.core.request.BootstrapDeleteRequest)3 BootstrapDeleteResponse (org.eclipse.leshan.core.response.BootstrapDeleteResponse)2 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ServerIdentity (org.eclipse.leshan.client.request.ServerIdentity)1 LwM2mObjectEnabler (org.eclipse.leshan.client.resource.LwM2mObjectEnabler)1 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)1 ErrorCallback (org.eclipse.leshan.core.response.ErrorCallback)1