0 votes
774 views
in Integrations by (21.5k points)

1 Answer

0 votes
by (30.6k points)

How you parse a SOAP response depends on how you called the service:

  • Web service integration (WSDL imported): you never see the envelope - BPM maps the response body to the generated business objects; tw.local.response.customer.name is ready to use. Faults arrive as errors (catch with an error boundary).
  • Raw SOAP text (Java HTTP client, a REST call to a SOAP endpoint, a message from a queue): parse the XML in a script. On BPM 8.x the server-side JavaScript supports E4X (XML literals) - the quickest way; on BAW 20+ E4X is gone and you use the Java DOM / XPath from the script:
// BPM 8.5.x / 8.6 - E4X (server-side script)
var xml = new XML(tw.local.soapText.replace(/^<\?xml[^>]*\?>/, ""));      // strip the XML declaration
var soap = new Namespace("http://schemas.xmlsoap.org/soap/envelope/");
var ns   = new Namespace("http://example.com/customer");
var body = xml.soap::Body;
tw.local.name  = String(body.ns::getCustomerResponse.ns::customer.ns::name);
tw.local.limit = parseFloat(body.ns::getCustomerResponse.ns::customer.ns::creditLimit);

// BAW 20+ / any version - Java XPath (no E4X)
var dbf = javax.xml.parsers.DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true);
var doc = dbf.newDocumentBuilder().parse(new org.xml.sax.InputSource(new java.io.StringReader(tw.local.soapText)));
var xp = javax.xml.xpath.XPathFactory.newInstance().newXPath();
tw.local.name  = String(xp.evaluate("//*[local-name()='customer']/*[local-name()='name']/text()", doc));
tw.local.limit = parseFloat(xp.evaluate("//*[local-name()='creditLimit']/text()", doc));
var fault = String(xp.evaluate("//*[local-name()='Fault']/*[local-name()='faultstring']/text()", doc));
if (fault) throw new Error("SOAP fault: " + fault);

Tips: use local-name() in XPath to ignore namespace prefixes; convert Java strings with String(...) before storing in tw.local; for large responses map only the fields you need; when the same parsing is needed in several places, put it into a toolkit service with the SOAP text in and a business object out. For 8.5.x code that must survive the BAW upgrade, write the XPath version now - E4X removal is one of the classic upgrade breakers.

References

Related questions

0 votes
1 answer 904 views
0 votes
1 answer 3.0k views
0 votes
2 answers 4.7k views
0 votes
1 answer 1.7k views
0 votes
1 answer 1.4k views
0 votes
1 answer 1.2k views
asked May 15, 2016 in Integrations by anonymous
0 votes
1 answer 1.9k views
0 votes
1 answer 1.7k views
0 votes
1 answer 670 views
0 votes
1 answer 2.6k views

723 questions

807 answers

98 comments

4.9k users

Join BPM Community Discord Channel

Welcome to BPM Tips Q&A, Community wiki/forum where you can ask questions and receive answers from other IBM BPM experts and members of the community. Users with 2000 points will automatically be promoted to expert level.
Created by Dosvak LLC
Our Youtube Channel
...