val jsonString =
“”"
{“name” : “jj”,
“displayName” : “jj”,
}
“”"
val tCreate = exec(http(“Create API”)
.post("/xyz/tpqr")
.headers(myheader)
.body(StringBody(jsonString)).asJSON
.check(status.is(201)))
}
Question : .body(StringBody(jsonString)).asJSON is this the right way to pass the JSON Body?
( I literally tried other posibilities like RawFileBody, EfileBody and not able to get desired output)
I am using gatling with Scala. Earlier Scala version was 2.12, after looking at some forums like StackOverflow, I downgraded the Scala version to 2.10 (through Project Structure ->SDK or Global Libraries) and still getting issues. Anyone able to do a POST successfully in Gatling and Scala, if yes, could you share what is the Gatling version, what’s Scala version, and how are you passing the body to post?
val jsonString =
“”"
{“name” : “jj”,
“displayName” : “jj”,
}
“”"
val tCreate = exec(http(“Create API”)
.post(“/xyz/tpqr”)
.headers(myheader)
.body(StringBody(jsonString)).asJSON
.check(status.is(201)))
}
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sbt.compiler.RawCompiler.apply(RawCompiler.scala:33)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:146)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:142)
at sbt.IO$.withTemporaryDirectory(IO.scala:344)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:142)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:139)
at sbt.IO$.withTemporaryDirectory(IO.scala:344)
at sbt.compiler.AnalyzingCompiler$.compileSources(AnalyzingCompiler.scala:139)
at sbt.compiler.IC$.compileInterfaceJar(IncrementalCompiler.scala:58)
at com.typesafe.zinc.Compiler$.compilerInterface(Compiler.scala:148)
at com.typesafe.zinc.Compiler$.create(Compiler.scala:53)
at io.gatling.compiler.ZincCompiler$delayedInit$body.apply(ZincCompiler.scala:147)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71)
at io.gatling.compiler.ZincCompiler$.main(ZincCompiler.scala:36)
at io.gatling.compiler.ZincCompiler.main(ZincCompiler.scala)
… 6 more
Caused by: java.lang.NoSuchMethodError: scala.util.PropertiesTrait.$init$(Lscala/util/PropertiesTrait;)V
at scala.tools.nsc.Properties$.(Properties.scala:12)
at scala.tools.nsc.Properties$.(Properties.scala)
at scala.tools.nsc.Driver.(Driver.scala:10)
at scala.tools.nsc.MainClass.(Main.scala:13)
at scala.tools.nsc.Main$.(Main.scala:28)
at scala.tools.nsc.Main$.(Main.scala)
at scala.tools.nsc.Main.process(Main.scala)
… 31 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 11.557 s
[INFO] Finished at: 2018-12-12T16:04:18+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.gatling:gatling-maven-plugin:2.2.4:test (default-cli) on project caap-load-testing: Gatling failed.: Simulations compilation failed. Process exited with an error: -1 (Exit value: -1) → [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] MojoExecutionException - Apache Maven - Apache Software Foundation
Which Java version are you using? If you’re not already on JDK8, I’d try getting that, and see if anything changes.
The scala versions you’ve listed having tried all require JDK8 (or less), so if you’re running 9 or higher, that’s likely the cause of your frustrations. The error you’re getting looks a lot to me like something that would happen due to incompatibilities between scala and java.
I am on latest Java version 1.8
Thanks Stephane for answering.
-
Java 8 Update 191 (64 bit)
-
In the Maven (.m2 folder) I have Gatling 2.2.4 and 2.3.0
-
Scala - Now only 2.12 version is there in Global Libraries, removed 2.10 now
Still same error
[INFO] Scanning for projects…
[INFO]
[INFO] -------------< app-platform-automation:caap-load-testing >--------------
[INFO] Building caap-load-testing 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] — gatling-maven-plugin:2.2.4:test (default-cli) @ caap-load-testing —
11:53:59,287 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
11:53:59,287 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
11:53:59,287 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [jar:file:/C:/Users/jagri/.m2/repository/io/gatling/gatling-maven-plugin/2.2.4/gatling-maven-plugin-2.2.4.jar!/logback.xml]
11:53:59,287 |-INFO in ch.qos.logback.core.joran.spi.ConfigurationWatchList@d706f19 - URL [jar:file:/C:/Users/jagri/.m2/repository/io/gatling/gatling-maven-plugin/2.2.4/gatling-maven-plugin-2.2.4.jar!/logback.xml] is not of type file
11:53:59,365 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
11:53:59,397 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
11:53:59,412 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [CONSOLE]
11:53:59,412 |-ERROR in ch.qos.logback.core.joran.spi.Interpreter@5:19 - no applicable action for [immediateFlush], current ElementPath is [[configuration][appender][immediateFlush]]
11:53:59,412 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
11:53:59,459 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - ROOT level set to WARN
11:53:59,459 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [CONSOLE] to Logger[ROOT]
11:53:59,459 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - End of configuration.
11:53:59,475 |-INFO in ch.qos.logback.classic.joran.JoranConfigurator@30b7c004 - Registering current configuration as safe fallback point
java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at io.gatling.mojo.MainWithArgsInFile.runMain(MainWithArgsInFile.java:50)
at io.gatling.mojo.MainWithArgsInFile.main(MainWithArgsInFile.java:33)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sbt.compiler.RawCompiler.apply(RawCompiler.scala:33)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:146)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1$$anonfun$apply$2.apply(AnalyzingCompiler.scala:142)
at sbt.IO$.withTemporaryDirectory(IO.scala:344)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:142)
at sbt.compiler.AnalyzingCompiler$$anonfun$compileSources$1.apply(AnalyzingCompiler.scala:139)
at sbt.IO$.withTemporaryDirectory(IO.scala:344)
at sbt.compiler.AnalyzingCompiler$.compileSources(AnalyzingCompiler.scala:139)
at sbt.compiler.IC$.compileInterfaceJar(IncrementalCompiler.scala:58)
at com.typesafe.zinc.Compiler$.compilerInterface(Compiler.scala:148)
at com.typesafe.zinc.Compiler$.create(Compiler.scala:53)
at io.gatling.compiler.ZincCompiler$delayedInit$body.apply(ZincCompiler.scala:147)
at scala.Function0$class.apply$mcV$sp(Function0.scala:40)
at scala.runtime.AbstractFunction0.apply$mcV$sp(AbstractFunction0.scala:12)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.App$$anonfun$main$1.apply(App.scala:71)
at scala.collection.immutable.List.foreach(List.scala:318)
at scala.collection.generic.TraversableForwarder$class.foreach(TraversableForwarder.scala:32)
at scala.App$class.main(App.scala:71)
at io.gatling.compiler.ZincCompiler$.main(ZincCompiler.scala:36)
at io.gatling.compiler.ZincCompiler.main(ZincCompiler.scala)
… 6 more
Caused by: java.lang.NoSuchMethodError: scala.util.PropertiesTrait.$init$(Lscala/util/PropertiesTrait;)V
at scala.tools.nsc.Properties$.(Properties.scala:12)
at scala.tools.nsc.Properties$.(Properties.scala)
at scala.tools.nsc.Driver.(Driver.scala:10)
at scala.tools.nsc.MainClass.(Main.scala:13)
at scala.tools.nsc.Main$.(Main.scala:28)
at scala.tools.nsc.Main$.(Main.scala)
at scala.tools.nsc.Main.process(Main.scala)
… 31 more
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 7.271 s
[INFO] Finished at: 2018-12-13T11:54:00+05:30
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal io.gatling:gatling-maven-plugin:2.2.4:test (default-cli) on project caap-load-testing: Gatling failed.: Simulations compilation failed. Process exited with an error: -1 (Exit value: -1) → [Help 1]
[ERROR]
[ERROR] To see the full stack trace of the errors, re-run Maven with the -e switch.
[ERROR] Re-run Maven using the -X switch to enable full debug logging.
[ERROR]
[ERROR] For more information about the errors and possible solutions, please read the following articles:
[ERROR] [Help 1] MojoExecutionException - Apache Maven - Apache Software Foundation
This error happens because you’re mixing artifacts for different Scala versions.
Run mvn:dependencyTree and fix your pom.xml.