Custom Exceptions handling using RestTemplate
Hi,
I want my RESTful webservices to throw Exceptions. On server I'm using CXF to do all RS-311 stuff, including catching my exceptions and putting exception data into HTTP headers (my way of doing this) and setting status to CONFLICT. No problem at all. But on client side, where I'm using RestTemplate, I don't see any way to first check if there was an Exception on server side, and if so gather all the data and throw the same Exception on client side. That is I'm looking for some generic method of doing so for all requests. I've found ResponseErrorHandler interface and I know how it is used, but handleError method assumes that I can only throw IOException. Theoretically I can put mine whole Exception hierarchy into IOException, but that's a bad idea.
My idea is simple, if server responses with 409 (CONFLICT) and there are two HTTP headers RESTException and RESTExceptionMessage, then I want exception thrown from RestTemplate. Is there any generic way of doing so? Or maybe I should avoid throwing Exceptions from RESTful webservices?
Best Regards
Jacek Bilski