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>
Related
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.
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.
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.
while 'playing around' with Camel using Spring DSL, I came across the following problem. Suppose the expected message flow looks like this:
client sends HTTP POST message with XML body to CAMEL
CAMEL proxies HTTP POST message towards server, with the URI slightly adapted using
info from the received XML body (eg: use XPATH to filter out a certain parameter)
after CAMEL has received a reply, CAMEL sends HTTP PUT message towards server, using parameters out of the XML body received in 1
So something like:
<route>
<from uri="...">
<to uri="...">
<to uri="...">
</route>
Question: how do I store the parameters in Spring DSL in step 1, so that I can use them later in step 3 ?
So, I would like to extract XML parameters out of the XML body of the message received in step 1 and put them into variables, which I then later on can use to compose the message to be sent in step 3.
For extracting the parameters, I was thinking of using XPATH. That looks ok, but I just don't see how to put the output of the XPATH into a variable and then use that variable later on ... (syntax ??)
Note: as you can see, my development knowledge is rather limited ... sorry for that. But it would still be great if someone could help with this :).
you can set store data in the Exchange properties or message headers like this...
.setHeader("ID", XPathBuilder.xpath("/order/#id", String.class))
.setProperty("ID", XPathBuilder.xpath("/order/#id", String.class))
and then retrieve them in a bean/processor from the Exchange like this...
String propId = (String) exchange.getProperty("ID");
String headerId = (String) exchange.getIn().getHeader("ID"); }
I leave you some examples:
<setHeader headerName="token">
<constant>someValue</constant>
</setHeader>
<setHeader headerName="userName">
<simple>${properties:userName}</simple> //from config
</setHeader>
<setProperty propertyName="bodyBkp">
<simple>${in.body}</simple>
</setProperty>
<setProperty propertyName="orderNumber">
<xpath resultType="String">//item[1]/orderNumber/text()</xpath>
</setProperty>
Getter
${exchangeProperty[orderNumber]}
${in.headers.token}
Documentation
Check the simple expression language:
http://camel.apache.org/simple.html
Sometimes looking at the test cases of Camel can be helpful as well, in particular for Spring DSL:
setProperty with Spring DSL
setHeader using XPATH with Spring DSL
simple expression language test
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