Class HttpUtils
- java.lang.Object
-
- org.apache.sling.testing.clients.util.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.StringbuildDefaultErrorMessage(SlingHttpResponse resp)Build default error messagestatic int[]getExpectedStatus(int defaultStatus, int... expectedStatus)static intgetHttpStatus(org.apache.http.HttpResponse response)Get HTTP Status of the response.static java.lang.StringgetLocationHeader(org.apache.http.HttpResponse response)Get the first 'Location' header and verify it's a valid URI.static booleanisInHttpStatusRange(org.apache.http.HttpResponse response, int range)Check if expected status is in rangestatic voidverifyHttpStatus(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 voidverifyHttpStatus(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 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 responseexpectedStatus- 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 ClientExceptionVerify 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:
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 ClientExceptionGet 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 ClientExceptionGet 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 responserange- the http status range- Returns:
- true if response is in range
-
getExpectedStatus
public static int[] getExpectedStatus(int defaultStatus, int... expectedStatus)
-
-