You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by amelaao <am...@gmail.com> on 2006/08/02 16:22:23 UTC

More on RegEx and BeanShell function

 I think my problem comes from the way I'm referencing this variable created
by RegEx from BeanShell.
My RegEx look like:

ReferenceName:       Attributes
Regular Expression: <ProductAttributes>(.+?)</ProductAttributes>
Template:                $1$
Match No:               1

and the BeanShell function string:

${__BeanShell(String str=vars.get("${Attributes}"); String newstr =
str.replace("<"\,"<p:"); return newstr;, )} .


 I tried many combinations of
                  vars.get("${Attributes}");
                 vars.get("${Attributes_g1}");
                  vars.get("Attributes"); inside this BeanShell but each
returns null, although the RegExpression variable Attributes displayed
through a separate JavaRequest Sampler is perfectly valid, not null,
XML string.

Please help,
 Amela



On 8/1/06, amelaao <am...@gmail.com> wrote:
>
>  so I would like my parameter productAttributes  to get its value from
> this function string I created, but still no results:
> ${__BeanShell(String str = vars.get("Attributes"); String newstr =
> str.replace("<"\,"<p"); vars.put("productAttributes"\, newstr);, )}
>
>  Any more ideas?
>
> Thanks,
> Amela
>
>  On 8/1/06, amelaao <am...@gmail.com> wrote:
> >
> >  To explain this a bit more. This is a sequence:
> > 1. Variable Attributes is returned from a RegEx in a step before.
> > 2. I have a Soap RPC Sampler with a preprocessor - User Parameters. This
> > parameter NewAttributes needs to be  populated with whatever BeanShell
> > function returns in order for that Soap RPC Request to form properly.
> >
> >
> >
> > On 8/1/06, Yanroy <rm...@wpi.edu> wrote:
> > >
> > >
> > > I haven't tried this, and I don't really know what I'm talking about
> > > as I'm
> > > new to beanshell, but I suspect you want to use vars.get("Attributes"}
> > > and
> > > then vars.put("Attributes", newstr) to replace the value in Attributes
> > > with
> > > your new one.  Or if you're just trying to use it immediately without
> > > storing it, perhaps just returning it like you are would work (that
> > > would
> > > make sense, but I'm not familiar with that syntax).
> > > --
> > > View this message in context: http://www.nabble.com/User-Defined-variable-and-BeanShell-function-tf2036135.html#a5602766
> > >
> > > Sent from the JMeter - User forum at Nabble.com <http://nabble.com/>.
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> > >
> > >
> >
> >
> > --
> > Regards,
> > Amela
> >
>
>
>
> --
> Regards,
> Amela
>



-- 
Regards,
Amela


-- 
Regards,
Amela

Re: More on RegEx and BeanShell function

Posted by sebb <se...@gmail.com>.
On 07/08/06, amelaao <am...@gmail.com> wrote:
> I tried ${__BeanShell(vars.get("Attributes").replace("<"\,"<p:"))}
> to begin with, but it didn't work. That was the way I set a user parameter
> in a pre-processor. Once I moved it from a pre-processor to a

What did not work? What happens if you tried just

${Attributes}

on its own in the Pre-Processor? Did you get the value of the variable?

Did you try:

${__BeanShell("${Attributes}".replace("<"\,"<p:"))}

?
> BeanShellRequest Sampler I was able to retrive the new variable afterwards
> without anyproblems.
>
> vars.put("productAttributes",vars.get("Attributes").replace("<","<p:"));
> return;
>
> Still do not understand why the BeanShell function didn't work, but at least
> I got some solution.

Depends on where you used it, perhaps the variable had not been defined yet.

> Thanks for all the help,
> Amela
>
> On 8/2/06, sebb <se...@gmail.com> wrote:
> >
> > On 02/08/06, amelaao <am...@gmail.com> wrote:
> > >  I think my problem comes from the way I'm referencing this variable
> > created
> > > by RegEx from BeanShell.
> >
> > Yes, see below.
> >
> > > My RegEx look like:
> > >
> > > ReferenceName:       Attributes
> > > Regular Expression: <ProductAttributes>(.+?)</ProductAttributes>
> > > Template:                $1$
> > > Match No:               1
> > >
> > > and the BeanShell function string:
> > >
> > > ${__BeanShell(String str=vars.get("${Attributes}"); String newstr =
> > > str.replace("<"\,"<p:"); return newstr;, )} .
> > >
> >
> > ${Attributes} will be replaced by the contents of the variable; you
> > are then looking this up as a variable, which won't exist.
> >
> > Try
> >
> > ${__BeanShell(${Attributes}.replace("<"\,"<p:"))}
> >
> > So long as Attributes does not contain any commas, it should work.
> >
> > If it does contain a comma, try:
> >
> > ${__BeanShell(vars.get("Attributes").replace("<"\,"<p:"))}
> >
> > >
> > >  I tried many combinations of
> > >                  vars.get("${Attributes}");
> > >                 vars.get("${Attributes_g1}");
> > >                  vars.get("Attributes"); inside this BeanShell but each
> > > returns null, although the RegExpression variable Attributes displayed
> > > through a separate JavaRequest Sampler is perfectly valid, not null,
> > > XML string.
> >
> > That is because you are de-referencing the variable twice...
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
>
>
> --
> Regards,
> Amela
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org


Re: More on RegEx and BeanShell function

Posted by amelaao <am...@gmail.com>.
I tried ${__BeanShell(vars.get("Attributes").replace("<"\,"<p:"))}
to begin with, but it didn't work. That was the way I set a user parameter
in a pre-processor. Once I moved it from a pre-processor to a
BeanShellRequest Sampler I was able to retrive the new variable afterwards
without anyproblems.

vars.put("productAttributes",vars.get("Attributes").replace("<","<p:"));
return;

Still do not understand why the BeanShell function didn't work, but at least
I got some solution.

Thanks for all the help,
Amela

On 8/2/06, sebb <se...@gmail.com> wrote:
>
> On 02/08/06, amelaao <am...@gmail.com> wrote:
> >  I think my problem comes from the way I'm referencing this variable
> created
> > by RegEx from BeanShell.
>
> Yes, see below.
>
> > My RegEx look like:
> >
> > ReferenceName:       Attributes
> > Regular Expression: <ProductAttributes>(.+?)</ProductAttributes>
> > Template:                $1$
> > Match No:               1
> >
> > and the BeanShell function string:
> >
> > ${__BeanShell(String str=vars.get("${Attributes}"); String newstr =
> > str.replace("<"\,"<p:"); return newstr;, )} .
> >
>
> ${Attributes} will be replaced by the contents of the variable; you
> are then looking this up as a variable, which won't exist.
>
> Try
>
> ${__BeanShell(${Attributes}.replace("<"\,"<p:"))}
>
> So long as Attributes does not contain any commas, it should work.
>
> If it does contain a comma, try:
>
> ${__BeanShell(vars.get("Attributes").replace("<"\,"<p:"))}
>
> >
> >  I tried many combinations of
> >                  vars.get("${Attributes}");
> >                 vars.get("${Attributes_g1}");
> >                  vars.get("Attributes"); inside this BeanShell but each
> > returns null, although the RegExpression variable Attributes displayed
> > through a separate JavaRequest Sampler is perfectly valid, not null,
> > XML string.
>
> That is because you are de-referencing the variable twice...
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>


-- 
Regards,
Amela

Re: More on RegEx and BeanShell function

Posted by sebb <se...@gmail.com>.
On 02/08/06, amelaao <am...@gmail.com> wrote:
>  I think my problem comes from the way I'm referencing this variable created
> by RegEx from BeanShell.

Yes, see below.

> My RegEx look like:
>
> ReferenceName:       Attributes
> Regular Expression: <ProductAttributes>(.+?)</ProductAttributes>
> Template:                $1$
> Match No:               1
>
> and the BeanShell function string:
>
> ${__BeanShell(String str=vars.get("${Attributes}"); String newstr =
> str.replace("<"\,"<p:"); return newstr;, )} .
>

${Attributes} will be replaced by the contents of the variable; you
are then looking this up as a variable, which won't exist.

Try

${__BeanShell(${Attributes}.replace("<"\,"<p:"))}

So long as Attributes does not contain any commas, it should work.

If it does contain a comma, try:

${__BeanShell(vars.get("Attributes").replace("<"\,"<p:"))}

>
>  I tried many combinations of
>                  vars.get("${Attributes}");
>                 vars.get("${Attributes_g1}");
>                  vars.get("Attributes"); inside this BeanShell but each
> returns null, although the RegExpression variable Attributes displayed
> through a separate JavaRequest Sampler is perfectly valid, not null,
> XML string.

That is because you are de-referencing the variable twice...

---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-user-help@jakarta.apache.org