Thanks.
public class FirmwareUpdateObject {
PackageUriResource packageUriRsc = new PackageUriResource();
UpdateResource updateRsc = new UpdateResource();
StateResource stateRsc = new StateResource();
UpdateResultResource updateResultRsc = new UpdateResultResource();
class PackageUriResource extends StringLwM2mResource {
protected void handleWrite(StringLwM2mExchange exchange) {
LOG.info("Starting to download the firmware package from {}", exchange.getRequestPayload());
exchange.respondSuccess();
HttpClient client = new HttpClient();
HttpMethod get = new GetMethod(exchange.getRequestPayload());
client.executeMethod(get);
payload = get.getResponseBody();
if (get.getStatusCode() == 200 && payload.length > 0) {
// TODO store the package
LOG.error("Invalid package file");
updateResultRsc.result = 5; // error result
LOG.error("Could not download the firmware package", e);
class UpdateResource extends StringLwM2mResource {
protected void handleExecute(LwM2mExchange exchange) {
LOG.info("Updating the firmware");
exchange.respond(ExecuteResponse.success());
updateResultRsc.result = 0;
} catch (InterruptedException e) {
updateResultRsc.result = 1;
class StateResource extends IntegerLwM2mResource {
protected void handleRead(final IntegerLwM2mExchange exchange) {
exchange.respondContent(state);
class UpdateResultResource extends IntegerLwM2mResource {
protected void handleRead(final IntegerLwM2mExchange exchange) {
exchange.respondContent(result);