public class SlingHttpResponse extends Object implements org.apache.http.client.methods.CloseableHttpResponse
| Modifier and Type | Field and Description |
|---|---|
static String |
CHANGE_LOG |
static String |
LOCATION |
static String |
MESSAGE |
static String |
PARENT_LOCATION |
static String |
PATH |
static String |
REFERER |
static String |
STATUS |
| Constructor and Description |
|---|
SlingHttpResponse(org.apache.http.client.methods.CloseableHttpResponse response) |
| Modifier and Type | Method and Description |
|---|---|
void |
addHeader(org.apache.http.Header header) |
void |
addHeader(String name,
String value) |
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(org.apache.http.Header header) |
void |
setHeader(String name,
String value) |
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) |
public static final String STATUS
public static final String MESSAGE
public static final String LOCATION
public static final String PARENT_LOCATION
public static final String PATH
public static final String REFERER
public static final String CHANGE_LOG
public SlingHttpResponse(org.apache.http.client.methods.CloseableHttpResponse response)
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
public boolean isConsumed()
public void checkStatus(int expected)
throws ClientException
Assert that response matches supplied status
expected - the expected http statusAssertionError - if the response does not match the expectedClientExceptionpublic void checkContentType(String expected) throws ClientException
Assert that response matches supplied content type (from Content-Type header)
expected - the expected content typeAssertionError - if the response content type does not match the expectedClientExceptionpublic void checkContentRegexp(String... regexp) throws ClientException
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
regexp - list of regular expressionsAssertionError - if the response content does not match one of the regexpClientExceptionpublic void checkContentContains(String... expected) throws ClientException
Assert that all the provided Strings are contained in the response
expected - list of expected stringsClientExceptionpublic String getSlingStatus()
public int getSlingStatusAsInt()
throws NumberFormatException
NumberFormatExceptionpublic String getSlingMessage()
public String[] getSlingCopyPaths()
public String getSlingLocation()
public String getSlingParentLocation()
public String getSlingPath()
public String getSlingReferer()
public String getSlingChangeLog()
protected String extractFromHTMLResponse(String searchPattern)
searchPattern - search pattern to look forpublic org.apache.http.StatusLine getStatusLine()
getStatusLine in interface org.apache.http.HttpResponsepublic void setStatusLine(org.apache.http.StatusLine statusline)
setStatusLine in interface org.apache.http.HttpResponsepublic void setStatusLine(org.apache.http.ProtocolVersion ver,
int code)
setStatusLine in interface org.apache.http.HttpResponsepublic void setStatusLine(org.apache.http.ProtocolVersion ver,
int code,
String reason)
setStatusLine in interface org.apache.http.HttpResponsepublic void setStatusCode(int code)
throws IllegalStateException
setStatusCode in interface org.apache.http.HttpResponseIllegalStateExceptionpublic void setReasonPhrase(String reason) throws IllegalStateException
setReasonPhrase in interface org.apache.http.HttpResponseIllegalStateExceptionpublic org.apache.http.HttpEntity getEntity()
getEntity in interface org.apache.http.HttpResponsepublic void setEntity(org.apache.http.HttpEntity entity)
setEntity in interface org.apache.http.HttpResponsepublic Locale getLocale()
getLocale in interface org.apache.http.HttpResponsepublic void setLocale(Locale loc)
setLocale in interface org.apache.http.HttpResponsepublic org.apache.http.ProtocolVersion getProtocolVersion()
getProtocolVersion in interface org.apache.http.HttpMessagepublic boolean containsHeader(String name)
containsHeader in interface org.apache.http.HttpMessagepublic org.apache.http.Header[] getHeaders(String name)
getHeaders in interface org.apache.http.HttpMessagepublic org.apache.http.Header getFirstHeader(String name)
getFirstHeader in interface org.apache.http.HttpMessagepublic org.apache.http.Header getLastHeader(String name)
getLastHeader in interface org.apache.http.HttpMessagepublic org.apache.http.Header[] getAllHeaders()
getAllHeaders in interface org.apache.http.HttpMessagepublic void addHeader(org.apache.http.Header header)
addHeader in interface org.apache.http.HttpMessagepublic void addHeader(String name, String value)
addHeader in interface org.apache.http.HttpMessagepublic void setHeader(org.apache.http.Header header)
setHeader in interface org.apache.http.HttpMessagepublic void setHeader(String name, String value)
setHeader in interface org.apache.http.HttpMessagepublic void setHeaders(org.apache.http.Header[] headers)
setHeaders in interface org.apache.http.HttpMessagepublic void removeHeader(org.apache.http.Header header)
removeHeader in interface org.apache.http.HttpMessagepublic void removeHeaders(String name)
removeHeaders in interface org.apache.http.HttpMessagepublic org.apache.http.HeaderIterator headerIterator()
headerIterator in interface org.apache.http.HttpMessagepublic org.apache.http.HeaderIterator headerIterator(String name)
headerIterator in interface org.apache.http.HttpMessagepublic org.apache.http.params.HttpParams getParams()
getParams in interface org.apache.http.HttpMessagepublic void setParams(org.apache.http.params.HttpParams params)
setParams in interface org.apache.http.HttpMessagepublic void close()
throws IOException
close in interface Closeableclose in interface AutoCloseableIOExceptionCopyright © 2007–2017 The Apache Software Foundation. All rights reserved.