0

I'm testing a SOAP service that accepts a request with an optional field. Below is a request body snippet to illustrate.

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header/>
    <soapenv:Body>
        <findPerson>
            <request>
                <!-- Optional field: -->
                <firstName>${FIRST_NAME}</firstname>
            </request>
        </findPerson>
    </soapenv:Body>
</soapenv:Envelope>

And the following is an extract from my current scenario setup in Scala:

scenario("Send FindPerson-request")
    [...]
    .feed(firstNameFeeder)
    .exec(
        http("FindPerson")
            .post(serviceUrl)
            .body(ELFileBody("bodies/FindPersonRequestBody.ssp"))
            [...]
    )

What I'm trying to do is to not include the <firstName> element in the request at all whenever the firstNameFeeder returns a null.

So far I've solved the problem by writing a bunch of custom Scala code to inject actual HTML tags into the request body depending on whether or not the feeder yields any data, but this is starting to become very cumbersome, and I feel like I'm in many ways working against the Gatling framework.

Am I missing something? Is there a better way to do this? I checked the documentation and noticed support for templating frameworks such as Mustache has been removed, but from my point of view, that could've been really useful in this case.

Thomas Kåsene
  • 5,301
  • 3
  • 18
  • 30
  • Would passing in a blank value not be enough? Surely the code would catch that? Alternatively you could, instead of having `$FIRST_NAME` just have `$FIRST_NAME` and when feeding in data the data would include the xml tags. I can add a more in depth answer if this sounds like something you would use. – Questioning Dec 14 '16 at 12:24
  • One of the problems is that though the original question doesn't illustrate it, I have many of these optional fields, and the more fields I have, the more custom code needs to be written to take them all into account. This is what I'm trying to avoid. I can bypass the problem as mentioned, but I'm wondering if there's a more "correct" way to approach this issue, which can't possibly be all that uncommon. – Thomas Kåsene Dec 14 '16 at 22:15
  • Also, to clarify: passing an empty value in the example won't be enough because that would send an empty string in the request (``), and I don't want that. I want the field itself to be completely gone. And I don't want the feeder source to be full of XML tags either, because then I won't be able to reuse the source for other web services (for example if I have two SOAP services that require name, but in one request the field is called `` and in the second request it's called ``.) – Thomas Kåsene Dec 14 '16 at 22:30
  • I'm afraid that's the only thing that comes to mind, short of manually putting the soap request together as a string and omitting the tags that have no data - but you've already mentioned that. The actual format Gatling uses is called `Scalate Ssp` - you may have more luck with that. (It does look like it supports something called [Velocity Style Directives](https://scalate.github.io/scalate/documentation/ssp-reference.html#velocity_style_directives) which may do the trick) – Questioning Dec 15 '16 at 08:50
  • It looks like `#if(${FIRST_NAME})${FIRST_NAME}#end` within the file body may give you what you are looking for. – Questioning Dec 15 '16 at 08:56

0 Answers0