I want to evaluate the value of SEATID.
Find my code below.
String res2[0] = "40B";
vars.put("SEAT_ID",res2[0]);
When i am trying the get the value of SEATID in a string i am not getting the actual value of SEATID.
String otherSampler = vars.get("{"seatCode":"${SEAT_ID}");
Output is coming as : {"seatCode":"${SEAT_ID}
Expected output : {"seatCode":"40B"}
I am wring the code in Beanshell pre processor. Please help.
You need to use vars.get on SEAT_ID
String otherSampler = "{\"seatCode\":\"" + vars.get("SEAT_ID") + "\"}"
Your code is wrong. Try using this for declaring SEAT_ID variable:
vars.put("SEAT_ID","{\"seatCode\":\"" + res2[0] + "\"}");
Then you could use:
String otherSampler = vars.get(SEAT_ID);
To get:
{"seatCode":"40B"}
Related
I am trying to convert the hex value (coming as part of content of the flowfile) 2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36 using fromRadix() EL in UpdateRecord processor. Below is the code I have used
${field.value:isEmpty():not():ifElse('${field.value:fromRadix(16)}','${literal("")}')}
But am getting error, "will route to failure: For input String "2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36"
I tried it through Groovy with the below code, it is working fine.
def data1 = '2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36'
BigInteger x = new BigInteger(data1,16)
println "original output: " + x
Output is coming as
original output: 19928446223359820201840237302010524452213876686816802601399388669528806869558
Would like to know what is wrong with my UpdateRecord processor code using fromRadix(16)
I ran into something very similar, it seems like the NiFi expression language throws an error when the input value (hex in this case) is a big string.
Instead of this "2c0f19d10da4e92896faf7a92ce26f94d2fe91acdc2a69730731613f7c094a36" try running it for "2c0f19d10da" (subtring of your input) and it works.
Under my jinja file i ve this line
- mockString= "{{ABC}}"
My mockString must have the exacte value "{{ABC}}" where the first letter is " , the second is { the third is also { ect...
Now when converting my template file ; it seems that i sees "{{ABC}}" as a variable , where it tries to interpret and change by its value , what is not my purpose.
How may i pass it as a simple string
Suggestions ??
Try passing it like this {{'"{{ABC}}"'}} this should work
you can try like this :
mockString= \"{{ACB}}\"
Please, take a look at following code:
var platNom = "apero"; // I set the value of my attribute in one variable
var monAttribut = ds.Convives.attributes[platNom]; //this works
var invitants = ds.Convives.query("$(this[platNom] == 'oui') ", {allowJavascript: true});// This does not work
Is there a problem in my syntax?
If I understand correctly you would like to use attribute variable to construct the query string. Then you can do this by simply reference platNom directly.
The correct syntax should be:
var invitants = ds.Convives.query(platNom + " == 'oui'")
Have a need to change the value from String to Long in BeanShell Assertion to do verification.
First Apporach
long balance_after_credit = Long.parseLong(String.valueOf("${balance_after_credit_from_db}"));
Second Approach
long balance_after_credit = Long.parseLong(vars.get("balance_after_credit_from_db"));
For instance, consider am getting a value as '743432545' for the variable balance_after_credit_from_db.
Error
org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval Sourced file: inline evaluation of: ``long token_balance_after_credit = Long.parseLong(vars.get("token_balance_after_c . . . '' : Typed variable declaration : Method Invocation Long.parseLong
Weird thing is sometimes, I didn't get errors and the script is getting passed.
Can anyone please point out where am doing a mistake. TIA.
Inlining JMeter variables into code-based scripts is not something recommended so go for 2nd approach.
How do you know that exactly String is being returned from the database all the time? It easily can be any other object type, in fact any of described in the Mapping SQL and Java Types article. The way more safe approach will be something like:
if (vars.getObject("balance_after_credit_from_db") instanceof String) {
long balance_after_credit = Long.parseLong(vars.get("balance_after_credit_from_db"));
}
else {
log.error("Unexpected \balance_after_credit_from_db\" variable type");
log.error("Expected: String, Actual: " + vars.getObject("balance_after_credit_from_db").getClass().getName());
throw new Exception("Unexpected variable type");
}
So in case of non-String JDBC query result you will be able to see the relevant message in jmeter.log file
See Debugging JDBC Sampler Results in JMeter article for more information on working with the entities coming from databases in JMeter tests
The second option
long balance_after_credit = Long.parseLong(vars.get("balance_after_credit_from_db"));
should work, provided you have a valid numeric variable value. For instance try to run something like this:
vars.put("x", "743432545");
long balance_after_credit = Long.parseLong(vars.get("x"));
It won't return any exception.
The problem is when the variable is not defined, has empty or non-numeric value. Then Long.parseLong will throw a NumberFormatException, which you shold catch and make use of (treat it as assertion failure):
String rawValue = vars.get("balance_after_credit_from_db");
long balance_after_credit = Long.MAX_VALUE; // initialize with some unrealistic value
try {
balance_after_credit = Long.parseLong(rawValue);
}
catch(NumberFormatException e) {
Failure = true;
FailureMessage = "Variable does not contain a valid long. It was " + rawValue + " instead";
}
I am trying to do the following:
String x=null;
Group group = factory.newGroup()
.append("x", x);
context.write(null,group)
With the following scheme:
String writeSchema = "message example {\n" +
"optional binary x;\n" +
"}";<br>
But I get NullPointerException in the append line. Maybe I am missing something in the scheme?
Here the String object itself is null. While writing to the filesystem it tries to get the value of the object which is causing the NullPointerExeception.
String x =null;
System.out.println(x.toString()); // Will cause a NullPointerExeception
Similarly any function call to the object will cause the same.
Try using String x ="null" instead