Accessing the parameter by dynamic name - apache-nifi

How to access the parameter #{...} in Process configuration field if its name needs to be changed dynamically (for example, the name of this parameter is contained in some FlowFile attribute OR the name generating using expression language).
Illustrative example – for the LogMessage process, I have prepared several parameters in (msg1, msg2, msg3 etc.) that I would like to output depending on the attribute numofmessage

You can do it using evaluateELString()
${literal('{dynamic_${name}}'):prepend('#'):evaluateELString()}

Currently you cannot use EL inside of a parameter reference. If you put something like #{${abc}} it will look for a parameter named ${abc} and won't find one so it will be invalid.
You can only do the reverse, use parameter inside of EL, for example ${ #{abc}:replace('xxx', 'zzz') }.
In general, parameters are meant to be a better version/replacement for the existing variables functionality, but in this case variables may work better for you since variables are referenced through EL.

Related

Is it possible to add an object refernce User Defined Variable in JMeter?

I can see that User Defined Variables can populate vars with string values only. Is there a way to populate an object reference User Defined Variable in User Defined Variables element.
I have tried as UDV values something like ${__groovy(new java.util.concurrent.ConcurrentHashMap())}. But this way leads to some string retrieved from the variable later.
I have even tried to use side effects of User Defined Variables groovy scripts like ${__groovy(vars.putObject("key", new java.util.concurrent.ConcurrentHashMap(); "assigned")}. But this one leads to some JMeter compilation error while being syntactically OK groovy script in my opinion.
I have tried using scripting pre-processors put on top of the test plan like one of SO answers suggested but they work before each sampler in the tree and thus do not what is intended do.
I still can't find a way to initialize an object reference variable in JMeter at the test plan initialization phase hijacking the thread initializing UDVs.
I know of possibilities to populate vars with putObject(<key>, <reference value>) from within scripting elements like JSR223/BeanShell/some others sampler/pre-processors etc.
But I want to populate the vars for all my thread groups at the initialization of the test plan in order to avoid using props imposing synchronized lock penalty on each put/get call. And there is no possibility to add a sampler at the top of the test plan.
EDIT after accepting correct answer by Dmitri T (for those who want to know the answer right away in more clear form):
${__groovy(vars.putObject("<key>"\, new HashMap()); "virtually anything")}
is correct (while indirect) way to populate an object reference variable in UDV test plan element.
while being syntactically OK groovy script in my opinion.
it's only your opinion, look at jmeter.log file and you will see interpretation error there
As per 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. For example:
${__time(EEE\, d MMM yyyy)}
the correct syntax would be something like:
${__groovy(vars.putObject('key'\,new java.util.concurrent.ConcurrentHashMap()),)}
Demo:
More information: Apache JMeter Functions - An Introduction

Dialogflow CX - using sys.person gives wierd output

https://i.stack.imgur.com/k1bZD.png
I am using sys.person to capture the person's name. Is there any way for just 'john' and not the entire {"name": "john"} to show instead? I want to avoid sys.given-name and sys.last-name since dialogflow says they are deprecated.
Do you have your entity configured as a list? If it is a list, you probably have to output the parameter like $session.params.name[0].name.
If it's not a list, $session.params.name.name would work, but in that case I suggest you change the entity name to person, as it would be more readable to see $session.params.person.name
From your screenshot, it looks like your parameter is an isList parameter.
I have checked today the behavior of static responses when referencing isList parameters and it seems that we can now display the list of values for a certain parameter without the array index in the responses using the format: $session.params.parameter-id.
In your case, it would be:
$session.params.name.
In addition, if you want to reference a specific array index in an isList parameter, you can use the format $session.params.parameter-id[i]. In your case, it would be $session.params.name[0]
or if you want to get the original value you can reference it as $session.params.name[0].original

How to use response field in a new request in Jmeter

I have this issue that I want to solve.
I want to create a new http request using field from previous response
I send a request
I used Json extractor to move the response string to a variable (let call this string nurl)
I used Regular expression and move the field that I want to "Reference Name"
(meanning from nurl I just want tt_cid)
Now I want to make a new call, and use that field tt_cid in my new call
How I shall call tt_cid? since it is not passed as User Defined Variables,
when I use tt_cid, I do not think J meter know it, since it is not written there, I just pulled it from the response.
Provided a Pic of what I have done
Regards to you all
Short answer call it ${tt_cid}.
since it is not passed as User Defined Variables, when I use tt_cid,
I do not think J meter know it,
For your understanding add Debug Sampler after Regular expression,
You will see all your JMeter variables, including tt_cid, which can be called as other variables ${tt_cid} inside other Samplers.
It's called Reference Name and not Variable Name because it's more complicated, You should read JMeter's Regular Expression to understand how it works internally, But basically it saves more than just 1 Variable.

MVC3 razor remote validation - Controller argument is always empty

I can call the controller but the argument (string) is always null.
All the examples I have found name the controller argument the same as the property we are validating remotely, sounds good/easy, but if you look at fiddler what is really being passed in is the name attribute from the input statement. Well that is problematic in that it is a subscripted name something like Person.EMailAddresses[0].Address, well I can't name my controller parameter like that.
So how do I get around this? There must be a way to specify the controllers parameter name in the remote() attribute?
It cannot be done using the default RemoteAttribute. This is a link to an example I posted of a reusable remote validation attribute, where you can specify the name of the controller, action and the name of the variable used to pass the value to the action.

Using parameters as user Defined Variables?

We run our tests in non gui mode and pass in various parameters like Server, port, threads etc. We'd also like to run our test in GUI mode, and be able to change these parameters in the GUI.
What I wanted to do, was use 2x User Defined variable objects, and have one with static data we can edit, and another with parameters. That way the actual test plan doesn't change, but we can set variables as parameters, and just disable the static data one. Or disable the parameterized one when we want to run with static data.
But this doesn't seem to work - no errors nothing.
I do something similar, but I used a UDF for this.
What I did was set up my variables and use default values.
VARNAME VALUE
otl_PROTOCOL ${__P(otl_protocol,https)}
otl_PORT ${__P(otl_port,443)}
otl_THREADS ${__P(otl_threads,1)}
otl_REPS ${__P(otl_reps,1)}
otl_RAMP ${__P(otl_ramp,0)}
I did one for server name as well. This way, I can use the defaults here or I can pass in parameters in either the command line args or in my user.properties. This works very well for me.
How are you passing in values from non-GUI mode? via CSV, using properties, User-Parameters, etc.?
If CSV, this is an easy fix. Simply create a User Defined Variables (UDV) object at the Test Plan Level and "hard code" all your parameters (Server, port, etc.). Keep your CSV config. If you run in GUI mode, disable the CSV and enable the UDV. When you save the file, keep the CSV enabled and the UDV disabled - that way when you run from non-GUI it'll read the CSV file.
If using properties, I would do the following: Create a UDV with all your parameters (Server, etc.). Before entering values, copy the component so you have TWO identical UDVs. In UDV 1, enter the property value from the command line. In UDV 2, enter the "hard coded" values. Throughout your script, replace any references to the properties with variable references. It would look something like this:
UD1: UD2:
Name Value Name Value
SERVER ${__P(Server)} SERVER devdomain.com
PORT ${__P(Port)} PORT 4111
Some HTTP Request
Domain: ${SERVER}
If using user-parameters, it would be the same concept as above.
Actually i am using a function named as regular expression for getting value.
here i have to use variable under variable because there is lots of value with same boundary, so i have selected one paragraph as ${ABC} and fetching value from this paragraph ${XYLEM}. both the variable created as regular expression.tried with ${__V(ABC${XYLEM})};
${__setProperty{Search_Investment_Banking,$Investment_Banking}};

Resources