How to modify the output message in rest driver

Hi,

We need to overwrite the output message from Rest driver. We tried strip xpath expression to remove the text in set Xml attribute and append Xml element. Strip worked but not others.

Here is the example. We need to replace the message "Code(-9010) An exception occurred: novell.jclient.JCException: createEntry -609 ERR_MISSING_MANDATORY" with custom message.

<nds dtdversion="4.0" ndsversion="8.x">
<source>
<product edition="Advanced" version="4.8.7.0000">DirXML</product>
<contact>NetIQ Corporation</contact>
</source>
<output>
<status event-id="PLUMS##12478174712##0" level="error">Code(-9010) An exception occurred: novell.jclient.JCException: createEntry -609 ERR_MISSING_MANDATORY<operation-data callbackurl="true" lvPayLoad='{ "cdsid": "P-"}' lvURL="">se-qa-api.BBCbars.net:443/.../>
<application>DirXML</application>
<module>PLUMS</module>
<object-dn>BFC\Meta\Identities\Active\External\P-</object-dn>
<component>Publisher</component>
</status>
<status event-id="PLUMS##12478174712##0" level="error">Code(-9010) An exception occurred: novell.jclient.JCException: nameToID -601 ERR_NO_SUCH_ENTRY<operation-data callbackurl="true" lvPayLoad='{ "cdsid": "P-"}' lvURL="">se-qa-api.BBCbars.net:443/.../>
<application>DirXML</application>
<module>PLUMS</module>
<object-dn>BFC\Meta\Identities\Active\External\P-</object-dn>
<component>Publisher</component>
</status>
</output>
</nds>

  • 0  

    In the Input transform, the current context (like in all policies) is the current operation.  That is <status>.  So to get rid of the Code (-9010)... stuff, you would strip by XPATH ./text()  (period, slash text open round bracket close it).

    You do need to Strip it first, since the Append XML Text would not overwrite it.

    Then Append XML text of your message, with the target being . (period).

    It is work noting you have two status events in your example, so you would do something like:

    Something like this rule... Could not test it with your posted Status events there is something wrong with the XML and it is too early to figure it out.

    <rule>
    	<description>[CIS] Replace Status message from REST Response</description>
    	<comment xml:space="preserve">Change the Text of the Status message from a Rest Response.</comment>
    	<comment name="author" xml:space="preserve">Geoffrey Carman</comment>
    	<comment name="version" xml:space="preserve">1</comment>
    	<comment name="lastchanged" xml:space="preserve">Aug 9, 2024</comment>
    	<conditions>
    		<and>
    			<if-operation mode="nocase" op="equal">status</if-operation>
    			<if-xpath op="true">contains(.,"jclient")</if-xpath>
    		</and>
    	</conditions>
    	<actions>
    		<do-strip-xpath expression="./text()"/>
    		<do-append-xml-text expression=".">
    			<arg-string>
    				<token-text xml:space="preserve">My replacement String text via Local variable, GCV or whatever.</token-text>
    			</arg-string>
    		</do-append-xml-text>
    	</actions>
    </rule>

  • 0 in reply to   

    Thankyou so much Geoffrey. It worked.

    Can you also suggest how to transform the actual response code(500) and response message(Server error) to customized code and message respectively.

  • 0   in reply to 

    You would have to build up the operation data node with the proper XML to represent that. I forget the structure off hand.  Find a response you like and try to convert the XDS <status> message to what you want.

  • 0 in reply to   

    Not sure, if I have clarified my question correctly. Let me rephrase it. 

     When a new user is created, status code is 201 and message is created.

     When a user is modified, status code is 204 and message is no content.

     When a user is deleted, status code is 200 and message is ok.

     In our case it is 500 Server Error. Pls Refer the above screenshot.

     Now while doing an error handling, I want a custom error code like 514 instead of 500 and message invalid site code instead of server error etc.

  • 0   in reply to 

    From the trace sample, it has to be Publisher channel to return an NDS level error.

    So the shim is properly sending HTTP codes for 'events' which is how REST is supposed to work.

    Check out this page in the docs about the Op-Data...

    Driver Concepts - NetIQ REST Driver Implementation Guide

    www.netiq.com/.../driver-concepts.html

    I think you need to build the Response document from your <status>.  So you woud add operation-data that looks something like:

    <input>      
       <driver-operation-data class-name="User" command="add" remote-host="172.16.0.0" url="http://172.16.0.0:XXXX/User">
            <header content-type="application/json"/>
          <response>
            <value>{"association":"noble2","CN":"noble2","Full Name":"noble2","Given Name":"noble2","nspmDistributionPassword":"novell@123","Surname":"noble2"}
            </value>
          </response>
        </driver-operation-data>
    </input>

    Now note, that is an <input> document meant to be recieved on teh Pub channel after a successful Sub event. You want the opposite but I THINK if you converted your <status> with its error to that <operation-data> and yep, the next example in the docs has the line you need

              <value message="Created" status="201">{"id":"0052v00000hxEXOAA2","success":true,"errors":[]}</value>
    

    So the <value> node should be a child of the <response> node and see if that works.  Note the XML Attribute status, set that to your 519 or whatever...

  • 0 in reply to   

    This is quite interesting and much needed for today's integration with many applications.

    I have tried multiple times to construct the xml response header for POST Method. Never succeeded to get the custom status code and status message. Do you have any sample for this ? It would be really a great help.

  • 0   in reply to 

    As always working with what you have would be best.  So why not post the XML snippet with the driver-op-data have configured and then the trace of what happens (Shim side, so engine/RL show us that, with trace at level 25 or higher).

  • 0 in reply to   

    XML Snippet..

    Trace log.

    <?xml version="1.0" encoding="UTF-8"?>
    <nds dtdversion="4.0" ndsversion="8.x">
       <source>
          <product edition="Advanced" version="4.8.7.0000">DirXML</product>
          <contact>NetIQ Corporation</contact>
       </source>
       <output>
          <status event-id="PLUMS##12471316514##0" level="error">
             <application>DirXML</application>
             <module>PLUMS</module>
             <object-dn>TCC\Meta\Identities\Active\External\P-</object-dn>
             <component>Publisher</component>
             <operation-data callbackurl="true" lvPayLoad='{ "cdsid": "P-"}' lvURL="">se-qa-api.BBCbars.net:443/..."></operation-data>
             <driver-operation-data>
                <response>
                   <value>message="custom error" status="519" {"id":"testID","success":false,"errors":"invalid"}</value>
                </response>
             </driver-operation-data>
          </status>
          <status event-id="PLUMS##12471316514##0" level="error">
             <application>DirXML</application>
             <module>PLUMS</module>
             <object-dn>TCC\Meta\Identities\Active\External\P-</object-dn>
             <component>Publisher</component>
             <operation-data />
             <driver-operation-data>
                <response>
                   <value>message="custom error" status="519" {"id":"testID","success":false,"errors":"invalid"}</value>
                </response>
             </driver-operation-data>
          </status>
       </output>
    </nds>

  • 0   in reply to 

    You have to know where you are, when you "enter" a rule your pointer is at the event node, in this case <status>, therefor when you do strip xpath(.) then you're trying to remove the text from status/ and not status/driver-operation-data/response/value.

  • 0   in reply to   

    I reformatted your message to tab delimit the XML so it is easier to read and put it in a code block, revert the change if you hate it.

    Actually Caspar I think he is in the right place.  I agree, he should have had a condition that operation=status, but the test for @level=error is pretty much unique to Status events anyway. 

    The issue is you want the value node to look like:


              <value message="Created" status="201">{"id":"0052v00000hxEXOAA2","success":true,"errors":[]}</value>

    You made it look like:

                   <value>message="custom error" status="519" {"id":"testID","success":false,"errors":"invalid"}</value>

    You did Append XML text as your last token.  You should have done set xml attributes for message and status then Append XML text for the JSON bit.  Like this:

    			<do-set-xml-attr expression="driver-operation-data[last()]/response[last()]/value[last()]" name="message">
    				<arg-string>
    					<token-text xml:space="preserve">custom error message</token-text>
    				</arg-string>
    			</do-set-xml-attr>
    			<do-set-xml-attr expression="driver-operation-data[last()]/response[last()]/value[last()]" name="status">
    				<arg-string>
    					<token-text xml:space="preserve">519</token-text>
    				</arg-string>
    			</do-set-xml-attr>
    			<do-append-xml-text expression="driver-operation-data[last()]/response[last()]/value[last()]">
    				<arg-string>
    					<token-text xml:space="preserve">That JSON String you had I am not retyping.</token-text>
    				</arg-string>
    			</do-append-xml-text>