Uploaded image for project: 'Edgent'
  1. Edgent
  2. EDGENT-425

Handle JSON parsing exceptions gracefully when processing IoT commands

    XMLWordPrintableJSON

Details

    • Improvement
    • Status: Open
    • Minor
    • Resolution: Unresolved
    • None
    • None
    • Connectors
    • None

    Description

      I am running the IotpSensors application launched using the runiotpsensors.sh script. I noticed that if the JSON command payload is malformed, e.g.:
      "{'deviceId': 'rpi-2', 'typeId': 'R-PI-02', 'cmdId': 'display', 'd': '{"d": {"msg": "Hello Edgent!"}}'}"
      instead of
      {'deviceId': 'rpi-2', 'typeId': 'R-PI-02', 'cmdId': 'display', 'jsonString': '{"d": {"msg": "Hello Edgent!"}}'}

      Which is an example of a client sending bad data, then my Edgent application stops generating data altogether after throwing the exception below.

      It isn't a big deal in a small scenario because I can just restart my Edgent application, but it might be annoying on a real device.

      Jun 26, 2017 5:17:59 PM org.apache.edgent.runtime.etiao.ThreadFactoryTracker trackedThreadUncaughtException
      SEVERE: Uncaught exception in thread pool-1-thread-27-IotpSensors
      java.lang.ClassCastException: com.google.gson.JsonPrimitive cannot be cast to com.google.gson.JsonObject
      	at com.google.gson.JsonObject.getAsJsonObject(JsonObject.java:182)
      	at org.apache.edgent.connectors.iotp.IotpDevice.lambda$commands$48c2e166$1(IotpDevice.java:348)
      	at org.apache.edgent.function.Functions$ThreadSafeFunction.apply(Functions.java:127)
      	at org.apache.edgent.oplet.functional.Map.accept(Map.java:45)
      	at org.apache.edgent.runtime.etiao.SettableForwarder.accept(SettableForwarder.java:54)
      	at org.apache.edgent.oplet.core.Pipe.submit(Pipe.java:65)
      	at org.apache.edgent.oplet.functional.Filter.accept(Filter.java:37)
      	at org.apache.edgent.runtime.etiao.SettableForwarder.accept(SettableForwarder.java:54)
      	at org.apache.edgent.oplet.core.Pipe.submit(Pipe.java:65)
      	at org.apache.edgent.oplet.plumbing.Isolate.run(Isolate.java:86)
      	at org.apache.edgent.oplet.plumbing.Isolate.lambda$initialize$0(Isolate.java:64)
      	at org.apache.edgent.runtime.etiao.ThreadFactoryTracker$2.run(ThreadFactoryTracker.java:87)
      	at java.lang.Thread.run(Thread.java:745)
      

      Attachments

        Activity

          People

            Unassigned Unassigned
            ndsilva Natasha D'Silva
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated: