I am currently developing a SOAP client with Spring WS. I followed the guides/tutorials and all is working fine. Except for one thing, error handling.
I have no control over the SOAP endpoint i am sending messages to. So i want to do some good exception handling in case of things going wrong. I encountered some HTTP errors in the testing scenarios i didn't count on. And i dont know how to handle them.
For example:
I send a SOAP message to the wrong URL. Which returned a HTTP 405 Method not allowed. (I send a POST to a GET only URL, it was a misconfiguration but still an error). In the body was literally a HTML error page from the SOAP endpoint. Ofcourse Spring couldn't handle this message and was throwing an exception. In the stacktrace it was clear it was a 405. But i want to extract the error code returned and log it in some other way (Or send it back to the user doing a request for sending the SOAP message).
These are some log messages i recieved after sending the SOAP message (other logging is omitted):
org.apache.http.wire : << "HTTP/1.1 405 Method Not Allowed[\r][\n]"
o.a.h.impl.conn.DefaultClientConnection : Receiving response: HTTP/1.1 405 Method Not Allowed
org.apache.http.headers : << HTTP/1.1 405 Method Not Allowed
Is there any way to catch and extract these HTTP error codes? If there is any more information needed, just ask. I am willing to provide as much info as i can but i dont know what else to post at this moment.
EDIT: Or is there any way to mock/test this with an integration test? I can't keep sending messages to the real SOAP endpoint. I don't get the same output from an integration test as from a real test (booting the app and sending messages to the real SOAP endpoint). I have set my logging levels for integration testing the same as for the real testing environment.
Thanks!