String replace function issue - jmeter

I used string replace function in jmeter script and was working fine when I ran the script on the local machine but when the same script was run on the server, it is showing an error.
The function used is : ${__strReplace(${C_Create_Escape},",\\\",)}
where create escape is a regular expression.
On server showing 400 error not passing the string replace function.
Error:
"timestamp":1547805846520,"status":400,"error":"Bad Request","exception":"org.springframework.http.converter.HttpMessageNotReadableException","message":"Could not read document: Unexpected character ('\\' (code 92)): was expecting double-quote to start field name\n
at [Source: java.io.PushbackInputStream#463eb3f3; line: 1, column: 2804] (through reference chain:
com.acn.hps.gpp.gibs.dto.FormRequestDTO[\"gibsFormDTO\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Unexpected character ('\\' (code 92)): was expecting double-quote to start field name\n at [Source: java.io.PushbackInputStream#463eb3f3; line: 1, column: 2804] (through reference chain: com.acn.hps.gpp.gibs.dto.FormRequestDTO[\"gibsFormDTO\"])","path":"/form/createOrEditForm"}

According to JMeter Documentation:
If a function parameter contains a comma, then be sure to escape this with "\", otherwise JMeter will treat it as a parameter delimiter.
This restriction has a side-effect: if you need to pass a backslash - you need to escape it with another backslash
So basically if you pass "a" to your function you will get \"a\" as the result:
While your server expects it to be escaped with the double slash, to wit \\"a\\"
My assumption is that you will need to add some more backslashes in order to be compliant with both JMeter Functions syntax and whatever your server expects. The resulting syntax would be:
${__strReplace(${C_Create_Escape},",\\\\\\\",)}
Check out Apache JMeter Functions - An Introduction article for more information on JMeter Functions concept.

Related

Can I pass a json object as value for a cli flag in go?

I am using urfave/cli for my go program and I would like to have a cli flag that reads a json value like this one:
{"name":"foo","surname":"var"}
I am currently reading that variable as a cli.StringFlag which returns a string. Then, I was planning to json.Unmarshall it but it does not work. The problem is that the returned string by the cli library is like this:
[{name foo} {surname var}]
which is not a json anymore.
Is there a way to achieve this? Note that if it returned a simple map, that would work too
for Linux, try to pass the paramaters with shell escape
#!/bin/bash
echo "{\"name\":\"foo\",\"surname\":\"var\"}"
in go program, just marshal this string parameter
The issue is that the shell (bash, ksh, csh, zsh, ...) interprets
{"name":"foo","surname":"var"}
as a sequence of bareword and quoted word tokens:
Token Type
Value
bareword
{
quoted word
name
bareword
:
quoted word
foo
bareword
,
quoted word
surname
bareword
:
quoted word
var
bare word
}
As it happens, a comma (,) is a shell operator, used for arithmetic, and that essentially gets discarded (at least in zsh, what I use).
The whole is then spliced together to get
name:foo surname:var
You can see this in action by opening your shell and executing the command
echo {"name":"foo","surname":"var"}
If, however, you quote your JSON document with single quotes ('):
echo '{"name":"foo","surname":"var"}'
You'll get what you might expect:
{"name":"foo","surname":"var"}
Note, however, that this will fail if the text in your JSON document contains a literal apostrophe/single quote (', U+0027), so you'd want to replace all such occurrences within the JSON document with \, to escape them.

Assigning a string containing colon (:) and minus sign (-) in bash to a local variable

I am trying to assign an AWS ARN value to a local bash variable as shown in the function below
function attach () {
let lb="arn:aws:elasticloadbalancing:us-west-1:1234334545:loadbalancer/app/myservice/ab3434dc0f";
# other processingin
}
Which is leading to error saying
let: lb=arn\:aws:elasticloadbalancing:us-west-1:1234334545:loadbalancer/app/myservice/ab3434dc0f: syntax error: invalid arithmetic operator (error token is "\:aws:elasticloadbalancing:us-west-1:1234334545:loadbalancer/app/myservice/ab3434dc0f")
After searching a bit, I found out that the colon (:) operators does a lot of things in bash. And looking at error here, I guess it is trying to assign rest of the string to arn. However, I could not find a way to escape this behaviour.
Thanks in advance.

YAML store expression language

I am trying to store an expression language in YAML file
"name": "${foo.data:toLower().equals('hello')}"
I tried putting '\' in front of '$' and {}, but it doesn't work.
I just want to set the "name" key to the expression language above.
Failed attempts results name key to get a property with "toLower().equals('hello')"
If you put a backslash (\) in front of the $ within the double quoted string, you should get an error because \$ is an unknown escape sequence in YAML.
If you don't get that error, your parser is broken, but you might be able to get around that by using double backslashes:
"name": "\\${foo.data:toLower().equals('hello')}"
(you may also need them for the { and })

Test AWS lambda function via cli

I want to test a lambda function via CLI instead of the AWS Management console. (Looking to automate function testing by making a bash script)
I've read the documentation: http://docs.aws.amazon.com/cli/latest/reference/lambda/invoke.html
I am trying to invoke the lambda function with a json event payload. My bashcode looks like this:
#!/bin/bash
name="arn:aws:lambda:euwest1:100000000000:function:foo"
invoketype="Event"
payload="{'account':'100261334439', 'region':'eu-west-1', 'detail-type':'Scheduled Event', 'source':'aws.events', 'time':'2017-07-16T03:00:00Z', 'id':'178710aa-6871-11e7-b6ef-e9b95183cfc9', 'resources':['arn:aws:events:eu-west-1:100000000000:rule/run_everyday']}"
aws lambda invoke --function-name "$name" --invocation-type "$invoketype" --payload "$payload" testresult.log
I am getting the error:
An error occurred (InvalidRequestContentException) when calling the Invoke operation: Could not parse request body into json: Unexpected character ('a'
(code 97)): was expecting double-quote to start field name at [Source: [B#7ac4c2fa; line: 1, column: 3]
I believe I am providing the payload in wrong format, but the documentation has no example, it just says that the datatype is 'blob'. I did some searching but only found info on BLOB (binary large object), but I'm pretty sure this is not what the documentation is referring to.
I have tried without the outer double quotes and replacing all the single quotes with double quotes, but all of these give the same error.
tl;dr
Correct (normally): $ aws lambda invoke --function-name myFunction --payload '{"key1":"value1"}' outputfile.txt
Correct (Windows): aws lambda invoke --function-name myFunction --payload "{""key1"": ""value1""}" outputfile.txt
OP's specific question is already answered correctly; this answer is for the benefit of those ending up here with slightly different circumstances from OP. What OS are you using? If its Windows, then you are likely pulling your hair out over single and double quote issues.
Windows command line does not understand single quotes, and double
quotes within a quoted string must be escaped as two double quotes
("").
Credit (normal): AWS documentation
Credit (Windows): Hail Reddit!
valid JSon should have key and value between double quotes
so you should have the payload attribute written as
payload='{"account":"100261334439", "region":"eu-west-1", "detail-type":"Scheduled Event", "source":"aws.events", "time":"2017-07-16T03:00:00Z", "id":"178710aa-6871-11e7-b6ef-e9b95183cfc9", "resources":["arn:aws:events:eu-west-1:100000000000:rule/run_everyday"]}'

Escaping double quotes - Prepared Statement in JMeter

I am trying to execute a stored procedure in JMeter using JDBC Request Sampler. One of the parameters include XML that contains quotes
I am getting the following error:
Response message: java.io.IOException: Cannot have quote-char in plain field:[ <xmlns:r="]
The setup:
QueryType: Prepered Update Statement
SQL Query: {CALL SPINSERT(?, ?)}
Parameters Values: Y, <xmlns:r="">
Parameters Types: CHAR, VARCHAR
I suppose I need to escape the double quotes, any ideas, how this should be done properly?
It's actually as per documentation on JMeter website, but the problem appeared to be that you cannot have a white space after the last double quote.
The list must be enclosed in double-quotes if any of the values
contain a comma or double-quote, and any embedded double-quotes must
be doubled-up, for example: "Dbl-Quote: "" and Comma: ,"

Resources