Author |
Message
|
gakd1987 |
Posted: Tue Nov 17, 2015 9:59 am Post subject: parsed blob data needs to be assesed if its JSON or XML |
|
|
Apprentice
Joined: 20 Aug 2013 Posts: 26
|
I have a flow in which we are invoking a restful service using HTTPRequest node and that request hits the datapower and gives back the response and the response from datapower is expected to be JSON. We are getting back JSON response in most of ideal cases except 1 scenario i.e. when the datapower timesout while processing the request and returns back XML as response and it fails in the HTTPRequest node. Ideally the datapower has to return JSON but due to some constraint the changes in DP is in prgress but mean while we are thinking to change the PARSER in the httprequest node to BLOB and then we would write a function to check if the BLOB is really a XML or JSON and reparse it accordingly. Is there a way to check if the BLOB is XML or JSON before its parsed by RCD node? |
|
Back to top |
|
 |
smdavies99 |
Posted: Tue Nov 17, 2015 11:02 am Post subject: |
|
|
 Jedi Council
Joined: 10 Feb 2003 Posts: 6076 Location: Somewhere over the Rainbow this side of Never-never land.
|
Look at the first character and see if is a <
You can cast the < as a blob and then extract the same length from the input BLOB.
IF they match then you have XML otherwise assume it is JSON.
There are probably other ways. _________________ WMQ User since 1999
MQSI/WBI/WMB/'Thingy' User since 2002
Linux user since 1995
Every time you reinvent the wheel the more square it gets (anon). If in doubt think and investigate before you ask silly questions. |
|
Back to top |
|
 |
mqjeff |
Posted: Tue Nov 17, 2015 11:15 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
use create lastchild domain.
catch exceptions. _________________ chmod -R ugo-wx / |
|
Back to top |
|
 |
timber |
Posted: Tue Nov 17, 2015 11:42 am Post subject: |
|
|
 Grand Master
Joined: 25 Aug 2015 Posts: 1292
|
Quote: |
Look at the first character and see if is a < |
If it works once then it will probably work every time. But it only works when the document does not start with a Byte Order Mark.
mqjeff's suggestion will always work. |
|
Back to top |
|
 |
|