Class HttpUtils


  • public class HttpUtils
    extends Object
    • Constructor Detail

      • HttpUtils

        public HttpUtils()
    • Method Detail

      • verifyHttpStatus

        public static void verifyHttpStatus​(SlingHttpResponse response,
                                            int... expectedStatus)
                                     throws TestingValidationException
        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:
        TestingValidationException - if status is not expected
      • verifyHttpStatus

        public static void verifyHttpStatus​(org.apache.http.HttpResponse response,
                                            String errorMessage,
                                            int... expectedStatus)
                                     throws TestingValidationException
        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:
        TestingValidationException - if status is not expected
      • buildDefaultErrorMessage

        public static 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)
        Get HTTP Status of the response.
        Parameters:
        response - The RequestExecutor of an executed request.
        Returns:
        The HTTP Status of the response
      • getLocationHeader

        public static String getLocationHeader​(org.apache.http.HttpResponse response)
                                        throws TestingValidationException
        Get the first 'Location' header and verify it's a valid URI.
        Parameters:
        response - HttpResponse the http response
        Returns:
        the location path
        Throws:
        TestingValidationException - 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)