Package org.apache.sling.testing.clients.util

# 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

Modifier and Type
Method
Description
`static 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 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, 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 Details

### HttpUtils

public HttpUtils()

## Method Details

### 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)