Class ClarityFailureResponseErrorHandler

java.lang.Object
org.springframework.web.client.DefaultResponseErrorHandler
org.cruk.clarity.api.http.ClarityFailureResponseErrorHandler
All Implemented Interfaces:
ResponseErrorHandler

public class ClarityFailureResponseErrorHandler extends DefaultResponseErrorHandler
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 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

      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.
      Overrides:
      hasError in class DefaultResponseErrorHandler
      Parameters:
      statusCode - The HTTP status code
      Returns:
      true if the response is not in the 200 series of HTTP codes.
    • handleError

      public void handleError(ClientHttpResponse response) throws IOException
      See if the response indicates an error and, if the body of the response is a Clarity error reply, create a throwable ClarityException from it and throw that.

      Normally this test should be redundant, as the ClarityExceptionAspect should automatically take care of creating throwable ClarityExceptions from the response.

      Specified by:
      handleError in interface ResponseErrorHandler
      Overrides:
      handleError in class DefaultResponseErrorHandler
      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: