@Override public final String toString() { return String.format("BootstrapDeleteRequest [%s]", getPath()); }
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); } }); }
/** * Creates a request for deleting object instances implemented by a client. (except the LwM2M Bootstrap-Server * Account and the Instance of the Device Object) * * @param path the path (could be a root path, an object path or an object instance path) * @exception InvalidRequestException if the path is not valid. */ public BootstrapDeleteRequest(String path) throws InvalidRequestException { this(newPath(path)); }
@Override public BootstrapDeleteResponse doDelete(BootstrapDeleteRequest request) { if (request.getPath().isRoot() || request.getPath().isObject()) { if (id == LwM2mId.SECURITY) { return BootstrapDeleteResponse.success(); } else if (request.getPath().isObjectInstance()) { if (id == LwM2mId.SECURITY) { LwM2mInstanceEnabler instance = instances.get(request.getPath().getObjectInstanceId()); if (ServersInfoExtractor.isBootstrapServer(instance)) { return BootstrapDeleteResponse.badRequest("bootstrap server can not be deleted"); if (null != instances.remove(request.getPath().getObjectInstanceId())) { return BootstrapDeleteResponse.success(); } else { return BootstrapDeleteResponse.badRequest(String.format("Instance %s not found", request.getPath())); return BootstrapDeleteResponse.badRequest(String.format("unexcepted path %s", request.getPath()));
@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()); } }
@Override public void visit(BootstrapDeleteRequest request) { coapRequest = Request.newDelete(); coapRequest.setConfirmable(true); EndpointContext context = EndpointContextUtil.extractContext(destination); coapRequest.setDestinationContext(context); setTarget(coapRequest, request.getPath()); }
@Override public void handleDELETE(CoapExchange coapExchange) { // Manage Delete Request String URI = coapExchange.getRequestOptions().getUriPathString(); ServerIdentity identity = extractServerIdentity(coapExchange, bootstrapHandler); if (identity.isLwm2mBootstrapServer()) { BootstrapDeleteResponse response = nodeEnabler.delete(identity, new BootstrapDeleteRequest(URI)); if (response.getCode().isError()) { coapExchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage()); } else { coapExchange.respond(toCoapResponseCode(response.getCode())); } } else { DeleteResponse response = nodeEnabler.delete(identity, new DeleteRequest(URI)); if (response.getCode().isError()) { coapExchange.respond(toCoapResponseCode(response.getCode()), response.getErrorMessage()); } else { coapExchange.respond(toCoapResponseCode(response.getCode())); } } }