简体   繁体   English

无法使用 PostProcessor 在 JMeter 中解码 jwt 令牌

[英]Not able to decode jwt token in JMeter using PostProcessor

I am new to JMeter.I want to perfrom some load testing on one of my application.我是 JMeter 的新手。我想对我的一个应用程序进行一些负载测试。 I want to decode JWT token and from there need to get Session id and it has to be appended to JMeter variable.我想解码 JWT 令牌,并从那里需要获取会话 ID,并且必须将其附加到 JMeter 变量。

Below is my code下面是我的代码

import com.auth0.jwt.*

log.info("Hello")
def jwt = JWT.decode(vars.get('idToken'))
log.info(jwt)

vars.put('sessionId', jwt.getClaim('sessionId').asString())
log.info(jwt.getClaim('sessionId').asString())

It is producing some errors while executing this code执行此代码时产生一些错误

Below is the exception message下面是异常信息

javax.script.ScriptException: groovy.lang.MissingPropertyException: No such property: JWT for class: Script11
    at org.codehaus.groovy.jsr223.GroovyScriptEngineImpl.eval(GroovyScriptEngineImpl.java:320) ~[groovy-jsr223-3.0.7.jar:3.0.7]
    at org.codehaus.groovy.jsr223.GroovyCompiledScript.eval(GroovyCompiledScript.java:71) ~[groovy-jsr223-3.0.7.jar:3.0.7]
    at javax.script.CompiledScript.eval(CompiledScript.java:93) ~[java.scripting:?]
    at org.apache.jmeter.util.JSR223TestElement.processFileOrScript(JSR223TestElement.java:217) ~[ApacheJMeter_core.jar:5.4.1]
    at org.apache.jmeter.extractor.JSR223PostProcessor.process(JSR223PostProcessor.java:45) [ApacheJMeter_components.jar:5.4.1]
    at org.apache.jmeter.threads.JMeterThread.runPostProcessors(JMeterThread.java:955) [ApacheJMeter_core.jar:5.4.1]
    at org.apache.jmeter.threads.JMeterThread.executeSamplePackage(JMeterThread.java:573) [ApacheJMeter_core.jar:5.4.1]
    at org.apache.jmeter.threads.JMeterThread.processSampler(JMeterThread.java:489) [ApacheJMeter_core.jar:5.4.1]
    at org.apache.jmeter.threads.JMeterThread.run(JMeterThread.java:256) [ApacheJMeter_core.jar:5.4.1]
    at java.lang.Thread.run(Thread.java:831) [?:?]

Need suggestion to resolve this issue.需要建议来解决这个问题。

JMeter Version : 5.4 JMeter 版本:5.4

You need to have java-jwt-x.xx.x.jar along with its dependencies inJMeter Classpath before running the script.在运行脚本之前,您需要在JMeter 类路径中拥有java-jwt-x.xx.x.jar及其依赖项

For the latest stable version 3.18.1 you will need the following .jars:对于最新的稳定版本 3.18.1,您将需要以下 .jars:

  • jackson-annotations-2.11.0.jar jackson-annotations-2.11.0.jar
  • jackson-core-2.11.0.jar杰克逊核心2.11.0.jar
  • jackson-databind-2.11.0.jar杰克逊-数据绑定-2.11.0.jar
  • java-jwt-3.18.1.jar java-jwt-3.18.1.jar

If you do have them in JMeter Classpath already you will have to restart JMeter to pick the libraries up如果您已经在 J​​Meter 类路径中拥有它们,则必须重新启动 JMeter以获取库

Once done you should be able to use the code you copied and pasted from somewhere:完成后,您应该能够使用从某处复制和粘贴的代码:

Demo using JWT token eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c from https://jwt.io/ web page:使用 JWT 令牌的演示eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c https : eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c

在此处输入图片说明

More information on Groovy scripting in JMeter: Apache Groovy - Why and How You Should Use It有关 JMeter 中 Groovy 脚本的更多信息: Apache Groovy - 为什么以及如何使用它

暂无
暂无

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

相关问题 JMeter:在另一个后处理器中使用 JSON 后处理器_ALL 变量来获取数据 - JMeter : Using the JSON Postprocessor _ALL variable in one more postprocessor to fetch the data 使用PostProcessor将响应保存到JMeter中的文件 - Save responses to a file in JMeter with PostProcessor Jmeter,使用jsr223 postProcessor将数据写入文件(如果存在) - Jmeter, over writing data to file if it exists using jsr223 postProcessor 如何在 Jmeter 中使用后处理器设置变量的值并在预处理器中为相同的采样器使用它? - How to set values of variable using postprocessor in Jmeter and use it in Preprocessor for same sampler? 我们可以使用 Jmeter 从 BeanShell PostProcessor 中的响应断言打印成功消息/断言结果吗? - Can we print success message/Assertion Result from Response Assertion in BeanShell PostProcessor using Jmeter? JMeter JSR223 后处理器 GET COOKIE - JMeter JSR223 PostProcessor GET COOKIE 具有Groovy的Jmeter PostProcessor,并获取响应数据的内容 - Jmeter PostProcessor with Groovy and fetching content of response data Jmeter postProcessor将在所有http请求完成后仅执行一次 - Jmeter postProcessor to be executed only once after all the http requests are complete jMeter JSR223PostProcessor - 使用脚本运行文件 - 相对路径 - jMeter JSR223PostProcessor - running file with script - relative path 在 jmeter 后处理器中设置变量并在非 GUI 模式下在命令提示符下访问 - set a variable in jmeter postprocessor and access in command prompt in NON GUI mode
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM