Original Message:
Sent: Thu April 09, 2020 07:31 AM
From: Hermanni Pernaa
Subject: set return code when xslt call dp:gatewayscript
You can set return-error to false and generate the error response yourself.
If you change the GatewayScript call as follows:
<xsl:variable name="flux" select="dp:gatewayscript('ChequeSansCoupon.js', $JsonString , false(), '')"/>
and then inside ChequeSansCoupon.js change the "catch" block to something like the one below:
session.input.readAsJSON(function (readAsJSONError, jsonData) { if (readAsJSONError) { var errorResponse = '<gatewayscript><errorcode>0x0000200</errorcode></gatewayscript>'; session.output.write(XML.parse(errorResponse)); } else { var response = '<gatewayscript><result>Input string was a valid JSON string</result></gatewayscript>' session.output.write(XML.parse(response)); }});
you'll get the following back to $flux if $JsonString is not valid:
<gatewayscript> <errorcode>0x0000200</errorcode></gatewayscript>
If the string is valid, then you'll get:
<gatewayscript> <result>Input string was a valid JSON string</result></gatewayscript>
Hope this helps.
------------------------------
Hermanni Pernaa
Original Message:
Sent: Wed April 08, 2020 01:08 PM
From: David Leroux
Subject: set return code when xslt call dp:gatewayscript
Hello Steve
I agree with you With no runtime errors or a session.reject, I would anticipate an error code returned as x00000000
But session.reject (if string is not json, for example), returns a error into the WSP which throws an error Policy (that's not what i want). I just want to recover the xml returns with dp:gatewayscript without the WSP generating an error policy
------------------------------
David Leroux
Original Message:
Sent: Wed April 08, 2020 12:22 PM
From: Stephen Linn
Subject: set return code when xslt call dp:gatewayscript
The error code returned is not one that you have control over. I'm pretty sure session.reject would have one error code, an uncaught exception would may have a different error code depending upon the issue, etc. The error code is dependent upon the type of error encountered by the .js. With no runtime errors or a session.reject, I would anticipate an error code returned as x00000000.
Regards,
Steve
------------------------------
Stephen Linn
Original Message:
Sent: Wed April 08, 2020 06:11 AM
From: David Leroux
Subject: set return code when xslt call dp:gatewayscript
If I do this, the WSP, which use the dp:gatewayscript thrown command, generate a error Policy.
If it's not possible to set a errorCode into ChequeSansCoupon without generate a global error Policy, i will continue to use this
if (readAsJSONError) { session.output.write('false');
Thanks a lot Herman :-)
------------------------------
David Leroux
Original Message:
Sent: Wed April 08, 2020 05:55 AM
From: Hermann Stamm-Wilbrandt
Subject: set return code when xslt call dp:gatewayscript
You cite my incorrect first response posting, which I edited afterwards.
The corrected response allows to do error handling in GatewayScipt with the help of session.reject().
------------------------------
Hermann Stamm-Wilbrandt
Compiler Level 3 support & Fixpack team lead
IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
Original Message:
Sent: Wed April 08, 2020 05:50 AM
From: David Leroux
Subject: set return code when xslt call dp:gatewayscript
thanks Herman.
I Don't understand when you said "you cannot, because in case of JSON parse error the GatewayScipt does not get executed at all"
I have the impression that my script is well executed even if the message is not json
for example, here is ChequeSansCoupin.js
session.input.readAsJSON(function (readAsJSONError, jsonData) { if (readAsJSONError) { session.output.write('false'); } else { session.output.write('true'); }});
when i call gatewayscript with a non json message, the response is
<gatewayscript> <errorcode>0x00000000</errorcode> <result>false</result></gatewayscript>
So for my case, i need to test /gatewayscript/result = 'false'. But I would have liked to test /gatewayscript/errorcode <> '0x00000000'
So you think it's not possible to change errorcode into a gatewayscript ?
------------------------------
David Leroux
Original Message:
Sent: Wed April 08, 2020 05:33 AM
From: Hermann Stamm-Wilbrandt
Subject: set return code when xslt call dp:gatewayscript
Hi,
> If $JsonString is not json, how code into ChequeSansCoupon.js a json error to have this return below
>
in ChequeSansCoupon.js:
session.input.readAsJSON(function (error, jsonstring) { if (error) { session.reject("<gatewayscript><errorcode>0x0000200</errorcode></gatewayscript> "); return; }...});
------------------------------
Hermann Stamm-Wilbrandt
Compiler Level 3 support & Fixpack team lead
IBM DataPower Gateways (⬚ᵈᵃᵗᵃ / ⣏⠆⡮⡆⢹⠁⡮⡆⡯⠂⢎⠆⡧⡇⣟⡃⡿⡃)
Original Message:
Sent: Tue April 07, 2020 09:55 AM
From: David Leroux
Subject: set return code when xslt call dp:gatewayscript
Hello
I understand it's possible to call a Gateway script from an XSLT stylesheet
So i use the command below (where $JsonString is a json)
<xsl:variable name="flux" select="dp:gatewayscript('ChequeSansCoupon.js', $JsonString , true(), '')"/>
If $JsonString is not json, how code into ChequeSansCoupon.js a json error to have this return below
<gatewayscript> <errorcode>0x0000200</errorcode></gatewayscript>
Thanks for reply
------------------------------
David Leroux
------------------------------