Xpath Post Processor : extract node content from a SOAP response - xpath

I have a soap response of this form
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<ns2:Responseto xmlns:ns2="http://xyz.company.com/">
<return>
<objectContent xsi:type="xs:string" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xs="http://www.w3.org/2001/XMLSchema">/path/to/file.txt</objectContent>
<objectType>FILEPATH</objectType>
<rid>111</rid>
<sid>2</sid>
</return>
</ns2:Responseto>
</S:Body>
</S:Envelope>
I wish to extract the object content in jmeter in order to feed to an xpath assertion.
Can anyone suggest how to do this?
I tried //return/objectType but then the DebugSampler shows me that the value of my variable is blank.

Put you XPath Extractor as a child of the Request that has the response you mention.
Configure the extractor like this:
"Main Sample" Only
"Use Namespaces" checked
"Ignore Whitespaces" checked
"Return entire XPath fragment instead of text content" Unchecked
"XPath query" : //return/objectType
I tested it it works.

Related

Execution of xpath failed in Mulesoft

My Mulesoft process is making a call to SuccessFactors API. The /LOGIN call results in a response like this.
<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
<S:Body>
<loginResponse xmlns="urn:sfobject.sfapi.successfactors.com" xmlns:ns2="urn:fault.sfapi.successfactors.com">
<result>
<sessionId>9A95*******A2631B8E820894CA.ps8bsfapi52t</sessionId>
<msUntilPwdExpiration>9223372036854775807</msUntilPwdExpiration>
</result>
</loginResponse>
</S:Body>
</S:Envelope>
I've the following name spaces declared in my namespace manager
<mulexml:namespace-manager>
<mulexml:namespace prefix="S" uri="http://schemas.xmlsoap.org/soap/envelope/"/>
<mulexml:namespace prefix="ns2" uri="urn:fault.sfapi.successfactors.com"/>
<mulexml:namespace prefix="" uri="urn:sfobject.sfapi.successfactors.com"/>
</mulexml:namespace-manager>
I want to read the sessionId into a mule session variable.
<set-session-variable variableName="SESSION" value="#[xpath('//S:Envelope/S:Body/loginResponse/result/sessionId').text]" doc:name="Get Session from Login"/>
But, upon execution I end up in this
<faultstring>Execution of the expression "xpath('//S:Envelope/S:Body/loginResponse/result/sessionId').text" failed. (org.mule.api.expression.ExpressionRuntimeException).</faultstring>
The XPath checks out well on any other tool but for Mulesoft.
Use XPATH with * as namespace, so you dont need to bother about namespace.
#[xpath('//*:Envelope/*:Body/*:loginResponse/*:result/*:sessionId').text]
xpath is deprecated new version of mule.
Update:
#[xpath3('//*:Envelope/*:Body/*:loginResponse/*:result/*:sessionId')]
Hope this helps.

Xpath not working in camel route

I'm sending soap xml through exchange object.When i try to route the request using xpath in apache camel,i'm not able to execute it properly.Please suggest
My Exchange body xml is
<Envelope><Header>
</Header>
<Body>
<Choice>
<Selector>1</selector>
</Choice>
</Body>
</Envelope>
My Camel Route
from(direct:XX)
.to(when(xpath("body()/Choice/Selector/.",String.class)=='1')
.to("direct:X")
.otherwise()
.to("direct:Y")
your Envelope cannot look like that. it must be something like:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Header/>
<soapenv:Body>
...
body()/Choice/Selector/. is not an Xpath. there is no such thing like body() in XPath.
Assuming that you have a SOAP Body content in the Exchange.body processed by some JAX-WS endpoint XPath will be
/Choice/Selector or /Choice/Selector/text() if it is an element with mixed content
BTW: if your Envelope is real example you try to test do not forget to fix your XML - you have wrong <Selector>1</selector> Tag names are case sensitive. It must be <Selector>1</Selector>

How to extract a response value when doing http post using Jmeter

Can anyone please help me here? I'm trying to do an http post in Jmeter, http works fine, but I'd like to extract the LastName value from the response to use in next http request. I've tried several methods using Xpath Extractor but the Debug sampler shows nothing. I've added XPath_Extractor as a child of HTTP Sampler.
what am I doing wrong here?
Here is what I setup in the XPath Extractor
Reference Name = lstname (which is the variable I carry to next http request)
XPath Query = //*[local-name()='LastName']/text()
also tried
/Reply/CustomerData/#LastName
Main Sample checked
Use NameSpaces- checked
Ingnore whitepspaces checked
Here is my http response
<?xml version="1.0" encoding="UTF-8"?>
<dm:reply xmlns:dm="http://www.xx.com/dm" version="1.0">
<Session>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062362"/>
<Reply type="Connection">
<ErrorMessage/>
<ErrorCode>0</ErrorCode>
</Reply>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062504"/>
<Reply type="Execute">
<CustomerData FirstName="" LastName="Moni" Address="SD" Chassis="AWD" CountryOfBirth="" CountryOfOriginFullName= Year="2010">
<RecordSet>
</RecordSet>
<ErrorMessage/>
<ErrorCode>0</ErrorCode>
</CustomerData>
</Reply>
<TimeDate CurrentDateTime="2015-12-16T08:57:21" CurrentMilliseconds="2881062590"/>
</Session>
</dm:reply>
You can use regular expression extractor - Post Processor to achieve this.
You need to fill in following parameters
Reference Name: LastName
The regular expression (would look like): LastName="(.*?)"
Template: $1$
Match : 1
Default Value: NotFound
Use ${LastName} in next request to access extracted value of LastName.
Add debug sampler to check if you are extracting correct value.
Why do you need all this namespaces stuff?
Don't check any boxes in the extractor
Use //CustomerData/#LastName as XPath expression
That's it
By the way, you can evaluate XPath Expressions directly against response using XPath Tester mode of the View Results Tree listener. See How to debug your Apache JMeter script article for more tips on getting to the bottom of your JMeter test issue.

Xpath extractor

Can someone help me with this:
I am using xpath extractor of jmeter to retrieve sessionId value from the below response.
I need the value of the sessionId to be stored in some file, so that i can use that value in succeeding calls..My basic response is as below:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:createUserResponse xmlns:ns2="http://www.musicthp.com"
isNewUser="false"
profileId="32109"
sessionId="ryIlb+E5yj7FReA2w96uag=="
success="true">
<duration>316</duration>
</ns2:createUserResponse>`
In order to use the results in a future call, you simply need to use the "Reference Name" as a variable.
If you configure the Xpath Extractor reference name as sessionID, subsequent calls would use ${sessionID}

Parsing SOAP response using libxml in Ruby

I am trying to parse following SOAP response coming from Savon SOAP api
<?xml version='1.0' encoding='UTF-8'?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
<soapenv:Body>
<ns:getConnectionResponse xmlns:ns="http://webservice.jchem.chemaxon">
<ns:return>
<ConnectionHandlerId>connectionHandlerID-283854719</ConnectionHandlerId>
</ns:return>
</ns:getConnectionResponse>
</soapenv:Body>
</soapenv:Envelope>
I am trying to use libxml-ruby without any success. Basically I want to extract anything inside tag and the connectionHandlerID value.
As you are using Savon you can convert the response to a hash. The conversion method response.to_hash does some other useful things for you as well.
You would then be able to get the value you want using code similar to the following
hres = soap_response.to_hash
conn_handler_id = hres[:get_connection_response][:return][:connection_handler_id]
Check out the documentation
I'd recommend nokogiri.
Assuming your XML response is in an object named response.
require 'nokogiri'
doc = Nokogiri::XML::parse response
doc.at_xpath("//ConnectionHandlerId").text

Resources