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)
Related
I've got a paginated list of cars, on a Spring Boot server, with the parameters sort, range, desc, page, etc to filter and sort by and am generating the URL in Thymeleaf that looks like:
example.com/cars?page=5&sort=mileage
I am wanting to be able to add more parameters to a URL with a few of these already but I'm quite new to this and don't really know how to get the current URL with all the parameters to add more params without losing the previous ones look like
example.com/cars?page=5&sort=mileage&desc=true
I've found an answer to do something like this on Spring but would ideally want to do it on the Thymeleaf template, is this possible?
Get full current url thymeleaf with all parameters
I found that you can get hold of specific parameters in Thymeleaf using ${param.sort} to get hold of the param sort, could something similar to this get hold of all the params currently?
Thanks
If someone is still looking for a thymeleaf template only solution, you could use ${#request.getRequestURI()} with ${#request.getQueryString()} and add your additional parameters via concatenation:
<a th:href="#{${url}}" th:with="url=${#request.getRequestURI()+'?'+#request.getQueryString()+'&foo=bar'}">Link</a>
If you need to escape query parameters, you can use #uris.escapeQueryParam():
<a th:href="#{${url}}" th:with="url=${#request.getRequestURI()+'?'+#request.getQueryString()+'&foo='+#uris.escapeQueryParam('b a r')}">Link</a>
Some further details:
You have to use th:with, otherwise the parser will throw TemplateProcessingException: Access to request parameters is forbidden in this context. in newer thymeleaf versions.
It also works when the current query is empty, the url generator will create a valid url, in my example including one ? and no & in the query part.
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.
How Can i extract value from DWR call using RegEx in jmeter.
In My Script Request Body is something like :
POST data:
`callCount=1`
`page=/abc/xyz.action`
`httpSessionId=`
`scriptSessionId=87F34A5261EFBF481F6D421920EF99F9406`
`c0-scriptName=DWRPostHelper`
`c0-methodName=savePostAsDraft`
`c0-id=0`
`c0-param0=string:447`
`c0-param1=number:933`
`c0-param2=number:0`
`c0-param3=string:Post%20Jmeter`
`c0-param4=string:`
`c0-param5=string:1`
`c0-param6=number:1427199824585`
`batchId=4`
And Response data is as below :
`//#DWR-INSERT`
`//#DWR-REPLY`
`dwr.engine._remoteHandleCallback('4','0',["447","Auto-saved at 17:55"]);`
Need to Extract value 447 from above Response.
is it Possible Using RegEx ? or is there any other way to do the same?
'dwr\.engine\._remoteHandleCallback\('[0-9]','[0-9]',\["([0-9]+)",
This should do it, written from memory, you may need to tweak the syntax a bit. Use $1$ for the template.
Try the following:
dwr\.engine\._remoteHandleCallback\('4','0',\["(.+?)"
Make sure that you set $1$ as "Template"
You can test your regular expressions using View Results Tree listener as follows:
See How to debug your Apache JMeter script guide for more details on how to get to the bottom of failure or unexpected behavior while developing a JMeter Test
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.
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