how to pass null or numeric value to http request variable in jmeter - casting

I am having one http request as shown below to which I am passing value from jdbcPreProcessor query.
But it throws Could not convert string to integer: ${tooth_1,}.
In my case, From my jdbcPreProcessor I will get value either as null or integer. And why this failing is because when my ${tooth_1} fetches value from jdbcPreProcessor , it fetches null to which it treats as string. so where should I do typecasting and how?
Treatments": [
{
"tooth": "${tooth_1}",
}
],

My expectation is that the application you're testing expects an Integer and you're trying to send a String to it
If the assumption is correct all you need is to remove the quotation marks around this "${tooth_1}" so it would look like:
"tooth": ${tooth_1},
Also make sure that your ${tooth_1} JMeter Variable exists and has the anticipated value, it can be checked using Debug Sampler and View Results Tree listener combination

Related

Regex to truncate a string on nginx

I am trying to use nginx caching features, however we have and endpoint that uses latitude and longitude, so for that, to increase the cache hit ratio, we have to truncate lat and long.
I created a map to ignore last two latitude digits. The problem is the map isn't working, it always returns the original latitude (45.45452).
Consider $arg_latitude being 45.45452, the expected result is 45.45.
map $arg_latitude $rounded_latitude {
default $arg_latitude;
~\d+\.\d\d $arg_latitude;
}
Any idea why isn't working?
The result of your map is always the original value of $arg_latitude, because that is the value that you have inserted in the right hand column.
You need to add a capture to your regular expression and use that as the new value.
For example:
map $arg_latitude $rounded_latitude {
default $arg_latitude;
~^(?<rounded>\d+\.\d\d) $rounded;
}
Use of a named capture is recommended, as a numeric capture may not be in-scope at the point where $rounded_latitude is evaluated.
See this document for more.

Server variable UNENCODED_URL contains strange value instead of encoded slash

We have a legacy IIS DLL that uses GetServerVariable (MSDN) to retrieve the value of UNENCODED_URL. When accessing the URL:
https://example.com/a%2Fb
the value retrieved will look like this:
/path/to/server.dll/a0.000000b
which is strange, because it should look like this:
/path/to/server.dll/a%2Fb
The LPEXTENSION_CONTROL_BLOCK's value of lpszPathInfo (MSDN) has the value:
/a/b
as expected.
Does anybody know why the UNENCODED_URL value looks like this and how can I retrieve the correct value?
If you’re using for example printf to output the value of the environment variable instead of using a debugger, or puts, that will explain it. %2f will be understood as a command to printf to output the first variable argument as a floating point number.
Always output strings with puts or other functions that do not alter the value.

How can I replace text in a Siebel data mapping?

I have an outgoing web service to send data from Siebel 7.8 to an external system. In order for the integration to work, before I send the data, I must change one of the field values, replacing every occurence of "old" with "new". How can I do this with EAI data mappings?
In an ideal world I would just use an integration source expression like Replace([Description], "old", "new"). However Siebel is far from ideal, and doesn't have a replace function (or if it does, it's not documented). I can use all the Siebel query language functions which don't need an execution context. I can also use the functions available for calculated fields (sane people could expect both lists to be the same, but Siebel documentation is also far from ideal).
My first attempt was to use the InvokeServiceMethod function and replace the text myself in eScript. So, this is my field map source expression:
InvokeServiceMethod('MyBS', 'MyReplace', 'In="' + [Description] + '"', 'Out')
After some configuration steps it works fine... except if my description field contains the " character: Error parsing expression 'In="This is a "test" with quotes"' for field '3' (SBL-DAT-00481)
I know why this happens. My double quotes are breaking the expression and I have to escape them by doubling the character, as in This is a ""test"" with quotes. However, how can I replace each " with "" in order to call my business service... if I don't have a replace function? :)
Oracle's support web has only one result for the SBL-DAT-00481 error, which as a workaround, suggests to place the whole parameter inside double quotes (which I already had). There's a linked document in which they acknowledge that the workaround is valid for a few characters such as commas or single quotes, but due to a bug in Siebel 7.7-7.8 (not present in 8.0+), it doesn't work with double quotes. They suggest to pass instead the row id as argument to the business service, and then retrieve the data directly from the BC.
Before I do that and end up with a performance-affecting workaround (pass only the ID) for the workaround (use double quotes) for the workaround (use InvokeServiceMethod) for not having a replace function... Am I going crazy here? Isn't there a simple way to do a simple text replacement in a Siebel data mapping?
first thing (quite possibly - far from optimal one) which is coming to my mind - is to create at source BC calculated field, aka (NEW_VALUE), which becomes "NEW" for every record, where origin field has a value "OLD". and simply use this field in integration map.

Getting Number of Occurrences of String in JMeter

I am analyzing a website that returns text (JSON array), which I'm using HTTP Request element for. What I'm trying to do is check the number of times a string appears in the response, for example a field called "itemname". So I have added a Regular Expression Extractor, put ItemNameVar as the Reference Name, ^itemname$ as the Regular Expression, $1$ for the Template, -1 for Match No, and "NOT FOUND" for Default Value. I've also added an If Controller, which says "${ItemNameVar_matchNr}" == "1", because I expect it to occur only one time. However, it never fails if I set it to a different number. What am I doing wrong here? Thank you.
It looks like to be an issue with your regular expression.
I would suggest using Beanshell Post Processor instead of Regular Expression Extractor as JSON structures aren't very handy to parse with regexes.
Reference Beanshell code will look as follows:
import org.apache.commons.lang3.StringUtils;
int matches = StringUtils.countMatches(new String(data), "itemname");
vars.put("ItemNameVar_matchNr", String.valueOf(matches));
Explanation:
First line - import necessary helper class
Second line - data is a short-hand for byte-array representation of Sampler response. Method countMatches counts number of occurrences of itemname criteria in string representation of response data. Result is saved as matches integer variable
Third line - value of matches is saved as JMeter Variable called ItemNameVar_matchNr
See How to use BeanShell: JMeter's favorite built-in component guide for more detailed explanation of Beanshell scripting in JMeter and small Beanshell cookbook containing JMeter API usage examples.
The approach you are following is absolutely correct.
Please check your Jmeter script. Make sure the next request you are trying to execute after
IF Controller is branch or within Controller
Jmeter IF Controller
Hope this will help.

Request GET parameters in Django

I have a incoming request that looks like this, its from a third part so it´s out of my hands.
/external/endpoint?PRN=1234567&INPUT=1111;ABCDEF&CUSTOMER=555454545
When I print the request parameters in request.GET this is what I get. The INPUT parameter is chopped off into two different ones.
Incoming dict: {u'INPUT': [u'1111'], u'ABCDEF': [u''],u'CUSTOMER': [u'555454545'], u'PRN': [u'1234567']}
I could hack the request URL myself but I was surprised by the default behavior of the request object. Thought it only divided the parameters by "&". Anyone else seen this or know if this is supposed to happen?
According to W3, ";" is actually the preferred parameter separator for a URI.
http://www.w3.org/TR/html4/appendix/notes.html#h-B.2.2
B.2.2 Ampersands in URI attribute values
The URI that is constructed when a form is submitted may be used as an
anchor-style link (e.g., the href attribute for the A element).
Unfortunately, the use of the "&" character to separate form fields
interacts with its use in SGML attribute values to delimit character
entity references. For example, to use the URI http://host/?x=1&y=2
as a linking URI, it must be written <A href="http://host/?x=1&y=2"> or
<A href="http://host/?x=1&y=2">.
We recommend that HTTP server implementors, and in particular, CGI
implementors support the use of ";" in place of "&" to save authors
the trouble of escaping "&" characters in this manner.