You can use xpath queries (such as //errorCode, //errorMessage, //warningCode) in the onComplete script to check for these values in the response xml.
A sample way of doing this is
XML outputXml = utils.parseXml(xpath:{/workflow/Execute_1/outputXml});
if (outputXml != null) {
String errorCode = outputXml.getText("//errorCode");
String errorMessage = outputXml.getText("//errorMessage");
String warningCode = outputXml.getText("//warningCode");
}
if these are null then they didn’t exist in the outptuXml.
This works well if these are elements in the response which I believe is most of the case now a days but if you see any responses with these come across as attributes then your query would need to change to use the @ symbol
String errorCode = outputXml.getText("//@errorCode");
String errorMessage = outputXml.getText("//@errorMessage");
String warningCode = outputXml.getText("//@warningCode");
You could always combine them and make a big script to check for all cases
String errorCodeE = outputXml.getText("//@errorCode");
String errorCodeA = outputXml.getText("//@errorCode");
String errorCode = errorCodeA != null ? errorCodeA : errorCodeE
Hi Chris
Tried something similar to your first recommendation, after finding samples in BOL don’t really work. That works well when all those Attributes exist. If they don’t, or have different Attribute-Names, it gets complicated. Like I know errorString but can’t remember seeing errorMessage, maybe that’s something new in FR20+.
Current working prototype below. Open for recommendations on how to make it cover more conditions and less Null-Pointer-Exception-y (I’m a Java Noob)
if(activity.exitCode == 0)
{
logger.info("in EC 0");
if (activity.outputXml != null)
{
XML xml = utils.parseXml(activity.outputXml);
String errorCode = xml.getText("//errorCode");
String warningCode = xml.getText("//warningCode");
String errorString = xml.getText("//errorString");
logger.warn("error: "+errorCode);
logger.warn("warning: "+warningCode);
logger.warn("string: "+errorString);
if (errorCode != null && warningCode != null && (errorCode > 0 || warningCode > 0))
{
logger.info("in xml processing");
activity.exitCode = Integer.parseInt(errorCode);
activity.commandOutput = errorString;
workflow.setFailed("Error e"+activity.exitCode+"] : "+activity.commandOutput);
}
}
}
Thanks,
Stefan
The only thing I’d change here is with this if statement
errorCode != null && warningCode != null
You may want to use an || otherwise both of these would have to be not null just to get the errorCode
If you run across this not working for a particular response, let me know and we can adjust it to handle it as well.