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" />
Related
I am using restlet to consume a URL.
I am creating a dynamic URL and with XML DSL.
Even if I hard code the parameter values like below
<toD uri="restlet:https://---URL---:443/claims/id/?userId=1&id=25?restletMethod=GET" />
I am getting the following error
Restlet operation failed invoking https://---URL---:443/employee/id/?id=25%3FrestletMethod%3DGET&userId=1
How do I set parameters to these dynamic URLs ?
It looks like you have a second question mark (?) in your query string. ie: id=25?restletMethod=GET
<toD uri="restlet:https://---URL---:443/claims/id/?userId=1&id=25?restletMethod=GET" />
You should probably replace that with another ampersand ( id=25&restletMethod=GET)
I have a complex camel route, which starts with an initialization route, which tries to set the headers with the info from the XML used as input.
I wonder how the route is not being able to parse the XML content, using XPath.
Before calling the route, I print the xml information in my java JUNIT, and it prints correctly, with all xml tags.
So I know the information is being sent as I am expecting.
But that route, which should set the headers using XPath, returns empty to any expression I try to use! I even used a XPath tool to assist me (https://codebeautify.org/Xpath-Tester), to check if was some xpath coding mistake, but I get the results I want from there.
So, let's suppose, I have an XML as:
<bic:Test>
<bic:context>
<bic:memberCode>GOOGLE</bic:memberCode>
</bic:context>
</bic:Test>
So, with the line below:
<setHeader headerName="myHeader">
<xpath resultType="java.lang.String">//<anyTag>/text()</xpath>
</setHeader>
or
<setHeader headerName="myHeader">
<xpath resultType="java.lang.String">//<anyTag></xpath>
</setHeader>
I will see the header with empty content.
I tried so many different things, that finally I decided to print the all the content, using an XPath expression as /.
It will print only the content ("GOOGLE"), not the tags.
Could you please assist me?
Thank you in advance!
This is probably a namespace related issue.
You have to define the bic namespace in the camel context and then use it in the xpath expression.
Have a look at the documentation in https://github.com/apache/camel/blob/master/camel-core/src/main/docs/xpath-language.adoc and particularly in the example of "Using XML configuration"
Also look at "Namespace auditing to aid debugging" for further information about debugging namespace related issues in camel.
Below First part is my code, i have to read my substring logic from xpath.But I dont want the above code to be in my camel context insead i want to read from property file, i wish i could do something like below in second part where substring logic is a key in property file. I am loading my property file from BrigePropertyPlaceholder by Spring.
<xpath>starts-with(substring-after((/*/FullName/text()), 'Mr.'), "Xyz")
</xpath>
<camelContext> ....
<xpath>{properties:substringlogic}</xpath>
</camelContext>
Try with
<xpath>{{substringlogic}}</xpath>
See more details in the Camel docs: http://camel.apache.org/using-propertyplaceholder.html
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.
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.