SOAP UI Property transfer from JDBC request into SOAP Request - jdbc

I have successfully created a JDBC request which is obtaining data from a db in the following XML:
<Results>
<ResultSet fetchSize="64">
<Row rowNumber="1">
<POLICY>9999</POLICY>
<CUSTOMER>00001</CUSTOMER>
</Row>
</ResultSet>
</Results>
I have a SOAP Request and I am trying to pass in both policy and customer values into specific locations on my request. I have set up a Property Transfer step to facilitate this.
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:v1="http://www.xxxxxxxxx.com/services" xmlns:v11="http://www.xxxxxxxxx.com/types" xmlns:v12="http://www.xxxxxxxxx.com/common">
<soapenv:Header/>
<soapenv:Body>
<v1:ReqMessage>
<v11:ServiceHeader>
<v11:CommonHeader>
<v11:ServiceName>Treatment</v11:ServiceName>
<v11:DateTimestamp>2017-02-10T10:51:00.000</v11:DateTimestamp>
</v11:CommonHeader>
<v11:ClientHeader>
<v11:SourceSystem>System</v11:SourceSystem>
</v11:ClientHeader>
<v11:SecurityHeader>
<v11:Username>9A</v11:Username>
</v11:SecurityHeader>
</v11:ServiceHeader>
<v1:ServiceBody>
<v12:TreatmentRequest>
<v12:PolicyNumber></v12:PolicyNumber>
<v12:MemberNumber></v12:MemberNumber>
</v12:GetTreatmentTypesRequest>
</v1:ServiceBody>
</v1:GetProdAndTreatTypesReqMessage>
</soapenv:Body>
</soapenv:Envelope>
I'm struggling to know the Xpath for both source and target to insert into the Property Transfer step.
I am not using SOAP UI Pro.

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>

Validate XML against 2 XSD

I'm trying to parse and validate a SOAP request with SAX. Two XSD are necessary, one for SOAP envelope (http://schemas.xmlsoap.org/soap/envelope/) and the one I defined. I cannot find a way to properly validate the request against these two XSD.
Here's the code I use to parse the request and validate it against soapenv.xsd. It works fine. If I specify my XSD instead, the validation fails with "Cannot find the declaration of element 'soapenv:Envelope'".
SAXParserFactory factory = SAXParserFactory.newInstance();
factory.setNamespaceAware(true);
factory.setValidating(true);
SAXParser saxParser = factory.newSAXParser();
saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaLanguage", "http://www.w3.org/2001/XMLSchema");
saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", MyClass.class.getResourceAsStream("/xml/soapenv.xsd"));
InputSource is = new InputSource(MyClass.class.getResourceAsStream("/xml/request.xml"));
XMLReader reader = saxParser.getXMLReader();
reader.setContentHandler(new MyHandler());
reader.setErrorHandler(new MyErrorHandler());
reader.parse(is);
How can I specify a second XSD?
Is there a better way to parse and validate SOAP requests?
EDIT
As proposed, I created thirdpty.xsd that imports my two XSDs.
<?xml version="1.0" encoding="UTF-8"?>
<xs:schema targetNamespace="thirdparty:general"
xmlns="thirdparty:general"
xmlns:xs="http://www.w3.org/2001/XMLSchema">
<xs:import schemaLocation="D:\ucfed\ValidateWSDL\src\xml\soapenv.xsd"
namespace="http://schemas.xmlsoap.org/soap/envelope/"/>
<xs:import schemaLocation="D:\ucfed\ValidateWSDL\src\xml\Presence.xsd"
namespace="thirdparty:presence"/>
</xs:schema>
I specify this new XSD for the validation:
saxParser.setProperty("http://java.sun.com/xml/jaxp/properties/schemaSource", MyClass.class.getResourceAsStream("/xml/thidpty.xsd"));
But still, only the SOAP envelope XSD is used for validation. If a modify one element from my other XSD, the validation does not detect it.
Here is the xml I am trying to validate
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="thirdparty:presence">
<soapenv:Header/>
<soapenv:Body>
<urn:getPresenceQuery>
<urn:origAccount uri="test#origin.com"/>
<urn:destAccount uri="test#destination.com"/>
</urn:getPresenceQuery>
</soapenv:Body>
</soapenv:Envelope>
Other ideas ?
Write a driver schema document which imports the other two; validate against the driver.

Xpath Post Processor : extract node content from a SOAP response

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.

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