Package org.apache.sling.testing.clients

# Class SlingHttpResponse

java.lang.Object
org.apache.sling.testing.clients.SlingHttpResponse

All Implemented Interfaces:
  `Closeable`, `AutoCloseable`, `org.apache.http.client.methods.CloseableHttpResponse`, `org.apache.http.HttpMessage`, `org.apache.http.HttpResponse`

public class SlingHttpResponse extends Object implements org.apache.http.client.methods.CloseableHttpResponse

## Field Summary

Fields
Modifier and Type
Field
Description
`static final String`
`CHANGE_LOG`
`static final String`
`LOCATION`
`static final String`
`MESSAGE`
`static final String`
`PARENT_LOCATION`
`static final String`
`PATH`
`static final String`
`REFERER`
`static final String`
`STATUS`

## Constructor Summary

Constructors
Constructor
Description
`SlingHttpResponse(org.apache.http.client.methods.CloseableHttpResponse response)`

## Method Summary

Modifier and Type
Method
Description
`void`
`addHeader(String name, String value)`
`void`
`addHeader(org.apache.http.Header header)`
`void`
`checkContentContains(String... expected)`
Assert that all the provided `Strings` are contained in the response
`void`
`checkContentRegexp(String... regexp)`
For each regular expression, assert that at least one line of the response matches the expression
`void`
`checkContentType(String expected)`
Assert that response matches supplied content type (from Content-Type header)
`void`
`checkStatus(int expected)`
Assert that response matches supplied status
`void`
`close()`
`boolean`
`containsHeader(String name)`
`protected String`
`extractFromHTMLResponse(String searchPattern)`
Extract information from response
`org.apache.http.Header[]`
`getAllHeaders()`
`String`
`getContent()`
Get the `String` content of the response.
`org.apache.http.HttpEntity`
`getEntity()`
`org.apache.http.Header`
`getFirstHeader(String name)`
`org.apache.http.Header[]`
`getHeaders(String name)`
`org.apache.http.Header`
`getLastHeader(String name)`
`Locale`
`getLocale()`
`org.apache.http.params.HttpParams`
`getParams()`
`org.apache.http.ProtocolVersion`
`getProtocolVersion()`
`String`
`getSlingChangeLog()`
Get change log from Sling Response
`String[]`
`getSlingCopyPaths()`
Get copy paths from message
`String`
`getSlingLocation()`
Get location from Sling Response
`String`
`getSlingMessage()`
Get message from Sling Response
`String`
`getSlingParentLocation()`
Get parent location from Sling Response
`String`
`getSlingPath()`
Get path from Sling Response
`String`
`getSlingReferer()`
Get referer from Sling Response
`String`
`getSlingStatus()`
Get status from Sling Response
`int`
`getSlingStatusAsInt()`
Get status from Sling Response as integer
`org.apache.http.StatusLine`
`getStatusLine()`
`org.apache.http.HeaderIterator`
`headerIterator()`
`org.apache.http.HeaderIterator`
`headerIterator(String name)`
`boolean`
`isConsumed()`
`void`
`removeHeader(org.apache.http.Header header)`
`void`
`removeHeaders(String name)`
`void`
`setEntity(org.apache.http.HttpEntity entity)`
`void`
`setHeader(String name, String value)`
`void`
`setHeader(org.apache.http.Header header)`
`void`
`setHeaders(org.apache.http.Header[] headers)`
`void`
`setLocale(Locale loc)`
`void`
`setParams(org.apache.http.params.HttpParams params)`
`void`
`setReasonPhrase(String reason)`
`void`
`setStatusCode(int code)`
`void`
`setStatusLine(org.apache.http.ProtocolVersion ver, int code)`
`void`
`setStatusLine(org.apache.http.ProtocolVersion ver, int code, String reason)`
`void`
`setStatusLine(org.apache.http.StatusLine statusline)`

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Field Details

### STATUS

public static final String STATUS

See Also:
  - Constant Field Values

### MESSAGE

public static final String MESSAGE

See Also:
  - Constant Field Values

### LOCATION

public static final String LOCATION

See Also:
  - Constant Field Values

### PARENT_LOCATION

public static final String PARENT_LOCATION

See Also:
  - Constant Field Values

### PATH

public static final String PATH

See Also:
  - Constant Field Values

### REFERER

public static final String REFERER

See Also:
  - Constant Field Values

### CHANGE_LOG

public static final String CHANGE_LOG

See Also:
  - Constant Field Values

## Constructor Details

### SlingHttpResponse

public SlingHttpResponse(org.apache.http.client.methods.CloseableHttpResponse response)

## Method Details

### getContent

public String getContent()

Get the `String` content of the response.

The content is cached so it is safe to call this method several times.

Attention! Calling this method consumes the entity, so it cannot be used as an InputStream later

Returns:
  the content as String

### isConsumed

public boolean isConsumed()

### checkStatus

public void checkStatus(int expected) throws TestingValidationException

Assert that response matches supplied status

Parameters:
  `expected` - the expected http status
Throws:
  `TestingValidationException` - if the response does not match the expected

### checkContentType

public void checkContentType(String expected) throws TestingValidationException

Assert that response matches supplied content type (from Content-Type header)

Parameters:
  `expected` - the expected content type
Throws:
  `TestingValidationException` - if the response content type does not match the expected

### checkContentRegexp

public void checkContentRegexp(String... regexp) throws TestingValidationException

For each regular expression, assert that at least one line of the response matches the expression

The regular expressions are automatically prefixed and suffixed with .* it order to partial-match the lines

Parameters:
  `regexp` - list of regular expressions
Throws:
  `TestingValidationException` - if the response content does not match one of the regexp

### checkContentContains

public void checkContentContains(String... expected) throws TestingValidationException

Assert that all the provided `Strings` are contained in the response

Parameters:
  `expected` - list of expected strings
Throws:
  `TestingValidationException` - if the response content does not match one of the strings

### getSlingStatus

public String getSlingStatus()
Get status from Sling Response

Returns:
  Sling Status

### getSlingStatusAsInt

public int getSlingStatusAsInt() throws NumberFormatException
Get status from Sling Response as integer

Returns:
  Sling Status
Throws:
  `NumberFormatException` - if sling status can't be parsed as a number

### getSlingMessage

public String getSlingMessage()
Get message from Sling Response

Returns:
  Sling Message

### getSlingCopyPaths

public String[] getSlingCopyPaths()
Get copy paths from message

Returns:
  copy paths as String Array

### getSlingLocation

public String getSlingLocation()
Get location from Sling Response

Returns:
  Sling Location

### getSlingParentLocation

public String getSlingParentLocation()
Get parent location from Sling Response

Returns:
  Sling Parent Location

### getSlingPath

public String getSlingPath()
Get path from Sling Response

Returns:
  Sling Path

### getSlingReferer

public String getSlingReferer()
Get referer from Sling Response

Returns:
  Sling Referer

### getSlingChangeLog

public String getSlingChangeLog()
Get change log from Sling Response

Returns:
  Sling Change Log

### extractFromHTMLResponse

protected String extractFromHTMLResponse(String searchPattern)
Extract information from response

Parameters:
  `searchPattern` - search pattern to look for
Returns:
  Sling information

### getStatusLine

public org.apache.http.StatusLine getStatusLine()

Specified by:
  `getStatusLine` in interface `org.apache.http.HttpResponse`

### setStatusLine

public void setStatusLine(org.apache.http.StatusLine statusline)

Specified by:
  `setStatusLine` in interface `org.apache.http.HttpResponse`

### setStatusLine

public void setStatusLine(org.apache.http.ProtocolVersion ver, int code)

Specified by:
  `setStatusLine` in interface `org.apache.http.HttpResponse`

### setStatusLine

public void setStatusLine(org.apache.http.ProtocolVersion ver, int code, String reason)

Specified by:
  `setStatusLine` in interface `org.apache.http.HttpResponse`

### setStatusCode

public void setStatusCode(int code) throws IllegalStateException

Specified by:
  `setStatusCode` in interface `org.apache.http.HttpResponse`
Throws:
  `IllegalStateException`

### setReasonPhrase

public void setReasonPhrase(String reason) throws IllegalStateException

Specified by:
  `setReasonPhrase` in interface `org.apache.http.HttpResponse`
Throws:
  `IllegalStateException`

### getEntity

public org.apache.http.HttpEntity getEntity()

Specified by:
  `getEntity` in interface `org.apache.http.HttpResponse`

### setEntity

public void setEntity(org.apache.http.HttpEntity entity)

Specified by:
  `setEntity` in interface `org.apache.http.HttpResponse`

### getLocale

public Locale getLocale()

Specified by:
  `getLocale` in interface `org.apache.http.HttpResponse`

### setLocale

public void setLocale(Locale loc)

Specified by:
  `setLocale` in interface `org.apache.http.HttpResponse`

### getProtocolVersion

public org.apache.http.ProtocolVersion getProtocolVersion()

Specified by:
  `getProtocolVersion` in interface `org.apache.http.HttpMessage`

### containsHeader

public boolean containsHeader(String name)

Specified by:
  `containsHeader` in interface `org.apache.http.HttpMessage`

### getHeaders

public org.apache.http.Header[] getHeaders(String name)

Specified by:
  `getHeaders` in interface `org.apache.http.HttpMessage`

### getFirstHeader

public org.apache.http.Header getFirstHeader(String name)

Specified by:
  `getFirstHeader` in interface `org.apache.http.HttpMessage`

### getLastHeader

public org.apache.http.Header getLastHeader(String name)

Specified by:
  `getLastHeader` in interface `org.apache.http.HttpMessage`

### getAllHeaders

public org.apache.http.Header[] getAllHeaders()

Specified by:
  `getAllHeaders` in interface `org.apache.http.HttpMessage`

### addHeader

public void addHeader(org.apache.http.Header header)

Specified by:
  `addHeader` in interface `org.apache.http.HttpMessage`

### addHeader

public void addHeader(String name, String value)

Specified by:
  `addHeader` in interface `org.apache.http.HttpMessage`

### setHeader

public void setHeader(org.apache.http.Header header)

Specified by:
  `setHeader` in interface `org.apache.http.HttpMessage`

### setHeader

public void setHeader(String name, String value)

Specified by:
  `setHeader` in interface `org.apache.http.HttpMessage`

### setHeaders

public void setHeaders(org.apache.http.Header[] headers)

Specified by:
  `setHeaders` in interface `org.apache.http.HttpMessage`

### removeHeader

public void removeHeader(org.apache.http.Header header)

Specified by:
  `removeHeader` in interface `org.apache.http.HttpMessage`

### removeHeaders

public void removeHeaders(String name)

Specified by:
  `removeHeaders` in interface `org.apache.http.HttpMessage`

### headerIterator

public org.apache.http.HeaderIterator headerIterator()

Specified by:
  `headerIterator` in interface `org.apache.http.HttpMessage`

### headerIterator

public org.apache.http.HeaderIterator headerIterator(String name)

Specified by:
  `headerIterator` in interface `org.apache.http.HttpMessage`

### getParams

public org.apache.http.params.HttpParams getParams()

Specified by:
  `getParams` in interface `org.apache.http.HttpMessage`

### setParams

public void setParams(org.apache.http.params.HttpParams params)

Specified by:
  `setParams` in interface `org.apache.http.HttpMessage`

### close

public void close() throws IOException

Specified by:
  `close` in interface `AutoCloseable`
Specified by:
  `close` in interface `Closeable`
Throws:
  `IOException`