How to show on the console XML http-response or any of its values

I have a WSO2 Stream Processor App that makes an http-resquest and receives a http-response:

@sink(type='http-request','sinkid',  publisher.url='', @map(type='xml', @payload('{{payloadBody}}')))
define stream SomeStream (payloadBody String, method string, headers string);

@source(type='http-response','sinkid', http.status.code='200', 
@map(type='xml', @attributes(parval='parval')))
define stream responseSomeStream(parval string);

How can I extract any of the data to the console? I tried several ways but none has worked.

What I get on the console after sending the payload is:

{} - Xpath: 'parval did not yield any results. Hence dropping the event : <resp action="read" units="S" user="TheUser" password="xxxxxxx" error="0"><val nodetype="16" node="2" display="u09 S5 Temp." name="u09 S5 Temp." stat="Online" statcode="2" error="0" pending="false" parval="-26.0" units="degc" units_index="4"> -26.0°C</val></resp> (Encoded)

I would like to extract some of the parameters from this XML response such as statcode, parval or units.

1 answer

  • answered 2019-03-14 04:50 Tishan

    Issue is with the mapping you have provided and as mapping is incorrect mapper is dropping the incoming event. Inside the @map annotation @attribute section you should provide correct xpath mappings to extract the attributes you need.Please refer these testcases where it performs custom mappings with xpath expressions.