Reading file from resources folder

Good day,

Running into an issue reading a file from the resources folder in my Scala code. I’m trying to read the files as a classpath resource from the classpath root as noted in https://gatling.io/docs/current/session/feeder/?highlight=resources#file-based-feeders as number 1 option. However, when I run it with the gatling.sh and pass the path via -rsf it can’t find the file. I can do it with options 2 and 3. Option 2 by using System.getProperty(“user.dir”) or the java.nio.file.Paths. Both work equally well locally.

Here’s a successful example of the user.dir after copying the resource file to the user-files/resources folder under the GATLING_HOME location and running the gatling.sh script with just the -rf and -s options: val BODY = StringBody(scala.io.Source.fromFile(System.getProperty(“user.dir”) + “/user-files/resources/MyFile.json”).getLines().mkString)

I can also run it just fine from gradle with the ‘com.github.lkishalmi.gatling’ plugin running. The following command where the file is located in the src/test/resources folder of the project: val BODY = StringBody(scala.io.Source.fromResource(“MyFile.json”).getLines().mkString).

What it feels like I’m missing is that the value passed in -rsf is a property somewhere, but I don’t know how to reference it. I’ve been searching around quite a bit and working with different options in the code and have come up empty.

Thanks!

Joe

Contradicting statements.

I’m trying to read the files as a classpath resource from the classpath root
pass the path via -rsf

rsf stands for resources folder. It’s an absolute path of a directory on the filesystem, it has nothing to do with classpath.

I can also run it just fine from gradle with the ‘com.github.lkishalmi.gatling’ plugin running.

This plugin is deprecated as it’s been contributed upstream. You should switch to https://gatling.io/docs/current/extensions/gradle_plugin/#gradle-plugin

StringBody(scala.io.Source.fromResource(“MyFile.json”).getLines().mkString)

Why don’t you use RawFileBody?

Ok, Thanks for the quick response! I’ll switch to plugins and dive into RawFileBody and update here with what I find.

Thanks!

Joe

I was able to pick this up again. The gradle plugin works great!

I switched to using RawFileBody. We didn’t use it previously as we require signatures for each request and the way the signature generator was written it read the file, removed the new lines and returned a string. I updated the signature generator tool as removing new lines isn’t necessary as it was just done for readability for the small files the engineer that wrote it was working with.

Thanks for the help!

Joe