简体   繁体   中英

Jmeter - JMS Publisher - How to get the value from XML request

I'm trying to get a value from the xml-document which I send from JMS Publisher to JMS Subscriber.

<?xml version="1.0" encoding="UTF-8"?>
<sys1>
    <req>
        <id>123</id>
        <message>hello</message>
    </req>
</sys1>

The document gets transformed. I need to check if the "id"s in xml-document stay the same or not after transformation. When I get "id" from the Subscriber - I just use Post Processor - XPath Extractor and get it.

But I get nothing when I use it in Publisher.

I read some jmeter mans and find that "This test element (XPath Extractor) allows the user to extract value(s) from structured response - XML or (X)HTML - using XPath query language."

Then I've tried to get it with the Regular Expression Extractor, but it only works with a response, too. But how can I get it from the Request?

I think you can get access to the request data only using JSR223 PostProcessor , example code would be something like:

def id = new groovy.xml.XmlParser().parseText(ctx.getCurrentSampler().getTextMessage()).req.id.text()

if you want to store the result into a JMeter Variable you can also do add the next line:

vars.put('id', id)

Once done you will be able to access the extracted value as ${id} where required

in the above code ctx stands for JMeterContext class instance, see the JavaDoc for description of all methods and fields and Top 8 JMeter Java Classes You Should Be Using with Groovy for more information on this and other JMeter API shorthands available for theJSR223 Test Elements

You might also be interested in Apache Groovy - Processing XML chapter of Groovy documentation

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM