Hello,
I am looking for help to parse the XML response in Webservices connector. I am getting the below sample API xml response. It is a multiple users response, but I have given for one user in the example.
Below are the configuration in WS connector. Headers
Content-Type: application/xml,text/xml Response Information
Root Path: .//USER_LIST_OUTPUT/USER_LIST/USER/
Success Code: 2** Response Mapping
Schema attributes (on the left column)
USER_LOGIN
USER_ID
Attribute Path (On the right column)
@USER_LOGIN @USER_ID
Error
During Account Aggregation below error occurs sailpoint.connector.ConnectorException: Error: Error extracting response from XML.
How should I configure the response to map the attributes like USER_LOGIN, USER_ID, FIRST_NAME in CONTACT_INFO?
The issue here is the response XML is not parsing correctly from the root path. The configured API (GET) is giving the above mentioned XML response when I executing it through Postman. But getting the XML parse error when I configure it in ISC.
After so much struggle I have resolved the issue by writing the WS AfterOperationRule. The rule is navigate through each node of the XML and assigned it to HashMap object and returned the same by assigning it to a data object as response.
In WS configuration, set the root path = ./data in Response and set Headers as below.
Content-Type = application/json
Accept = * / *
Update: Since many are requesting the code snippet of the rule, here Iām posting it.
Map userDetailsMap = new HashMap();
if (rawResponseObject != null) {
//Create XPath
XPath xpath = XPathFactory.newInstance().newXPath();
XPathExpression xPathExpr = xpath.compile("/USER_LIST_OUTPUT/USER");
NodeList nodes = (NodeList) xPathExpr.evaluate(doc, XPathConstants.NODESET);
for (int i = 0; i < nodes.getLength(); i++) {
Element node = (Element) nodes.item(i);
// Get ASSIGNED_GROUPS
ArrayList < String > assignedGrp = new ArrayList < String > ();
NodeList assignedGrpNodeList = node.getElementsByTagName("ASSIGNED_GROUPS");
if (assignedGrpNodeList != null && assignedGrpNodeList.getLength() > 0) {
for (int i = 0; i < assignedGrpNodeList.getLength(); i++) {
//get the groups element
Element assetGrpElement = (Element) assignedGrpNodeList.item(i);
NodeList GrpTitleNodeList = assetGrpElement.getElementsByTagName("GRP_TITLE");
if (GrpTitleNodeList != null && GrpTitleNodeList.getLength() > 0) {
for (int j = 0; j < GrpTitleNodeList.getLength(); j++) {
//get the Group Title object in ASSIGNED_GROUPS
Element groupElement = (Element) GrpTitleNodeList.item(j);
String assetGrp = groupElement.getFirstChild().getNodeValue();
assignedGrp.add((assetGrp == null ? "" : assetGrp));
}
userDetailsMap.put("ASSIGNED_GROUPS", assignedGrp);
}
}
}
accountsToReturn.add(userDetailsMap);
}
}
//Return the results in the data key
Map accountListMap = new HashMap();
accountListMap.put("data", accountsToReturn);
return accountListMap;