Class HttpUtils
- java.lang.Object
-
- org.apache.sling.testing.clients.util.HttpUtils
-
public class HttpUtils extends Object
-
-
Constructor Summary
Constructors Constructor Description HttpUtils()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static String
buildDefaultErrorMessage(SlingHttpResponse resp)
Build default error messagestatic int[]
getExpectedStatus(int defaultStatus, int... expectedStatus)
static int
getHttpStatus(org.apache.http.HttpResponse response)
Get HTTP Status of the response.static 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 rangestatic void
verifyHttpStatus(org.apache.http.HttpResponse response, 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.
-
-
-
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 responseexpectedStatus
- 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; ifnull
, errorMessage is extracted from responseexpectedStatus
- 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 responserange
- the http status range- Returns:
- true if response is in range
-
getExpectedStatus
public static int[] getExpectedStatus(int defaultStatus, int... expectedStatus)
-
-