title: Manipulate post body of httpsampler before request
body: <p>I'm testing an Eclipse-RAP application with JMeter.<br>
  In RAP the client (javascript-framework in the browser) communicates with the server over a json-based protocol.</p>
  
  <p>A message looks like this:</p>
  
  <pre><code>{"head":{"requestCounter":3,"uiSessionId":"832834"},"operations":[["set","w1",{"bounds":    [0,0,1680,893],"cursorLocation":[1262,-1]}]]}
  </code></pre>
  
  <p>As you see there is a session-ID stored in <code>uiSessionId. I extracted this id using a "Regular Expression Extractor" and stored it in a variable named</code>UI_SESSION_ID`.<br>
  Then i edited the raw "Post Body" of the recorded HTTP-Request:</p>
  
  <pre><code>{"head":{"requestCounter":3,"uiSessionId":"${UI_SESSION_ID}"},"operations":[["set","w1",{"bounds":    [0,0,1680,893],"cursorLocation":[1262,-1]}]]}
  </code></pre>
  
  <p>and it works.</p>
  
  <p>But i have to alter each Post-Body of each HTTP-Request which can be a lot.
  After some research i thought using a "BeanShell PreProcessor" would be the right thing, but: </p>
  
  <pre><code>var sampler = ctx.getCurrentSampler();
  </code></pre>
  
  <p>would give me a HTTPSampler and i did not find any method which allows me to retrieve the post-body, replace the session-id with the variable and set the altered post-body.<br>
  JavaDoc: <a href="http://jmeter.apache.org/api/org/apache/jmeter/protocol/http/sampler/HTTPSampler.html" rel="nofollow">http://jmeter.apache.org/api/org/apache/jmeter/protocol/http/sampler/HTTPSampler.html</a></p>
  
  <p>Do you know any way i can replace the <code>uiSessionId</code> with the variable without changing every request manually?</p>