cancel
Showing results for 
Search instead for 
Did you mean: 

How to mock an HTTP Status with specific codes

Highlighted
Occasional Contributor

How to mock an HTTP Status with specific codes

The few posts that talk about this, must be for older versions of Soap UI, or perhaps, maybe Pro.  I am on the open source v 5.5.0.

I create a new mock response, I click the exclamation point at the top.  That does create a sample fault packet.
So far so good.
But I want to set the HTTP Status to a specific code.  Several posts indicate there are options on the left panel for setting http status code, but they are not there. I can't find any way to do it.   I tried, in desperation, to just create an http status header, with every possible spelling I could think of for http status, but nothing works.

How would I set a specific http status on this fault?
For example, I need to emulate a 401, 403, 408, 409, 500, 503 and others.   

Tags (3)
10 REPLIES 10
Community Hero

Re: How to mock an HTTP Status with specific codes

There are two ways.

1. Randomly send the response with different status code.
2. Send a header in the request. Based on the header value, send the response.

For both above, you can use Dispatch as Script for better control to send the response.


Regards,
Rao.
Occasional Contributor

Re: How to mock an HTTP Status with specific codes

Thanks for answering, but I'm still unclear on exactly how to get the status into the response. 
for #1, where do I put it?
for #2, what header?   I've tried what I thought it should be, but it did not work, so I must have used the wrong spelling.

Community Hero

Re: How to mock an HTTP Status with specific codes

Please show your script.


Regards,
Rao.
Occasional Contributor

Re: How to mock an HTTP Status with specific codes

I don't have a script, but I found information online that said there is an option in the mock response panel where I can set the status code.  I can't find that option, does that option not exist?  Is a script the only way to do it?

Community Hero

Re: How to mock an HTTP Status with specific codes

You mentioned that you created a 'fault' which makes me think you might have a SOAP mockservice?

Status Code is not used in SOAP. It will only be an option for mock responses in a REST service.

Occasional Contributor

Re: How to mock an HTTP Status with specific codes

Yes, in the mock service, when I create a response, it allows me to create a normal response or a fault response.

 

My question is, how do I specify which type of fault that is, there are dozens of fault types.   According to the documentation, there is supposed to be an option in the fault window to specify which fault type you want.   But it's not there.   I am current on my install of SOAP UI.


Community Hero

Re: How to mock an HTTP Status with specific codes

You can only specify the status code for a REST mockservice. See attached. (It should be blue, not green)

Occasional Contributor

Re: How to mock an HTTP Status with specific codes

So is there no way to mock a speciifc status code for SOAP?  I'm interfacing with a vendor that uses SOAP, and I want to set up negative tests to be sure I handle them properly.

Community Hero

Re: How to mock an HTTP Status with specific codes

SOAP specification doesn't allow for status codes.

 

When the server returns a SOAP fault:

For SOAP 1.1, the status code must be 500 “Internal Server Error”.  
For SOAP 1.2, it varies based on the type of the SOAP fault.
For env:Sender, the status code is 400 “Bad Request”,
but for anything else it is 500 like SOAP 1.1.

(https://blogs.msdn.microsoft.com/nathana/2011/03/31/deciphering-a-soap-fault-with-a-400-status-code/)

 

Your SOAP version should be automatically detected from your WSDL. You can also change the SOAP version at the Binding level in your project.