Forum Discussion

LoundesM's avatar
LoundesM
Contributor
9 years ago
Solved

Http Status Codes

Hi

 

is there a way of adding additional http status codes to the pre defined list for virt responses?

 

creating a virt but need a status code of 428 - Precondition Required but that isnt in the drop down list

 

failing the ability to configure that list is it possible to set the status on the fly? and if so how would I do that?

 

 

thanks

Mike

 

  • Shadid's avatar
    Shadid
    9 years ago

    Hi again,

     

    Right now, this is not possible. It is the underlying HttpServletResponse which sets the reason phrase from the status code, and 428 is not there so it does not find any mapping reason phrase. 

     

    By the way, as a workaround you can send a custom header in the response with the reason phrase (Precondition Required), if that helps.

     

    Regards,

    Shadid

5 Replies

  • Hi,

     

    You can set any HTTP status code for a particular response.

     

    You can do it by selecting the response then clicking the Script on the right inspector and then pasting this code

     

    mockResponse.responseHttpStatus = 428

     Hope this helps!

     

    Regards,

    Shadid

    • LoundesM's avatar
      LoundesM
      Contributor

      Hi

       

      that works to an extent

       

      I get the following response

      -------------

      HTTP/1.1 428 428
      Content-Type: application/json
      Content-Encoding: gzip
      Content-Length: 60
      Server: Jetty(6.1.26)

      {
          "reason" : "Precondition required"
      }

      -------------

       

      If I dont use that line in the response script and just select a response code from the drop down list I get something like this

      -------------

      HTTP/1.1 401 Unauthorized
      Content-Type: application/json
      Content-Encoding: gzip
      Content-Length: 60
      Server: Jetty(6.1.26)

      {
          "reason" : "Precondition required"
      }

      -------------

       

      How do I change the text associated with the code?

      i.e. change '428 428' to '428 Precondition Required'

       

       

      for ref I'd already tried this which didnt work

      mockResponse.setResponseHttpStatus = 428

       

      (referenced from - http://www.soapui.org/apidocs/com/eviware/soapui/model/mock/MockResponse.html#setResponseHttpStatus(int))

       

      • Shadid's avatar
        Shadid
        Staff

        Hi again,

         

        Right now, this is not possible. It is the underlying HttpServletResponse which sets the reason phrase from the status code, and 428 is not there so it does not find any mapping reason phrase. 

         

        By the way, as a workaround you can send a custom header in the response with the reason phrase (Precondition Required), if that helps.

         

        Regards,

        Shadid