Bug 58108

Summary: use sampler.toString() in BeanShell PreProcessor , HTTP JMeterProperty can not be replaced anymore
Product: JMeter Reporter: xiangjian <pigneverdie>
Component: HTTPAssignee: JMeter issues mailing list <issues>
Status: NEW ---    
Severity: normal    
Priority: P2    
Version: 2.13   
Target Milestone: ---   
Hardware: PC   
OS: All   
Attachments: three pictures in one
Test Plan Demo

Description xiangjian 2015-07-06 09:59:33 UTC
Created attachment 32884 [details]
three pictures in one

in BeanShell PreProcessor :

sampler.toString();
vars.put("sign","123");

${sign} can not be replaced by 123 in HttpSampler

please see Attachements
Comment 1 xiangjian 2015-07-06 10:10:29 UTC
  the sampler.toStirng() will use

 the Class HTTPSamplerBase:
getUrl()-->getQueryString()-->item.getEncodedName();
Comment 2 Sebb 2015-07-06 11:49:07 UTC
I canot work out what the problem is here.

Please provide the simplest possible Test Plan showing the issue.

State what you expected to happen and what actually happened.

Did the same test sequence work OK in a previous version of JMeter, if so which?
Comment 3 xiangjian 2015-07-07 02:16:39 UTC
(In reply to Sebb from comment #2)
> I canot work out what the problem is here.
> 
> Please provide the simplest possible Test Plan showing the issue.
> 
> State what you expected to happen and what actually happened.
> 
> Did the same test sequence work OK in a previous version of JMeter, if so
> which?

Hi Sebb ,

Thanks for reply.

I add an attachement provide the simplest Test Plan.
you will see my problem in it .
the Test Plan can not work because of the problem ,please use "//" before sampler.toString() in BeanShell PreProcessor .
Comment 4 xiangjian 2015-07-07 02:17:16 UTC
Created attachment 32886 [details]
Test Plan Demo
Comment 5 Sebb 2015-07-07 03:06:14 UTC
Thanks, that is a great help.

I can confirm the problem, but I've no idea what is causing it yet.
Comment 6 xiangjian 2015-07-07 03:37:00 UTC
(In reply to Sebb from comment #5)
> Thanks, that is a great help.
> 
> I can confirm the problem, but I've no idea what is causing it yet.


from the source code ,I find something ,it may help:

sampler.toString() will do( from HttpSamplerBase.java) :

    @Override
    public String toString() {
        try {
            StringBuilder stringBuffer = new StringBuilder();
            stringBuffer.append(this.getUrl().toString());//problem is here

this.getUrl().toStirng() make the bug;

and from the functin getUrl():

  if(HTTPConstants.GET.equals(getMethod()) || HTTPConstants.DELETE.equals(getMethod())) {
            // Get the query string encoded in specified encoding
            // If no encoding is specified by user, we will get it
            // encoded in UTF-8, which is what the HTTP spec says
            String queryString = getQueryString(getContentEncoding());//problem is here

getQueryString() make the bug;

and from the function getQueryStirng():

   try {
        	   item.getEncodedValue(contentEncoding);// problem is here
           }
finnally , i find the bug may be in the class AbstractTestElement
when i do sampler.toString(),it will do getPropertyAsString(),and the parameters can not be replaced any more after it.
Comment 7 Sebb 2015-07-08 10:53:44 UTC
The following test plan also fails:

Test Plan
- BeanShell PP (at same level as the sampler)
- HTTP Sampler

This fails:

Test Plan
- BeanShell PP
- HTTP Sampler
- Java Request using the variable (this sees the variable OK)

However, this works:

Test Plan
- BeanShell PP
- Java Request using the variable (this sees the variable OK)
- HTTP Sampler

The processing of variables is quite complicated as they sometimes need to be resolved (e.g. when being used at run-time) and sometimes that must be returned in their original state (e.g. for display in the GUI).

I expect what is happening is that the "running" state is not being set at the correct time.