Class HttpUtils


  • public class HttpUtils
    extends java.lang.Object
    • Constructor Summary

      Constructors 
      Constructor Description
      HttpUtils()  
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.lang.String buildDefaultErrorMessage​(SlingHttpResponse resp)
      Build default error message
      static int[] getExpectedStatus​(int defaultStatus, int... expectedStatus)  
      static int getHttpStatus​(org.apache.http.HttpResponse response)
      Get HTTP Status of the response.
      static java.lang.String getLocationHeader​(org.apache.http.HttpResponse response)
      Get the first 'Location' header and verify it's a valid URI.
      static boolean isInHttpStatusRange​(org.apache.http.HttpResponse response, int range)
      Check if expected status is in range
      static void verifyHttpStatus​(org.apache.http.HttpResponse response, java.lang.String errorMessage, int... expectedStatus)
      Verify expected status and show error message in case expected status is not returned.
      static void verifyHttpStatus​(SlingHttpResponse response, int... expectedStatus)
      Verify expected status and dump response in case expected status is not returned.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • HttpUtils

        public HttpUtils()
    • Method Detail

      • verifyHttpStatus

        public static void verifyHttpStatus​(SlingHttpResponse response,
                                            int... expectedStatus)
                                     throws ClientException
        Verify expected status and dump response in case expected status is not returned. Warning! It will try to consume the entity in case of error
        Parameters:
        response - The Sling HTTP response
        expectedStatus - List of acceptable HTTP Statuses
        Throws:
        ClientException - if status is not expected
      • verifyHttpStatus

        public static void verifyHttpStatus​(org.apache.http.HttpResponse response,
                                            java.lang.String errorMessage,
                                            int... expectedStatus)
                                     throws ClientException
        Verify expected status and show error message in case expected status is not returned.
        Parameters:
        response - The SlingHttpResponse of an executed request.
        errorMessage - error message; if null, errorMessage is extracted from response
        expectedStatus - List of acceptable HTTP Statuses
        Throws:
        ClientException - if status is not expected
      • buildDefaultErrorMessage

        public static java.lang.String buildDefaultErrorMessage​(SlingHttpResponse resp)
        Build default error message
        Parameters:
        resp - The response of a sling request
        Returns:
        default error message
      • getHttpStatus

        public static int getHttpStatus​(org.apache.http.HttpResponse response)
                                 throws ClientException
        Get HTTP Status of the response.
        Parameters:
        response - The RequestExecutor of an executed request.
        Returns:
        The HTTP Status of the response
        Throws:
        ClientException - never (kept for uniformity)
      • getLocationHeader

        public static java.lang.String getLocationHeader​(org.apache.http.HttpResponse response)
                                                  throws ClientException
        Get the first 'Location' header and verify it's a valid URI.
        Parameters:
        response - HttpResponse the http response
        Returns:
        the location path
        Throws:
        ClientException - never (kept for uniformity)
      • isInHttpStatusRange

        public static boolean isInHttpStatusRange​(org.apache.http.HttpResponse response,
                                                  int range)
        Check if expected status is in range
        Parameters:
        response - the http response
        range - the http status range
        Returns:
        true if response is in range
      • getExpectedStatus

        public static int[] getExpectedStatus​(int defaultStatus,
                                              int... expectedStatus)