Module org.cruk.clarity.api
Package org.cruk.clarity.api.http
Class ClarityFailureResponseErrorHandler
java.lang.Object
org.springframework.web.client.DefaultResponseErrorHandler
org.cruk.clarity.api.http.ClarityFailureResponseErrorHandler
- All Implemented Interfaces:
ResponseErrorHandler
REST client error handler that looks at the response body when there is a failure
code (an HTTP 400 or 500 code) and sees if the body contains a Clarity
exception
message. If it does, that is thrown instead.
This handler relies on the exception conversion aspect around the JAXB2 unmarshaller.
- See Also:
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
handleError
(ClientHttpResponse response) See if the response indicates an error and, if the body of the response is a Clarity error reply, create a throwableClarityException
from it and throw that.protected boolean
hasError
(HttpStatus statusCode) Refinement of the default implementation, as we want anything that's not a successful error code (in the 200 series) to be classed as a failure.void
setMarshaller
(Jaxb2Marshaller marshaller) Set the marshaller used to create the XML.Methods inherited from class org.springframework.web.client.DefaultResponseErrorHandler
getCharset, getHttpStatusCode, getResponseBody, handleError, hasError, hasError
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.springframework.web.client.ResponseErrorHandler
handleError
-
Constructor Details
-
ClarityFailureResponseErrorHandler
public ClarityFailureResponseErrorHandler()Empty constructor.
-
-
Method Details
-
setMarshaller
@Autowired @Qualifier("clarityJaxbMarshaller") public void setMarshaller(Jaxb2Marshaller marshaller) Set the marshaller used to create the XML.- Parameters:
marshaller
- The Jaxb2Marshaller.
-
hasError
Refinement of the default implementation, as we want anything that's not a successful error code (in the 200 series) to be classed as a failure.- Overrides:
hasError
in classDefaultResponseErrorHandler
- Parameters:
statusCode
- The HTTP status code- Returns:
true
if the response is not in the 200 series of HTTP codes.
-
handleError
See if the response indicates an error and, if the body of the response is a Clarity error reply, create a throwableClarityException
from it and throw that.Normally this test should be redundant, as the
ClarityExceptionAspect
should automatically take care of creating throwableClarityException
s from the response.- Specified by:
handleError
in interfaceResponseErrorHandler
- Overrides:
handleError
in classDefaultResponseErrorHandler
- Parameters:
response
- The HTTP response.- Throws:
IOException
- if there is a problem reading from the response.ClarityException
- if the response is found to be a Clarity exception.- See Also:
-