camel substring operation- n characters from end of message body - spring

This will probably be a layup for most of you, so I apologize in advance.
I am using Apache camel with spring DSL.
My message body has been converted to a string. I want everything from the 9th to 998th character, preferably using a simple expression. I have tried
<transform>
<simple>${body.substring(8,${body.length}-1)}</simple>
</transform>
but Camel doesn't recognize the subtraction. As such, it will try to convert the string "1045-2" to an integer, and obviously fail. Is there a workaround here?

The following code snippet will work.
<transform>
<simple>${body.substring(8,${body.length()-1})}</simple>
</transform>

Use groovy, javascript etc which is more powerful dynamic programming language
<groovy>request.body.substring(8, request.body.length-1)</groovy>
You need to add camel-groovy as a dependency together with groovy also.
Camel Groovy documentation

Related

How to replace file content which has special character, with dynamic value in JMeter

Can I replace a file content with dynamic content even if the file has special characters.
This is what I get when I try to do that.
and this is how my file looks like
[{"someName": "M`o\c\k","someNumber": "${randomNumber}"}]
and I have a variable configured for ${randomNumber}.
Please check if the below can met your requirement.
Random Variable Config:-
Dummy sampler for the json
JSR223 Post processor to put the dummy response in a variable
Used the variable in HTTP. This is just for demo. Probably, in your case it will be websocket.
Output
Also, groovy provide json support. Below you can check a similar solution based on groovy. Where it is mentioned to escape special character for json.
Jmeter Groovy how can I replace this string with {
Hope this helps.
I was able to solve my scenario by adding a json library to my JMeter, JSON.Simple. I added the jar to my jmeter classpath. Then I was able to a BeanShell PreProcessor.
The Json simple object will not escape the special characters and its much easier to manipulate. So that was great for my use case.

how to use jmeter to update xml to post later

I have a JMeter job that I'm taking the XML response from, updating the XML, then PUT the XML back to update the record. I have ALL the parts, except the XML update part.
I need to update XML root/Settings/HasRetry from not only "false" to "true", but also add other nodes directly under it. Order matters in this XML.
xml to update
Ideas on the best way to do this? I tried a via a simple java script:
java replace
...but the JS pukes on that b/c of the special characters in the XML string.
Ideas?
You have an error in your script, last line should look like vars.put("ResponceData", res); as your current implementation simply ignores the replacement logic.
Also be aware that it is not recommended to use Beanshell for scripting, since JMeter 3.1 users are encouraged to switch to JSR223 Test Elements and Groovy language.
Groovy is Java compliant hence in majority of cases valid Beanshell code will be a valid Groovy code, however it is not recommended to use JMeter Variables references like ${ResponceData} as it will ruin scripts compilation feature and performance will be a big question mark so switch to vars.get('ResponceData') instead.
Example Groovy code for values replacement will look something like:
def str = vars.get('ResponceData')
def res = str.replace(vars.get('findSearch'), vars.get('findReplaceWith'))
vars.put('ResponceData', res)
Demo:
See Apache Groovy - Why and How You Should Use It to learn more about Groovy scripting in JMeter.

how to check that tag does not contain spaces or null as value using regular expression

I am trying to validate a string (containg numbers, alphabets and spaces in between words and also contains trailing and leading white spaces) .I need a regular expression which i can put in response assertion of jmeter
Standard recommendation not to use regular expressions for working with HTML and/or XML.
Go for XPath Assertion instead, using it you can implement your requirement using XPath query like:
//yourElement[#yourTag!='null' and not(contains(#yourTag,' '))]
XPath language is quite easy, at least it is much easier to create and read XPath expressions rather than "regular" ones. Check out XPath Tutorial to get started and How to Use JMeter Assertions in Three Easy Steps guide to learn more about assertions available in JMeter.

What does 'antMatchers' mean?

I am learning spring-boot and for my brain, in order to accept some things, it needs to find a meaningful explanation of those things. Could anybody tell me what "ant" in "antMatchers" means? What has an insect like an "ant" got to do with the mapping between a resource and the path of the REST-call?
I know that this is not a language research forum, but I think that developers have also the right to understand or refuse logical/illogical things.
Thank you ;)
It comes from Apache Ant Project, which is a java build system that utilises an xml scripting language. Here is the website Apache Ant Home and in Spring Doc for AntPathMatcher it says "Part of this mapping code has been kindly borrowed from Apache Ant." So "antMatchers" means an implementation of Ant-style path patterns in mappings.
The term comes from the archaic build system, Apache Ant. In Ant paths were matched against a simple pattern containing * symbols meaning any string, and ** meaning 'recursive' descending any number of directories/folders. So, an ant-matcher like this: /a/b/*/d/**/z could match: /a/b/w/d/x/y/z because the w bit is matched by * and the /x/y/ bit is matched by **.

How to use parameter in Ireport 4.5 when using xpath and xml as Datasource

Does anyone know how to use a parameter within and xpath in Ireport. I am using 4.5
I have something like this that works:
<fieldDescription><![CDATA[origin/localizedNames/name[#lang = "en"]]]></fieldDescription>
and what i want to do is something like
<fieldDescription><![CDATA[origin/localizedNames/name[#lang = "$P{lang}"]]]></fieldDescription>
Where lang is my parameter... but it does not seem to work and i cant find any example on the net.
thanks in advance,
Dimitri
You can use parameters in XPath expressions.
The sample:
<queryString language="xPath"><![CDATA[/Northwind/Orders[CustomerID='$P{CustomerID}']]]></queryString>
You can find the sample in folder %jasperreports%\demo\samples\xmldatasource from JasperReports distribution package.
You can also read this article about XPath using.

Resources