Class HttpResponseException

  • All Implemented Interfaces:
    java.io.Serializable

    public class HttpResponseException
    extends java.io.IOException
    Exception thrown when an error status code is detected in an HTTP response.

    Implementation is not thread safe.

    Since:
    1.0
    See Also:
    Serialized Form
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.StringBuilder computeMessageBuffer​(HttpResponse response)
      Returns an exception message string builder to use for the given HTTP response.
      int getAttemptCount()
      Returns the attempt count
      java.lang.String getContent()
      Returns the HTTP response content or null for none.
      HttpHeaders getHeaders()
      Returns the HTTP response headers.
      int getStatusCode()
      Returns the HTTP status code or 0 for none.
      java.lang.String getStatusMessage()
      Returns the HTTP status message or null for none.
      boolean isSuccessStatusCode()
      Returns whether received a successful HTTP status code >= 200 && < 300 (see getStatusCode()).
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getCause, getLocalizedMessage, getMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace, toString
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • statusCode

        private final int statusCode
        HTTP status code.
      • statusMessage

        private final java.lang.String statusMessage
        Status message or null.
      • headers

        private final transient HttpHeaders headers
        HTTP headers.
      • content

        private final java.lang.String content
        HTTP response content or null for none.
      • attemptCount

        private final int attemptCount
        Number of attempts performed
    • Constructor Detail

      • HttpResponseException

        public HttpResponseException​(HttpResponse response)
        Constructor that constructs a detail message from the given HTTP response that includes the status code, status message and HTTP response content.

        Callers of this constructor should call HttpResponse.disconnect() after HttpResponseException is instantiated. Example usage:

         try {
         throw new HttpResponseException(response);
         } finally {
         response.disconnect();
         }
         
        Parameters:
        response - HTTP response
    • Method Detail

      • isSuccessStatusCode

        public final boolean isSuccessStatusCode()
        Returns whether received a successful HTTP status code >= 200 && < 300 (see getStatusCode()).
        Since:
        1.7
      • getStatusCode

        public final int getStatusCode()
        Returns the HTTP status code or 0 for none.
        Since:
        1.7
      • getStatusMessage

        public final java.lang.String getStatusMessage()
        Returns the HTTP status message or null for none.
        Since:
        1.9
      • getHeaders

        public HttpHeaders getHeaders()
        Returns the HTTP response headers.
        Since:
        1.7
      • getContent

        public final java.lang.String getContent()
        Returns the HTTP response content or null for none.
        Since:
        1.14
      • getAttemptCount

        public final int getAttemptCount()
        Returns the attempt count
        Since:
        1.41
      • computeMessageBuffer

        public static java.lang.StringBuilder computeMessageBuffer​(HttpResponse response)
        Returns an exception message string builder to use for the given HTTP response.
        Since:
        1.7