You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by SanderW <sa...@performancearchitecten.nl> on 2014/12/31 07:45:38 UTC
How do I replacing null in beanshell by empty string
Hi,
I'm getting the following response from a server (the actual response
contains almost 50 variables):
/var s0={};var s1="John Allen";s0.firstnames=s1;var s2=null;s0.prefix=s2;var
s3="Doe";s0.lastname=s3;
DWREngine._handleResponse('97_1420006799508', s0);/
I'm using BSF PostProcessor to put all the variables in JMeter variables
with the following code:
/var person = null;
function dwrPrototype () {
this._handleResponse = function(handle,myObject){
person = myObject;
};
}
var DWREngine = new dwrPrototype();
(new Function(prev.getResponseDataAsString())())
vars.put("firstnames",person.firstnames);
vars.put("firstnames",person.prefix);
vars.put("firstnames",person.lastname); /
In the Results Tree I the following response data for a Debug Sampler:
firstnames=John Allen
prefix=null
lastname=Doe
If I use the variable prefix later on in a field, the request fails because
it contains ${prefix} instead of null.
I would rather have and empty string ("") filled in the field.
How do I do this?
--
View this message in context: http://jmeter.512774.n5.nabble.com/How-do-I-replacing-null-in-beanshell-by-empty-string-tp5721570.html
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org
Re: How do I replacing null in beanshell by empty string
Posted by SanderW <sa...@performancearchitecten.nl>.
Ah found it.
I was replacing the null with "", but this resulted in:
/var s0={};var s1="John Allen";s0.firstnames=s1;*var s2=*;s0.prefix=s2;var
s3="Doe";s0.lastname=s3;
DWREngine._handleResponse('97_1420006799508', s0);/
So s2 does now not have a value at all.
What I should have done is:
(new Function(prev.getResponseDataAsString().replaceAll("null","\"\""))())
--
View this message in context: http://jmeter.512774.n5.nabble.com/How-do-I-replacing-null-in-beanshell-by-empty-string-tp5721570p5721573.html
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org
Re: How do I replacing null in beanshell by empty string
Posted by SanderW <sa...@performancearchitecten.nl>.
Hi Chaitanya,
It is a little overkill to put this in for each variable (50 times).
I'm more looking for a replace all.
If I use this:
log.info(prev.getResponseDataAsString().replaceAll("null",""));
then I see that the nulls are being replaced, but I can't seem to get it
working in the script.
My programming skills are bad ;-)
--
View this message in context: http://jmeter.512774.n5.nabble.com/How-do-I-replacing-null-in-beanshell-by-empty-string-tp5721570p5721572.html
Sent from the JMeter - User mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
For additional commands, e-mail: user-help@jmeter.apache.org
Re: How do I replacing null in beanshell by empty string
Posted by chaitanya bhatt <bh...@gmail.com>.
if(person.prefix != null)
vars.put("prefix",person.prefix);
else
vars.put("prefix","");
Should work.
Chaitanya M Bhatt
http://www.performancecompetence.com
On Tue, Dec 30, 2014 at 10:45 PM, SanderW <sa...@performancearchitecten.nl>
wrote:
> Hi,
>
> I'm getting the following response from a server (the actual response
> contains almost 50 variables):
>
> /var s0={};var s1="John Allen";s0.firstnames=s1;var
> s2=null;s0.prefix=s2;var
> s3="Doe";s0.lastname=s3;
> DWREngine._handleResponse('97_1420006799508', s0);/
>
> I'm using BSF PostProcessor to put all the variables in JMeter variables
> with the following code:
>
> /var person = null;
>
> function dwrPrototype () {
> this._handleResponse = function(handle,myObject){
> person = myObject;
> };
> }
> var DWREngine = new dwrPrototype();
>
> (new Function(prev.getResponseDataAsString())())
>
> vars.put("firstnames",person.firstnames);
> vars.put("firstnames",person.prefix);
> vars.put("firstnames",person.lastname); /
>
> In the Results Tree I the following response data for a Debug Sampler:
> firstnames=John Allen
> prefix=null
> lastname=Doe
>
> If I use the variable prefix later on in a field, the request fails because
> it contains ${prefix} instead of null.
> I would rather have and empty string ("") filled in the field.
>
> How do I do this?
>
>
>
> --
> View this message in context:
> http://jmeter.512774.n5.nabble.com/How-do-I-replacing-null-in-beanshell-by-empty-string-tp5721570.html
> Sent from the JMeter - User mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@jmeter.apache.org
> For additional commands, e-mail: user-help@jmeter.apache.org
>
>