How to fail the requests in gatling that has status FAILURE in its response XML

Hi,

I am posting a soap request in gatling. Gatling Request is as below

package com.flexera.lfsperformance.scenarios

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class DeleteRequest extends Simulation {

 val httpProtocol = http
  .baseUrl("http://IP:PORT")
  .inferHtmlResources()
  .acceptEncodingHeader("gzip,deflate")
  .contentTypeHeader("text/xml;charset=UTF-8")
  .userAgentHeader("Apache-HttpClient/4.1.1 (java 1.5)")

 val headers_0 = Map(
  "Proxy-Connection" -> "Keep-Alive",
  "SOAPAction" -> """""""")

 val clientIdFeeder = Iterator.from(1).map(i => Map("id" -> "%03d".format(i)))

 val scn = scenario("DELETE_REQUEST")
   .repeat(10 ) {
   feed(clientIdFeeder)
    .exec(http("DeleteRequest")
     .post("/ / / /")
     .headers(headers_0)
     .body(ElFileBody("DeleteRequest.dat"))
     .basicAuth("username", "Password"))
         }

 
 setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}

**Soap body is :**

 <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:urn="urn:v3.fne.webservices.operations.flexnet.com">
   <soapenv:Header/>
   <soapenv:Body>
      <urn:deleteDeviceRequest>
         <!--1 or more repetitions:-->
         <urn:deviceIdentifier>
            <urn:deviceType>${deviceType}</urn:deviceType>
            <urn:deviceId>FNO${id}</urn:deviceId>
            <urn:deviceIdType>${deviceIdType}</urn:deviceIdType>
            <urn:publisherName>${publisherName}</urn:publisherName>
         </urn:deviceIdentifier>
      </urn:deleteDeviceRequest>
   </soapenv:Body>
</soapenv:Envelope>

**The actual response we receive is :**

HTTP/1.1 200 OK
Expires: 0
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Set-Cookie: JSESSIONID=wC2WtCaN9GITVdC3AE4sSFuZ.localhost; path=/flexnet; HttpOnly
Server: jboss
X-XSS-Protection: 1; mode=block
Pragma: no-cache
X-Frame-Options: SAMEORIGIN
Connection: keep-alive
X-Content-Type-Options: nosniff
Transfer-Encoding: chunked
Content-Type: text/xml;charset=utf-8 

<soapenv:Envelope xmlns:soapenv=“http://schemas.xmlsoap.org/soap/envelope/” xmlns:xsd=“XML Schema” xmlns:xsi=“http://www.w3.org/2001/XMLSchema-instance”>

   <soapenv:Body>
      <deleteDeviceResponse xmlns="urn:v3.fne.webservices.operations.flexnet.com">
         <statusInfo>
            <status>**FAILURE**</status>
         </statusInfo>
         <failedData>
            <failedDevice>
               <deviceIdentifier>
                  <deviceType>CLIENT</deviceType>
                  <deviceId>FNO1</deviceId>
                  <deviceIdType>STRING</deviceIdType>
                  <publisherName>fnetest</publisherName>
               </deviceIdentifier>
               <reason>**LFSError_HOST_NOT_FOUND:  Unable to find CLIENT host with unique keys [hostId=FNO1], [hostIdType=STRING], and [publisherName=fnetest] in tenant ADMN**.</reason>
            </failedDevice>
         </failedData>
      </deleteDeviceResponse>
   </soapenv:Body>
</soapenv:Envelope>


The actual response is FAILURE but, according to gatling since the status code is 200 OK all the requests are pass(OK). (Attached the gatling simulation graph)

Is there any way I can fail(KO) all the requets that has FAILURE in its response?  

Please put a regular expression check for your valid response which when found the request passes otherwise it will fail(KO).

The other option you can use is ignoreDefaultChecks which checks for a status 200 and passes your request.

Thanks for the solution Manjunath. It worked.

I have another query.

Is there any way we can write the for FAILURE into simulation.log file.

I am not sure how we can write this to simulation.log but you could write this to the console log and parse as per your necessity. To write the log to console you just need to add this to your logback.xml under tyhe logger section. You also could redirect this console log to a file if needed. hope this helps

<appender-ref ref="CONSOLE"/>

Yes, I had found the solution to write into a different file (Like the one you suggested). But, I was wondering if there could be any way we can append messages to simultion.log file. Apparently, I found from other websites that, writing into simultion.log file is not possible as it is is a private API and they haven’t made it public.

Thank you

Yes, that would be indie the gatling framework and default. Maybe that is reason you could not append to simulation directly.