Version: 17.07
Supported Since: 17.01
XPath Extractor processing element can be used to extract a string value from a XML message payload and assign the extracted value to a given scope variable of the message context.
In order to use this processing element, you must first select the Content Extractor dependency from the processor list when you are creating an empty Ultra project. If you have already created a project, you can add this dependency via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Processors list, select the Content Extractor dependency. |
Next |
Message will be emitted from this port after setting the extract value from the XPath as the configured scope variable |
On Exception |
The message context will be sent to this outport if any exception occurred while extracting the provided XPath |
XPath * |
Basic |
XPath to be evaluated over the received XML message payload. |
Variable Name * |
Basic |
Name of the scope variable to be assigned with the extracted String value from the configured XPath. |
Namespaces |
Basic |
If any custom namespaces are being used inside XPath expression, those should be defined as a map with those namespaces as keys and the corresponding namespace URIs as values. |
In the following use case, the requirement is to mediate messages to a header based routing web service while ensuring all the requests contain the required routing header and if there is any message which doesn’t have that header, routing header should be populated by extracting the required content from the received XML message payload via an XPath. Header based routing service expects the request category as the header with the name "Routing_Category". This header value will be used to forward the received request to the actual back end service.
In order to implement above use case you must first select following dependencies when you are creating an empty Ultra project
HTTP NIO Connector from the connector list.
Content Extractor and Flow Control dependencies from the processor list.
If you have already created a project, you can add above dependencies via Component Registry. From Tools menu, select Ultra Studio → Component Registry and from the Connectors list and Processors list, select above dependencies
For the implementation we should first check whether the received message contains the "Routing_Category", if it has that header received request will be directly forwarded to the back end service which will do the header based routing. If the received message doesn’t have the "Routing_Category" header, then request category will be extracted from the XML message payload by executing a pre-defined XPath. Then extracted request category will be set as the "Routing_Category" header before forwarding the request to the actual back end service.
To implement above use case, first let’s create our integration flow named “integrate-with-header-based-routing". Then add an NIO HTTP Ingress Connector and configure the request receiving service path and port.
Next processing element should be the Conditional Evaluator to check whether the received request contains the routing header - "Routing_Category".
Then XPath Extractor processing element should be added to extract the request category from the received XML message. Received XML message would be in the following format.
<Order xmlns="http://adrt.com/processors/xpath/docs">
<ReferenceNo>IR-921348</ReferenceNo>
<ClientID>84840G</ClientID>
<OrderCategory>CheckPrice</OrderCategory>
<Items>
<Item>
<ItemCode>MP192845</ItemCode>
<ItemType>Food</ItemType>
<ItemName>Milk Powder</ItemName>
<ItemDescription>XYZ Milk Powder</ItemDescription>
<ItemCount>60</ItemCount>
</Item>
....
....
<Item>
<ItemCode>SD192845</ItemCode>
<ItemType>Food</ItemType>
<ItemName>Soft Drink</ItemName>
<ItemDescription>ABC Soft Drink 1L</ItemDescription>
<ItemCount>50</ItemCount>
</Item>
</Items>
</Order>
To extract the RequestCategory from the above XML message, XPath Extractor processing element should be configured as below.
Namespaces map should be configured as a resource in project.xpml as below.
After that, Add Transport Header processing element should be added to the add the extracted RequestCategory as a transport header with name "Routing_Category". Finally NIO HTTP Egress Connector element should be added to send the received request message to the actual back end service.
With all above elements, complete integration flow would be like this,
Now run your integration flow and send a request message to the configured request URL to test your integration flow. Once you send a request, check with the flow tracing, you should be able to see that "Routing_Category" transport header will be populated from the RequestCategory value if the header is not available in the original request.