Simulating HTTP errors with CXF web service

170 views Asked by At

I have a CXF web client, and a service which simulates a real service (which is currently out of my control and inaccessible to me -- for now).

Using my client & sim, I can already test how the client behaves under normal circumstances, but I would now also like to test it in the cases of various HTTP or low-level socket exceptions such as read timeouts, gateway timeouts, or other HTTP errors.

Socket errors are easy enough: just set a small enough timeout (or have no endpoint available at all), and catch any SocketException -- no need for the service to do anything special.

But I don't know how to create true HTTP errors from CXF, in cases where, for example, I setup a special scenario where I want the sim to fail early on with a HTTP error.

One half-solution is to create a org.apache.cxf.interceptor.Fault in my service, set a setResponseCode (for example, 404) and throw it from the the server.

The somewhat works, as the HTTP's status will be 404 -- but there is still a full SOAP fault message attached -- so it's not truly realistic as I'm trying to simulate HTTP errors that could occur before the service is ever even reached.

So how can I do this? The reason it's important is that, in order to write client-side error handling code, I need to know how CXF will behave when it gets true HTTP errors. For example, what exceptions I should be catching, and how to extract info from them. Also, for reasons I won't go into here, if I encounter a HTTP error, I need to get the status code.

I know a little bit about CXF interceptors, but if the solution is that route, I have been unsuccessful in trying. Any ideas? Thanks!

0

There are 0 answers