Hi Experts,
I have a requirement where i need to do a lookup call to a web service and need to capture a value from the response message.I am using the below code t call a web service and able to get the response. but need help in retrieving the output value.
Requirement -
Response message looks like below -
<Lists xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<Items>
<List>
<ID>gWmoJWo4UtuyqBIx101Gg$pdxyhgLZLzjYDA</ID>
<Name123</Name></List>
<List>
<ID>gWmoJWo4UtuypqV5oxmVyewtAPMVARXHnmg</ID>
<Name>456</Name>
</List>
.
.
.
.
.
.
.</Items>
</Lists>
I will many number of List nodes in the resposne message and need to get ID as the output value where the Name field = 456(which will be one).
I am using the below code -
AbstractTrace trace = container.getTrace();
String ID ="";
try
{
/* Determine a channel (Business system, Communication channel) */
Channel channel = LookupService.getChannel("BC_Middleware","PI_Receiver");
/* Get an accessor for the soap channel */
SystemAccessor accessor = null;
accessor = LookupService.getSystemAccessor(channel);
/* Construct the REST Request Message*/
String loginxml ="<?xml version=\"1.0\" encoding=\"UTF-8\"?><ns0:definitionId>definitionId</ns0:definitionId>";
InputStream inputStream = new ByteArrayInputStream(loginxml.getBytes());
/* Create xml payload */
Payload payload = LookupService.getXmlPayload(inputStream);
/* Execute lookup.*/
Payload RESTOutPayload = null;
RESTOutPayload = accessor.call(payload); /*The SOAP call is made here and the response obtained is in the RESTOutPayload.*/
/* Parse the Payload to get the REST Response back.*/
InputStream inp = RESTOutPayload.getContent();
DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document document = builder.parse(inp);
XPathExpression expr = xpath.compile("//Lists/Items/List[Name = '456']");
NodeList List = (NodeList) expr.evaluate(document, XPathConstants.NODESET);
if (List.getLength() == 0 ){ // If no such Custom Field is found
result.addValue("") ; // Blank value is added to the output
}
else{ // If the desired Custom Field is found
Node listnode = List.item(0); // index is 0 since there is only one value available under this node and no looping needed
String ID = listnode.getFirstChild().getNodeValue() ; //Value is fetched here
result.addValue(ID) ; // fetched value i added to the output.
}
}
catch (Exception e)
{
trace.addWarning("Error" + e);
}
I am not able to execute the UDF its giving error - cannot find symbol xpath. and i added all the libraries (org.w3c.domain, javax.xml.xpath.*)
Please help me on this
Thanks & regards
narayanareddy B