You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@jmeter.apache.org by Ed Young <ej...@summitbid.com> on 2009/04/29 22:44:37 UTC

Calculating content length

Is there a way to calculate the length of some string, including any
embedded variables?

It would have to first expand the variables and then do the calculation...

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


Re: Calculating content length

Posted by Ed Young <ej...@summitbid.com>.
You're right. I'm not sure what I was doing incorrectly, but it was likely
the way I was quoting the variables or not quoting them in some cases.

Luckily it's alot easier than I was making it. I can use either of the
__javaScript() or __BeanShell() functions to solve my problem. Thanks.

On Wed, May 6, 2009 at 11:09 AM, sebb <se...@gmail.com> wrote:

> On 06/05/2009, Ed Young <ej...@summitbid.com> wrote:
> > Once again, as soon as I posted below, I seem to have solved my problem,
> and
> >  again it's much simpler than I'd made it.
> >
> >  I simply made a user variable something like this:
> >
> >  CONTENT_LENGTH   ${__BeanShell("v=0${RTSP_PORT}o=- ${SESSION_ID} 0 IN
> IP4
> >  ${HOSTNAME}s=t=0 0a=X-playlist-item: ${PROVIDER_ID} ${ASSET_ID}c=IN IP4
> >  0.0.0.0m=video 0 udp MP2T".length())}
>
> Same would work with __javaScript().
>
> >  The only issue is whether I need to include the CRLF
> __javaScript('\r\n') in
> >  the content length calculation. I had to omit it from the above
> >  CONTENT_LENGTH because it seems BeanShell doesn't like having
> __javaScript()
> >  functions passed into it.
> >
>
> BeanShell does not see function calls or variable references as these
> are resolved before the string is passed to it.
>
> But why not just use "\r\n" in the string?
>
> The only tricky part is where a variable contains double-quotes, in
> which case "${VAR}" won't be a valid string. The solution is to use
> vars.get("VAR") which is a string.
>
> >
> >  On Wed, Apr 29, 2009 at 7:13 PM, sebb <se...@gmail.com> wrote:
> >
> >
> > > On 29/04/2009, Ed Young <ej...@summitbid.com> wrote:
> >  > > Is there a way to calculate the length of some string, including any
> >  > >  embedded variables?
> >  >
> >  > Why do you need to do this?
> >  >
> >  > >  It would have to first expand the variables and then do the
> >  > calculation...
> >  >
> >  > Just pass the string to a function that returns its length; variables
> >  > are resolved before the function is called.
> >  >
> >  > >
>  ---------------------------------------------------------------------
> >  > >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> >  > >  For additional commands, e-mail:
> jmeter-user-help@jakarta.apache.org
> >  > >
> >  > >
> >  >
> >  > ---------------------------------------------------------------------
> >  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> >  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >  >
> >  >
> >
> >
> >
> > --
> >
> > - Ed
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>


-- 
- Ed

Re: Calculating content length

Posted by sebb <se...@gmail.com>.
On 06/05/2009, Ed Young <ej...@summitbid.com> wrote:
> Once again, as soon as I posted below, I seem to have solved my problem, and
>  again it's much simpler than I'd made it.
>
>  I simply made a user variable something like this:
>
>  CONTENT_LENGTH   ${__BeanShell("v=0${RTSP_PORT}o=- ${SESSION_ID} 0 IN IP4
>  ${HOSTNAME}s=t=0 0a=X-playlist-item: ${PROVIDER_ID} ${ASSET_ID}c=IN IP4
>  0.0.0.0m=video 0 udp MP2T".length())}

Same would work with __javaScript().

>  The only issue is whether I need to include the CRLF __javaScript('\r\n') in
>  the content length calculation. I had to omit it from the above
>  CONTENT_LENGTH because it seems BeanShell doesn't like having __javaScript()
>  functions passed into it.
>

BeanShell does not see function calls or variable references as these
are resolved before the string is passed to it.

But why not just use "\r\n" in the string?

The only tricky part is where a variable contains double-quotes, in
which case "${VAR}" won't be a valid string. The solution is to use
vars.get("VAR") which is a string.

>
>  On Wed, Apr 29, 2009 at 7:13 PM, sebb <se...@gmail.com> wrote:
>
>
> > On 29/04/2009, Ed Young <ej...@summitbid.com> wrote:
>  > > Is there a way to calculate the length of some string, including any
>  > >  embedded variables?
>  >
>  > Why do you need to do this?
>  >
>  > >  It would have to first expand the variables and then do the
>  > calculation...
>  >
>  > Just pass the string to a function that returns its length; variables
>  > are resolved before the function is called.
>  >
>  > >  ---------------------------------------------------------------------
>  > >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  > >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  > >
>  > >
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>
>
>
> --
>
> - Ed
>

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


Re: Calculating content length

Posted by Ed Young <ej...@summitbid.com>.
Once again, as soon as I posted below, I seem to have solved my problem, and
again it's much simpler than I'd made it.

I simply made a user variable something like this:

CONTENT_LENGTH   ${__BeanShell("v=0${RTSP_PORT}o=- ${SESSION_ID} 0 IN IP4
${HOSTNAME}s=t=0 0a=X-playlist-item: ${PROVIDER_ID} ${ASSET_ID}c=IN IP4
0.0.0.0m=video 0 udp MP2T".length())}

The only issue is whether I need to include the CRLF __javaScript('\r\n') in
the content length calculation. I had to omit it from the above
CONTENT_LENGTH because it seems BeanShell doesn't like having __javaScript()
functions passed into it.


On Wed, Apr 29, 2009 at 7:13 PM, sebb <se...@gmail.com> wrote:

> On 29/04/2009, Ed Young <ej...@summitbid.com> wrote:
> > Is there a way to calculate the length of some string, including any
> >  embedded variables?
>
> Why do you need to do this?
>
> >  It would have to first expand the variables and then do the
> calculation...
>
> Just pass the string to a function that returns its length; variables
> are resolved before the function is called.
>
> >  ---------------------------------------------------------------------
> >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>


-- 
- Ed

Re: Calculating content length

Posted by Ed Young <ej...@summitbid.com>.
I'm using the TCPSampler to send an RTSP protocol message. I'm
collecting the variables for the message from XML files, so the
content and content length will therefore vary.

It seems to me the  __javaScript() function is a likely route, which
I'll try first.


On Wed, Apr 29, 2009 at 7:13 PM, sebb <se...@gmail.com> wrote:
> On 29/04/2009, Ed Young <ej...@summitbid.com> wrote:
>> Is there a way to calculate the length of some string, including any
>>  embedded variables?
>
> Why do you need to do this?
>
>>  It would have to first expand the variables and then do the calculation...
>
> Just pass the string to a function that returns its length; variables
> are resolved before the function is called.
>
>>  ---------------------------------------------------------------------
>>  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>>  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>



-- 
- Ed

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


Re: Calculating content length

Posted by sebb <se...@gmail.com>.
On 06/05/2009, Ed Young <ej...@summitbid.com> wrote:
> I'm confused as to what you mean by "Just pass the string to a function that
>  returns it's length".
>
>  The only functions I'm aware of in jmeter are the ones documented in section
>  19 of the manual:
>  http://jakarta.apache.org/jmeter/usermanual/functions.html
>
>  Is there a way to create my own? Everything I see in the doc indicates built
>  in functions, but no indication of how to create a custom one.
>
>  I started by trying to use the __javaScript() function but abandoned it
>  because I was unable to pass in my string + user variables and execute the
>  length method on it.

That's what I meant.

What did you try?

__javaScript("This is a string".length)

works for me.

So does

__javaScript("Started at ${START.HMS}".length)

>  Now I'm experimenting with the BeanShell Preprocessor for the first time,
>  which looks promising, but seems like there should be an easier way to
>  simply calculate a string with embedded user variables.
>

See above.

>
>
>
>  On Wed, Apr 29, 2009 at 7:13 PM, sebb <se...@gmail.com> wrote:
>
>
> > On 29/04/2009, Ed Young <ej...@summitbid.com> wrote:
>  > > Is there a way to calculate the length of some string, including any
>  > >  embedded variables?
>  >
>  > Why do you need to do this?
>  >
>  > >  It would have to first expand the variables and then do the
>  > calculation...
>  >
>  > Just pass the string to a function that returns its length; variables
>  > are resolved before the function is called.
>  >
>  > >  ---------------------------------------------------------------------
>  > >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  > >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  > >
>  > >
>  >
>  > ---------------------------------------------------------------------
>  > To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
>  > For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>  >
>  >
>
>
>
> --
>
> - Ed
>

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


Re: Calculating content length

Posted by Ed Young <ej...@summitbid.com>.
I'm confused as to what you mean by "Just pass the string to a function that
returns it's length".

The only functions I'm aware of in jmeter are the ones documented in section
19 of the manual:
http://jakarta.apache.org/jmeter/usermanual/functions.html

Is there a way to create my own? Everything I see in the doc indicates built
in functions, but no indication of how to create a custom one.

I started by trying to use the __javaScript() function but abandoned it
because I was unable to pass in my string + user variables and execute the
length method on it.

Now I'm experimenting with the BeanShell Preprocessor for the first time,
which looks promising, but seems like there should be an easier way to
simply calculate a string with embedded user variables.




On Wed, Apr 29, 2009 at 7:13 PM, sebb <se...@gmail.com> wrote:

> On 29/04/2009, Ed Young <ej...@summitbid.com> wrote:
> > Is there a way to calculate the length of some string, including any
> >  embedded variables?
>
> Why do you need to do this?
>
> >  It would have to first expand the variables and then do the
> calculation...
>
> Just pass the string to a function that returns its length; variables
> are resolved before the function is called.
>
> >  ---------------------------------------------------------------------
> >  To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> >  For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
> >
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: jmeter-user-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: jmeter-user-help@jakarta.apache.org
>
>


-- 
- Ed

Re: Calculating content length

Posted by sebb <se...@gmail.com>.
On 29/04/2009, Ed Young <ej...@summitbid.com> wrote:
> Is there a way to calculate the length of some string, including any
>  embedded variables?

Why do you need to do this?

>  It would have to first expand the variables and then do the calculation...

Just pass the string to a function that returns its length; variables
are resolved before the function is called.

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

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