Calling Scala methods to do http operations

I am putting together some generic classes to provide a generic framework to avoid having to have a large number of scenarios. I am using session to store data that can then be used in the EL

My Scala knowledge is pretty flaky, as a Java dev, but here’s some work in progress

I have a top level scenario that does


val scen = scenario(“MainPage”)
.exec(session => CommandFactory.initCommand(ScriptId.MAINPAGE, session))
.repeat(2) {
exec(session => runCommand(“MainPage”, session))


where CommandFactory creates instances of ScalaCommand based on the required functionality (MAINPAGE). That would then be something passed in rather than hard coded above. CommandFactory does:


object CommandFactory {
def initCommand(id: ScriptId, session: Session): Session = {

var opt = session(“vuser”).asOption[VirtualUser]
var user = if (opt == None) new VirtualUser(session) else opt.get
var packName = “com…”;
var cmd = packName + “.” + id.txName() + “Command$” +
var cmdOption: Option[ScalaCommand] = session(id.txName()).asOption[ScalaCommand]

var cmdClass:ScalaCommand = if (cmdOption == None)
var klass = Class.forName(cmd).newInstance()


cmdClass.initCommand(id, user, session)

session.set(“Command:” + id.txName(), cmdClass).set(“vuser”, user)


In the Scala command class I am trying to send the request


def sendRequest(session: Session): Session =
val method = ServiceLoader.getMethod(id.txName().toLowerCase(), user.get)
val request = makeRequest(method)
val service = request.getService()
var url = service.getProtocol + “://” + service.getHost + service.getRoot() + method.getPath
var tx = id.txName() +
session.set(“url”, url).set(“tx”, tx)


I would like to exec the http request, but I am not sure how I can get this to work as session needs to be passed back to retain the new settings it has but for this to be exec’able I think it has to return a ChainBuilder. I was hoping to be able to exec(http… after the session setting, but I can’t make it work.