[英]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:
If you do have them in JMeter Classpath already you will have to restart JMeter to pick the libraries up如果您已经在 JMeter 类路径中拥有它们,则必须重新启动 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.