Skip to content
This repository has been archived by the owner on Jul 28, 2021. It is now read-only.

Commit

Permalink
Assume all fields are optional in status message
Browse files Browse the repository at this point in the history
  • Loading branch information
Ian Craggs committed Sep 27, 2018
1 parent 1d2f703 commit 7ccff8d
Showing 1 changed file with 31 additions and 12 deletions.
43 changes: 31 additions & 12 deletions src/main/java/com/ibm/iotf/client/app/Status.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public abstract class Status {
private String user;
private String action;
private String connectTime;
private int port;
private int port = 0;
private DateTime time;

// Additional "Disconnect" status properties
Expand Down Expand Up @@ -114,13 +114,28 @@ public Status(MqttMessage msg) throws UnsupportedEncodingException{
JsonObject payloadJson = JSON_PARSER.parse(payload).getAsJsonObject();

// Common attributes
clientAddr = payloadJson.get("ClientAddr").getAsString();
protocol = payloadJson.get("Protocol").getAsString();
clientId = payloadJson.get("ClientID").getAsString();
time = DT_PARSER.parseDateTime(payloadJson.get("Time").getAsString());
action = payloadJson.get("Action").getAsString();

port = payloadJson.get("Port").getAsInt();
if (payloadJson.has("ClientAddr"))
clientAddr = payloadJson.get("ClientAddr").getAsString();
else
clientAddr = new String();
if (payloadJson.has("Protocol"))
protocol = payloadJson.get("Protocol").getAsString();
else
protocol = new String();
if (payloadJson.has("ClientID"))
clientId = payloadJson.get("ClientID").getAsString();
else
clientId = new String();
if (payloadJson.has("Time"))
time = DT_PARSER.parseDateTime(payloadJson.get("Time").getAsString());
else
time = new DateTime();
if (payloadJson.has("Action"))
action = payloadJson.get("Action").getAsString();
else
action = new String();
if (payloadJson.has("Port"))
port = payloadJson.get("Port").getAsInt();

if (action.equals("Disconnect")) {
if (payloadJson.has("User"))
Expand All @@ -131,10 +146,14 @@ public Status(MqttMessage msg) throws UnsupportedEncodingException{
connectTime = payloadJson.get("ConnectTime").getAsString();
else
connectTime = new String();
writeMsg = payloadJson.get("WriteMsg").getAsInt();
readMsg = payloadJson.get("ReadMsg").getAsInt();
readBytes = payloadJson.get("ReadBytes").getAsInt();
writeBytes = payloadJson.get("WriteBytes").getAsInt();
if (payloadJson.has("WriteMsg"))
writeMsg = payloadJson.get("WriteMsg").getAsInt();
if (payloadJson.has("ReadMsg"))
readMsg = payloadJson.get("ReadMsg").getAsInt();
if (payloadJson.has("ReadBytes"))
readBytes = payloadJson.get("ReadBytes").getAsInt();
if (payloadJson.has("WriteBytes"))
writeBytes = payloadJson.get("WriteBytes").getAsInt();
if (payloadJson.has("Reason"))
reason = payloadJson.get("Reason").getAsString();
else
Expand Down

0 comments on commit 7ccff8d

Please sign in to comment.