com.ibm.internal.iotf.devicemgmt.handler.CancelRequestHandler Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of watson-iot Show documentation
Show all versions of watson-iot Show documentation
IBM Watson IoT client library to simplify device/gateway/application interactions with the IoT Platform
The newest version!
/**
*****************************************************************************
Copyright (c) 2017 IBM Corporation and other Contributors.
All rights reserved. This program and the accompanying materials
are made available under the terms of the Eclipse Public License v1.0
which accompanies this distribution, and is available at
http://www.eclipse.org/legal/epl-v10.html
Contributors:
Mike Tran - Initial Contribution
Sathiskumar Palaniappan - Added resource model
*****************************************************************************
*
*/
package com.ibm.internal.iotf.devicemgmt.handler;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import com.google.gson.JsonPrimitive;
import com.ibm.internal.iotf.devicemgmt.ManagedClient;
import com.ibm.internal.iotf.devicemgmt.DMServerTopic;
import com.ibm.internal.iotf.devicemgmt.ResponseCode;
/**
* Request handler for MMqttClient.SERVER_TOPIC_CANCEL
*
Expected request message format
*
*
* {
* "d": {
* "data": [
* {
* "field": "mgmt.firmware"
* }
* ]
* }
* }
*
*/
public class CancelRequestHandler extends DMRequestHandler {
public CancelRequestHandler(ManagedClient dmClient) {
setDMClient(dmClient);
}
/**
* This method handles the cancel request messages from IBM Watson IoT Platform
*/
@Override
protected void handleRequest(JsonObject jsonRequest, String topic) {
JsonArray fields;
JsonObject d = (JsonObject)jsonRequest.get("d");
if (d != null) {
fields = (JsonArray)d.get("data");
if (fields != null) {
ObserveRequestHandler observe = getObserveRequestHandler(getDMClient());
if (observe != null) {
observe.cancel(fields);
}
}
}
JsonObject response = new JsonObject();
response.add("reqId", jsonRequest.get("reqId"));
response.add("rc", new JsonPrimitive(ResponseCode.DM_SUCCESS.getCode()));
respond(response);
}
/**
* Return the cancel topic
*/
@Override
protected String getTopic() {
DMServerTopic topic = this.getDMClient().getDMServerTopic();
return topic.getCancelTopic();
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy