Natasha D'Silva created EDGENT-425:
--------------------------------------
Summary: Handle JSON parsing exceptions gracefully when processing
IoT commands
Key: EDGENT-425
URL: https://issues.apache.org/jira/browse/EDGENT-425
Project: Edgent
Issue Type: Improvement
Components: Connectors
Reporter: Natasha D'Silva
Priority: Minor
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.
{code:java}
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)
{code}
--
This message was sent by Atlassian JIRA
(v6.4.14#64029)