diff --git a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapHandler.java b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapHandler.java index 450689ddd8..0985060144 100644 --- a/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapHandler.java +++ b/leshan-server-core/src/main/java/org/eclipse/leshan/server/bootstrap/DefaultBootstrapHandler.java @@ -106,13 +106,17 @@ public BootstrapResponse bootstrap(Identity sender, BootstrapRequest request) { e.execute(new Runnable() { @Override public void run() { - delete(session, cfg); + startBootstrap(session, cfg); } }); return BootstrapResponse.success(); } + protected void startBootstrap(BootstrapSession session, BootstrapConfig cfg) { + delete(session, cfg); + } + protected void delete(final BootstrapSession session, final BootstrapConfig cfg) { final BootstrapDeleteRequest deleteRequest = new BootstrapDeleteRequest(); @@ -234,26 +238,31 @@ public void onError(Exception e) { } }); } else { - final BootstrapFinishRequest finishBootstrapRequest = new BootstrapFinishRequest(); - send(session, finishBootstrapRequest, new ResponseCallback() { + // we are done, send bootstrap finished. + bootstrapFinished(session, cfg); + } + } - @Override - public void onResponse(BootstrapFinishResponse response) { - LOG.trace("Bootstrap Finished {} return code {}", session.getEndpoint(), response.getCode()); - if (response.isSuccess()) { - sessionManager.end(session); - } else { - sessionManager.failed(session, FINISHED_WITH_ERROR, finishBootstrapRequest); - } - } - }, new ErrorCallback() { - @Override - public void onError(Exception e) { - LOG.debug(String.format("Error during bootstrap finished on %s", session.getEndpoint()), e); - sessionManager.failed(session, SEND_FINISH_FAILED, finishBootstrapRequest); + protected void bootstrapFinished(final BootstrapSession session, final BootstrapConfig cfg) { + + final BootstrapFinishRequest finishBootstrapRequest = new BootstrapFinishRequest(); + send(session, finishBootstrapRequest, new ResponseCallback() { + @Override + public void onResponse(BootstrapFinishResponse response) { + LOG.trace("Bootstrap Finished {} return code {}", session.getEndpoint(), response.getCode()); + if (response.isSuccess()) { + sessionManager.end(session); + } else { + sessionManager.failed(session, FINISHED_WITH_ERROR, finishBootstrapRequest); } - }); - } + } + }, new ErrorCallback() { + @Override + public void onError(Exception e) { + LOG.debug(String.format("Error during bootstrap finished on %s", session.getEndpoint()), e); + sessionManager.failed(session, SEND_FINISH_FAILED, finishBootstrapRequest); + } + }); } protected void send(BootstrapSession session, DownlinkRequest request,