Simulate empty response if server is down

399 views Asked by At

I have 2 mockservices returning success and failure responses based on request body. Now I need to simulate an empty response if the server is down or unavailable.

How can this be done in Java ?

1

There are 1 answers

0
devdanke On BEST ANSWER

You could set the timeout of your client socket to a very short value to simulate timing out trying to connect to the server.

Here's a question showing how to set a socket timeout. Most HTTP clients let you provide config properties for the underlying TCP socket.

There are also test utilities to help with this, such as WebMock, explained in this question.