Netscaler Rewrite complete HTTP Request Body before sending to the backend server

You may run into cases where the sending application has one set of message standards and the receiving service has its own standards. One such case that I recently ran into with an app trying to initiate a call request via vendor-neutral open standards to Cisco Unified communication system. Obviously, Cisco expects the API request to be in its own format and some process needs to do this translation/transformation to complete the request successfully.

Cisco has good documentation on these Call APIs, also published a sample java application which can be found at https://developer.cisco.com/site/webdialer/

Netscaler Rewrite Action can be levered to transform the HTTP REQ Body to Cisco desired format. Below is a rewrite action that I used to bridge the gap, Basically, replaced the message body to Cisco specifications from the extracted information of the original message.

Expression

Note: Had to break the expression strings in chucks of ~200 char’s to please Netscaler character limitation. Also, while I could have used XPATH to extract the desired information, I went with regex as it turned out to be faster during testing.

"<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:urn=\"urn:WD70\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instanc"+"e\"><soapenv:Header /><soapenv:Body><urn:makeCallSoap soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><in0 xsi:type=\"urn:Credential\"><userID xsi:type=\"xsd:string\">username"+"</userID><password xsi:type=\"xsd:string\">******</password></in0><in1 xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" xsi:type=\"soapenc:string\">" + HTTP.REQ.BODY(HTTP.REQ.CONTENT_LENGTH).AFTER_REGEX(re/<PhoneNumber>/).Before_REGEX(re/<.PhoneNumber>/) + "</in1><in2 xsi:type=\"urn:UserProfile"+"\"><user xsi:type=\"xsd:string\">?</user><deviceName xsi:type=\"xsd:string\">CSF" + HTTP.REQ.BODY(HTTP.REQ.CONTENT_LENGTH).AFTER_REGEX(re/<PhoneAgentID>/).Before_REGEX(re/<.PhoneAgentID>/).TO_UPPER + "</deviceName><lineNumber xsi:type=\"xsd:string\">?</lineNumber></in2></urn:makeCallSoap></soapenv:Body></soapenv:"+"Envelope>"

References >

https://www.citrix.com/blogs/2014/03/03/creating-policies-greater-than-255-characters/

https://developer.cisco.com/site/webdialer/

Leave a comment

Your email address will not be published.