Highlighted
rcano Respected Contributor.
Respected Contributor.
1237 views

REST Driver - Response custom error codes.

Hi guys,

I'm implementing a new solution with the REST Driver as and endpoint of the IDV, and I have some doubts.

I configured it properly and I achieved some user creations from a REST client successfully, returning a 201 Created code.

In my custom case, I need to create users with more than the two default CN and Surname mandatory attributes, so I made a test sending only the CN mandatory attribute and the driver vetoed the operation as expected. However, the REST client didn't received any error code and is still waiting for a response from the REST driver.

Its possible to send back a custom error code to the REST Client in these situations? I was looking the default driver policies but I didn't found the place to perform this.

Thanks in advance,
Rodrigo Cano
Labels (1)
0 Likes
6 Replies
Knowledge Partner
Knowledge Partner

Re: REST Driver - Response custom error codes.

Hi Rodrigo,
I believe, that you can do it (and this is not really related to the REST driver).

You can have your own validation of existence of mandatory attributes and send "response" document back (custome error code) to the app, before than process with veto.
0 Likes
rcano Respected Contributor.
Respected Contributor.

Re: REST Driver - Response custom error codes.

al_b;2449220 wrote:
Hi Rodrigo,
I believe, that you can do it (and this is not really related to the REST driver).

You can have your own validation of existence of mandatory attributes and send "response" document back (custome error code) to the app, before than process with veto.


Hi al_b,

I guess that I can perform some kind of validation before the veto will be processed, but after few more tests, I noticed that the REST Driver sent 201 Created code even though the operation has been vetoed. There is any way to change that codes or are shim related?

Thank you,
Rodrigo Cano
0 Likes
Knowledge Partner
Knowledge Partner

Re: REST Driver - Response custom error codes.

rcano;2449225 wrote:
Hi al_b,

I guess that I can perform some kind of validation before the veto will be processed, but after few more tests, I noticed that the REST Driver sent 201 Created code even though the operation has been vetoed. There is any way to change that codes or are shim related?

Thank you,
Rodrigo Cano


Hi Rodrigo,
Bingo, I'm talking about pre-validation.

I noticed that the REST Driver sent 201 Created code even though the operation has been vetoed

Could you post your trace?
Defenetely if this "201 Created code" initiated by driver - you will be able to overwrite it.

You also can have your "pre-validation" logic in the Publisher Event Transformation policy (when document still work with Modify operation instead Add in Pub Matching).
Potentially "Modify" will not generate "201 Created code".
0 Likes
rcano Respected Contributor.
Respected Contributor.

Re: REST Driver - Response custom error codes.

al_b;2449228 wrote:
Hi Rodrigo,
Bingo, I'm talking about pre-validation.


Could you post your trace?
Defenetely if this "201 Created code" initiated by driver - you will be able to overwrite it.

You also can have your "pre-validation" logic in the Publisher Event Transformation policy (when document still work with Modify operation instead Add in Pub Matching).
Potentially "Modify" will not generate "201 Created code".


Hi al_b,

I tried what you suggested and I made a pre-validation in the Publisher event. In this case, the driver returned a 204 No Content code instead the 201 Created when the operation is vetoed.

This is the full trace:

[01/23/17 14:07:51.248]:HipraLink REST Driver PT:Receiving DOM document from application.
[01/23/17 14:07:51.249]:HipraLink REST Driver PT:
<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20150722_0750" instance="DrvHipraLink" version="1.0.0.0">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input>
<driver-operation-data class-name="User" command="add" event-id="DrvHipraLink##11702314751##0" remote-host="127.0.0.1" url="http://127.0.0.1:443/User">
<response>
<header content-type="text/plain; charset=UTF-8"/>
<value>{"association":"PROVESPROVES","Surname":["PROVESHIPRALINKPROVES"]}</value>
</response>
</driver-operation-data>
</input>
</nds>
[01/23/17 14:07:51.250]:HipraLink REST Driver PT:Applying input transformation policies.
[01/23/17 14:07:51.250]:HipraLink REST Driver PT:Applying policy: %+C%14CNETQRESTJSON-itp-CheckRetries%-C.
[01/23/17 14:07:51.250]:HipraLink REST Driver PT: Applying to driver-operation-data #1.
[01/23/17 14:07:51.250]:HipraLink REST Driver PT: Evaluating selection criteria for rule 'set retry on status if sought'.
[01/23/17 14:07:51.250]:HipraLink REST Driver PT: (if-operation equal "status") = FALSE.
[01/23/17 14:07:51.250]:HipraLink REST Driver PT: Rule rejected.
[01/23/17 14:07:51.250]:HipraLink REST Driver PT:Policy returned:
[01/23/17 14:07:51.251]:HipraLink REST Driver PT:
<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20150722_0750" instance="DrvHipraLink" version="1.0.0.0">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input>
<driver-operation-data class-name="User" command="add" event-id="DrvHipraLink##11702314751##0" remote-host="127.0.0.1" url="http://127.0.0.1:443/User">
<response>
<header content-type="text/plain; charset=UTF-8"/>
<value>{"association":"PROVESPROVES","Surname":["PROVESHIPRALINKPROVES"]}</value>
</response>
</driver-operation-data>
</input>
</nds>
[01/23/17 14:07:51.252]:HipraLink REST Driver PT:Applying policy: %+C%14CNETQRESTJSON-itp-JSONtoXDS%-C.
[01/23/17 14:07:51.252]:HipraLink REST Driver PT: Applying to driver-operation-data #1.
[01/23/17 14:07:51.252]:HipraLink REST Driver PT: Evaluating selection criteria for rule 'Translate JSON to XDS'.
[01/23/17 14:07:51.252]:HipraLink REST Driver PT: (if-class-name available) = TRUE.
[01/23/17 14:07:51.252]:HipraLink REST Driver PT: (if-class-name not-equal "DirXML-Driver") = TRUE.
[01/23/17 14:07:51.253]:HipraLink REST Driver PT: Rule selected.
[01/23/17 14:07:51.253]:HipraLink REST Driver PT: Applying rule 'Translate JSON to XDS'.
[01/23/17 14:07:51.253]:HipraLink REST Driver PT: Action: do-if().
[01/23/17 14:07:51.253]:HipraLink REST Driver PT: Evaluating conditions.
[01/23/17 14:07:51.253]:HipraLink REST Driver PT: (if-operation match "status") = FALSE.
[01/23/17 14:07:51.253]:HipraLink REST Driver PT: Performing else actions.
[01/23/17 14:07:51.253]:HipraLink REST Driver PT: Action: do-if().
[01/23/17 14:07:51.254]:HipraLink REST Driver PT: Evaluating conditions.
[01/23/17 14:07:51.254]:HipraLink REST Driver PT: (if-xml-attr 'command' available) = TRUE.
[01/23/17 14:07:51.254]:HipraLink REST Driver PT: Performing if actions.
[01/23/17 14:07:51.254]:HipraLink REST Driver PT: Action: do-if().
[01/23/17 14:07:51.254]:HipraLink REST Driver PT: Evaluating conditions.
[01/23/17 14:07:51.254]:HipraLink REST Driver PT: (if-xml-attr 'command' equal "poll") = FALSE.
[01/23/17 14:07:51.254]:HipraLink REST Driver PT: Performing else actions.
[01/23/17 14:07:51.254]:HipraLink REST Driver PT: Action: do-set-local-variable("operations",scope="policy",arg-node-set(token-xpath("."))).
[01/23/17 14:07:51.255]:HipraLink REST Driver PT: arg-node-set(token-xpath("."))
[01/23/17 14:07:51.255]:HipraLink REST Driver PT: token-xpath(".")
[01/23/17 14:07:51.255]:HipraLink REST Driver PT: Token Value: {<driver-operation-data> @class-name = "User" @command = "add" @event-id = "DrvHipraLink##11702314751##0" @remote-host = "127.0.0.1" @url = "http://127.0.0.1:443/User"}.
[01/23/17 14:07:51.255]:HipraLink REST Driver PT: Arg Value: {<driver-operation-data> @class-name = "User" @command = "add" @event-id = "DrvHipraLink##11702314751##0" @remote-host = "127.0.0.1" @url = "http://127.0.0.1:443/User"}.
[01/23/17 14:07:51.258]:HipraLink REST Driver PT: Action: do-for-each(arg-node-set(token-local-variable("operations"))).
[01/23/17 14:07:51.261]:HipraLink REST Driver PT: arg-node-set(token-local-variable("operations"))
[01/23/17 14:07:51.264]:HipraLink REST Driver PT: token-local-variable("operations")
[01/23/17 14:07:51.266]:HipraLink REST Driver PT: Token Value: {<driver-operation-data> @class-name = "User" @command = "add" @event-id = "DrvHipraLink##11702314751##0" @remote-host = "127.0.0.1" @url = "http://127.0.0.1:443/User"}.
[01/23/17 14:07:51.271]:HipraLink REST Driver PT: Arg Value: {<driver-operation-data> @class-name = "User" @command = "add" @event-id = "DrvHipraLink##11702314751##0" @remote-host = "127.0.0.1" @url = "http://127.0.0.1:443/User"}.
[01/23/17 14:07:51.276]:HipraLink REST Driver PT: Performing actions for local-variable(current-node) = <driver-operation-data> @class-name = "User" @command = "add" @event-id = "DrvHipraLink##11702314751##0" @remote-host = "127.0.0.1" @url = "http://127.0.0.1:443/User".
[01/23/17 14:07:51.276]:HipraLink REST Driver PT: Action: do-set-local-variable("command",scope="policy",token-xpath("@command")).
[01/23/17 14:07:51.277]:HipraLink REST Driver PT: arg-string(token-xpath("@command"))
[01/23/17 14:07:51.277]:HipraLink REST Driver PT: token-xpath("@command")
[01/23/17 14:07:51.277]:HipraLink REST Driver PT: Token Value: "add".
[01/23/17 14:07:51.277]:HipraLink REST Driver PT: Arg Value: "add".
[01/23/17 14:07:51.277]:HipraLink REST Driver PT: Action: do-if().
[01/23/17 14:07:51.277]:HipraLink REST Driver PT: Evaluating conditions.
[01/23/17 14:07:51.278]:HipraLink REST Driver PT: (if-local-variable 'command' match "query|delete") = FALSE.
[01/23/17 14:07:51.278]:HipraLink REST Driver PT: Performing else actions.
[01/23/17 14:07:51.278]:HipraLink REST Driver PT: Action: do-set-local-variable("xmlInput",notrace="true",scope="policy",token-base64-encode(charset="UTF-8",token-replace-all("<","<",token-xml-serialize(token-xpath("."))))).
[01/23/17 14:07:51.278]:HipraLink REST Driver PT: -- trace suppressed --
[01/23/17 14:07:51.279]:HipraLink REST Driver PT: Action: do-set-local-variable("applicationContent",notrace="true",scope="policy",token-xpath("rs:jsonToXDS($xmlInput)")).
[01/23/17 14:07:51.336]:HipraLink REST Driver PT: -- trace suppressed --
[01/23/17 14:07:51.336]:HipraLink REST Driver PT: Action: do-if(notrace="true").
[01/23/17 14:07:51.337]:HipraLink REST Driver PT: -- trace suppressed --
[01/23/17 14:07:51.337]:HipraLink REST Driver PT: Action: do-strip-xpath(".").
[01/23/17 14:07:51.337]:HipraLink REST Driver PT:Policy returned:
[01/23/17 14:07:51.337]:HipraLink REST Driver PT:
<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20150722_0750" instance="DrvHipraLink" version="1.0.0.0">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input>
<add class-name="User" event-id="DrvHipraLink##11702314751##0">
<association>PROVESPROVES</association>
<add-attr attr-name="Surname">
<value value="string">PROVESHIPRALINKPROVES</value>
</add-attr>
</add>
</input>
</nds>
[01/23/17 14:07:51.338]:HipraLink REST Driver PT:Applying policy: %+C%14CNETQRESTDCFG-itp-AddAssociation%-C.
[01/23/17 14:07:51.338]:HipraLink REST Driver PT: Applying to add #1.
[01/23/17 14:07:51.338]:HipraLink REST Driver PT: Evaluating selection criteria for rule 'Check for association -ADD'.
[01/23/17 14:07:51.339]:HipraLink REST Driver PT: (if-operation match "status") = FALSE.
[01/23/17 14:07:51.339]:HipraLink REST Driver PT: Rule rejected.
[01/23/17 14:07:51.339]:HipraLink REST Driver PT: Evaluating selection criteria for rule 'Check for association - MODIFY'.
[01/23/17 14:07:51.339]:HipraLink REST Driver PT: (if-operation match "modify") = FALSE.
[01/23/17 14:07:51.339]:HipraLink REST Driver PT: Rule rejected.
[01/23/17 14:07:51.339]:HipraLink REST Driver PT:Policy returned:
[01/23/17 14:07:51.340]:HipraLink REST Driver PT:
<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20150722_0750" instance="DrvHipraLink" version="1.0.0.0">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input>
<add class-name="User" event-id="DrvHipraLink##11702314751##0">
<association>PROVESPROVES</association>
<add-attr attr-name="Surname">
<value value="string">PROVESHIPRALINKPROVES</value>
</add-attr>
</add>
</input>
</nds>
[01/23/17 14:07:51.341]:HipraLink REST Driver PT:No schema mapping policies.
[01/23/17 14:07:51.341]:HipraLink REST Driver PT:Resolving association references.
[01/23/17 14:07:51.341]:HipraLink REST Driver PT:Applying event transformation policies.
[01/23/17 14:07:51.341]:HipraLink REST Driver PT:Applying policy: %+C%14Cpub-etp-CheckMandatoryAttr%-C.
[01/23/17 14:07:51.341]:HipraLink REST Driver PT: Applying to add #1.
[01/23/17 14:07:51.341]:HipraLink REST Driver PT: Evaluating selection criteria for rule 'Veto if mandatory attributes not available.'.
[01/23/17 14:07:51.342]:HipraLink REST Driver PT: (if-class-name equal "User") = TRUE.
[01/23/17 14:07:51.342]:HipraLink REST Driver PT: Rule selected.
[01/23/17 14:07:51.342]:HipraLink REST Driver PT: Applying rule 'Veto if mandatory attributes not available.'.
[01/23/17 14:07:51.342]:HipraLink REST Driver PT: Action: do-veto-if-op-attr-not-available("CN").
[01/23/17 14:07:51.342]:HipraLink REST Driver PT:Policy returned:
[01/23/17 14:07:51.343]:HipraLink REST Driver PT:
<nds dtdversion="3.5" ndsversion="8.x">
<source>
<product build="20150722_0750" instance="DrvHipraLink" version="1.0.0.0">Identity Manager REST Driver</product>
<contact>NetIQ Corporation.</contact>
</source>
<input/>
</nds>
[01/23/17 14:07:51.343]:HipraLink REST Driver PT:Fixing up association references.
[01/23/17 14:07:51.343]:HipraLink REST Driver PT:No schema mapping policies.
[01/23/17 14:07:51.343]:HipraLink REST Driver PT:Applying output transformation policies.
[01/23/17 14:07:51.344]:HipraLink REST Driver PT:Applying policy: %+C%14CNETQRESTDCFG-otp-AddAssociation%-C.
[01/23/17 14:07:51.344]:HipraLink REST Driver PT:Policy returned:
[01/23/17 14:07:51.344]:HipraLink REST Driver PT:
<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product edition="Standard" version="4.5.3.0">DirXML</product>
<contact>NetIQ Corporation</contact>
</source>
<output/>
</nds>
[01/23/17 14:07:51.344]:HipraLink REST Driver PT:Applying policy: %+C%14CNETQRESTJSON-otp-XDStoJSON%-C.
[01/23/17 14:07:51.344]:HipraLink REST Driver PT:Policy returned:
[01/23/17 14:07:51.344]:HipraLink REST Driver PT:
<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product edition="Standard" version="4.5.3.0">DirXML</product>
<contact>NetIQ Corporation</contact>
</source>
<output/>
</nds>
[01/23/17 14:07:51.345]:HipraLink REST Driver PT:
<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product edition="Standard" version="4.5.3.0">DirXML</product>
<contact>NetIQ Corporation</contact>
</source>
<output/>
</nds>


There's any way to change the 204 code directly to something more indicative with the corresponding text?

I don't know what is the action or the method to overwrite the default shim codes.

Thanks in advance,
Rodrigo Cano
0 Likes
kharing Valued Contributor.
Valued Contributor.

Re: REST Driver - Response custom error codes.

Hi Rodrigo,

I am actually currently having trouble with a similar issue as I would like the response to make clear that no matching object was found (creation does not take place in Publisher shim of REST driver). Instead, if I set the status to error and send a veto for the event, a 204 is returned as response. Better than no response but still not what I'd like it to be.

Did you find  a good solution for changing the response to custom error codes?

Best regards,

Katharina

0 Likes
gbatty1 Trusted Contributor.
Trusted Contributor.

Re: REST Driver - Response custom error codes.

Hi All,

Sorry to dig up an old thread.

Similar to the other posts, I'm using the Rest driver to expose IDM endpoints so we can create users or groups in the vault.

I'm searching for a way to customise or choose the appropriate HTTP status codes reported back to the client if my driver logic determines it's appropriate (ie HTTP 400).

Whilst I can place an appropriate message in the response (ie, bad request), the best HTTP status code response to the client request I can come up with so far is 500 Server Error, and this is when I deliberately set the xml attribute level to "error".

I've also tried playing with the xml attribute type, setting that to "app-general" but still can only get the HTTP 500 error.

Has anybody figured out a way to dictate the HTTP status code responses?

0 Likes
The opinions expressed above are the personal opinions of the authors, not of Micro Focus. By using this site, you accept the Terms of Use and Rules of Participation. Certain versions of content ("Material") accessible here may contain branding from Hewlett-Packard Company (now HP Inc.) and Hewlett Packard Enterprise Company. As of September 1, 2017, the Material is now offered by Micro Focus, a separately owned and operated company. Any reference to the HP and Hewlett Packard Enterprise/HPE marks is historical in nature, and the HP and Hewlett Packard Enterprise/HPE marks are the property of their respective owners.