How to use jMeter to extract information in a wddx packet? - xpath

I am a newbie in both using XPath and JMeter. I have an XML file that contains a wddx packet. The following is a sample file. The actual data can contain as many as 100 records at a time.
<wddxPacket version='1'>
<header/>
<data>
<recordset rowCount='2' fieldNames='FIELD1, FIELD2' type='coldfusion.sql.QueryTable'>
<field name='FIELD1'>
<string>MyValue1</string>
<string>MyValue2</string>
</field>
<field name='FIELD2'>
<string>MyValue3</string>
<string>MyValue4</string>
</field>
</recordset>
</data>
</wddxPacket>
What I need to do is to loop through the XML file based upon the row count specified in the recordset tag and then extract the string values in FIELD1, FIELD2, etc. and use them in some other WebService (SOAP) Sampler. Just to make sure that I can extract the value, I am using the JMeter function, XPath. The XPath call is as follow (I am trying to get MyValue1),
${__XPath(c:\test.xml, /wddxPacket/data/recordset/field[#name='FIELD1']/string)}
Just to make sure that the file reading part is correct, I use the FileToString() function and assign the content into a variable. Based upon what I can in the Debug Sampler, the variable does show the correct content. However, using the above function call to XPath and assign the result to a variable, the variable is blank. Here are my questions, as far as extracting the values in an XML file is concerned, am I going about the wrong way? If so, what should I do instead?

I don't know JMeter, but this XPath
/wddxPacket/data/recordset/field[#name='FIELD1']/string
does not return a string value, it returns a node set containing the two nodes
<string>MyValue1</string>
<string>MyValue2</string>
If you want only the first node you can use this XPath:
/wddxPacket/data/recordset/field[#name='FIELD1']/string[1]
and if you want just the first string value you could try this XPath:
string(/wddxPacket/data/recordset/field[#name='FIELD1']/string)
Last but not least: are you sure your XML file does not use any namespace? Because if it does you need to specify them explicitly in your XPaths.

Related

Need to extract value from UI using Xpath - using Taiko framework

Am trying to extract value from the field. I can use only Xpath to identify the field.
tried
$(xpath).text() - i think since am tring to extract vale it returned 0
$(xpath).value() - did not work
textBox().value() - inside text box am able to pass id, name. but i need to pass xpath to get the value.
Any solutions?
you can use the evaluate api to return the value.

How to extract QueryString value using NiFi processor/language expression?

I am wondering how to extract a querystring value from incoming url using NiFi.
Initially, I started by implementing UpdateAttribute:
For example, I would like from the incoming url http://smth.net/hello?val=23
to have value of 23 extracted.
Further, I expect that I can use that extracted value by referencing it in following way:
(InvokeHttp processor) http://some.net/getValues?id=${q}
Any hints appreciated!
Edited question:
The flowfile inspect after extracting query string looks like:
you could use UpdateAttribute with replaceAll (regular expression):
${url:replaceAll('.*[\\?\\&]val=([^&]*).*','$1')}
maybe regexp could be optimized...
Actually, the easiest possible way to retrieve a query string value is by using NiFi's expression like: ${http.query.param.[keyNameOfQueryString]}.. So, if the request URL is 127.0.0.1/hello?val=23 then the NiFi expression would be ${http.query.param.val}
Other way to do is using regex, as daggett suggested, but in my case I had to do the following:
${http.query.string:replaceAll('val=(\d+).*', '$1')}
Note http.query.string in place of url.

Mule ESB: How to use xpath expression on session variable?

I have a requirement to extract some information form session variables. The session variables Type is String and contains XML. i tried XPATH expression like -
xpath('//tns:CreateUpdateRQ/tns:RequestInfo/sns:requestSourceID',sessionVars.originalMessage)
however I get exception stating "Could not find transformer NULL Payload to Document". I tried MEL like - #[sessionVars.originalMessage.CreateUpdateRQ.RequestInfo.requestID]. But it's not working either.
How can I extract information from session variable of Type string holding XML.
P.S. I can set the payload to sesion variable & use xpath but it's not suitable for my case because I need to extract the information from session variable 7 pass it as argument to datamapper.
Appreciate you help on this.
To facilitate reading the xml file, I recommend transforming String (Object) to xml, for example:
<xml:object-to-xml-transformer />
then
<logger level="WARN" message="#[xpath://soapenv:Envelope/soapenv:Body//...]" />
In short, make sure the payload is XML type, you can by setting it
<set-property propertyName="Content-Type" value="text/xml" />

Jmeter - values from Regular expression extractor is not getting written in the file

I have added a regular expression as below in order to extract the response value inside the xml.
p400="http://newman.services.premium.hellocorp.com">(.+?)</p400:newman></soapenv:Body>
the reference name is "output_xml"
I have added a simple data writer as well and added "output_xml" to the sample variables in Jmeter properties file also. Still I am not able to see the xml getting written in the file.
Please advice me on this. Thanks!
I'm not sure, that it's possible with simple file writer, try FlexibleFileWriter plugin http://jmeter-plugins.org/wiki/FlexibleFileWriter/?utm_source=jpgc&utm_medium=link&utm_campaign=FlexibleFileWriter
And have you checked, that this extractor works on your data?
Try to add Debug Postprocessor (ensure that "JMeter variables" is set true) and View Results Tree elements to you project and inspect variables.
The given xml formats
p400="http://newman.services.premium.hellocorp.com">(.+?)</p400:newman></soapenv:Body>
You need to update the following regex formats to extract the response values
Regular expression formats
http://newman.services.premium.hellocorp.com">(.+)</p

In a blueprint.xml route, call a propertyplaceholder using an xpath returned value

I have a blueprint.xml in which I write some routes for an ESB.
I want to get values from an XML file passed into the route.
I want to then use these values to make up a dynamic property key name and call the properties file and get the matching property (all within the route). I want to avoid having to create a Java processor due to the overhead of instantiating this each time.
Essentially I want to do this:
<from uri="file:C:/myfilelocation?"/>
<to uri= {{<xpath>//company</xpath>+<xpath>//branch</xpath>}}/>
So in blueprint you call a property using {{}}
I am trying to place the xpath values as the property key inside of the property {{}} tags. In my properties file I have a mapping for each company/branch combination like so:
company1branch1=http://thiscompany.com
company2branch2=http://someothercompany.com
Any way to do this, e.g. some sort of escape characters?
The < to > is for static uris, if you want to use dynamic runtime computed uris, then you should use the recipient list EIP: http://camel.apache.org/recipient-list.html that allows to send a message to a recipient calculcated at runtime.
This is also describer in this FAQ: http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html
Though with the xpath, you would need to set them as headers first.
Something a like:
<setHeader headerName="company">
<xpath resultType="java.lang.String">/xxxx</xpath>
</setHeader>
...
<recipientList><simple>{{${header.company}${header.branch}}}</simple></recipientList>
Also the recipient list can send to 2+ destinations, the separator is by default comma. But you can configure that. See the links above.

Resources