简体   繁体   English

jmeter Beanshell PostProcessor删除标头引发异常

[英]jmeter Beanshell PostProcessor remove header throws exception

When I was using BeanShell PostProcessor to delete the header,there is a problem my code: 当我使用BeanShell PostProcessor删除标题时,我的代码存在问题:


import org.apache.jmeter.protocol.http.control.Header; 

sampler.getHeaderManager().removeHeaderNamed("Authorization");

exception: 例外:


2017/05/18 15:24:52 ERROR - jmeter.util.BeanShellInterpreter: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.Header;   sampler.getHeaderManage . . . '' : Attempt to resolve method: getHeaderManager() on undefined variable or class name: sampler 

2017/05/18 15:24:52 WARN  - jmeter.extractor.BeanShellPostProcessor: Problem in BeanShell script org.apache.jorphan.util.JMeterException: Error invoking bsh method: eval   Sourced file: inline evaluation of: ``import org.apache.jmeter.protocol.http.control.Header;   sampler.getHeaderManage . . . '' : Attempt to resolve method: getHeaderManager() on undefined variable or class name: sampler 

somebody help me 来人帮帮我

  1. You don't have sampler shorthand in the PostProcessor, if you need to remove the header from the previous sampler the relevant code should look like: 您在PostProcessor中没有sampler简写形式,如果您需要从先前的采样器中删除标头,则相关代码应如下所示:

     ctx.getCurrentSampler().getHeaderManager().removeHeaderNamed("Authorization"); 
    • ctx is a shorthand to JMeterContext class instance ctxJMeterContext类实例的简写
    • be aware that PostProcessors are executed after requests so make sure your implementation is inline with what you are trying to achieve 请注意,PostProcessor是请求执行的因此请确保您的实现与您要实现的目标一致
  2. If you need to remove the header before the request consider using PreProcessor instead. 如果您需要在请求之前删除标头,请考虑改用PreProcessor。 In this case you will be able to use sampler shorthand 在这种情况下,您将可以使用sampler速记
  3. I would recommend considering using JSR223 Test Elements and Groovy language as an alternative to Beanshell as Groovy performance is much better at it is more Java-compliant. 我建议考虑使用JSR223测试元素Groovy语言来替代Beanshell,因为Groovy的性能要好得多,并且更符合Java。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM