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 statusClientException
- if the response does not match the expectedpublic void checkContentType(String expected) throws ClientException
Assert that response matches supplied content type (from Content-Type header)
expected
- the expected content typeClientException
- if the response content type does not match the expectedpublic 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 expressionsClientException
- if the response content does not match one of the regexppublic void checkContentContains(String... expected) throws ClientException
Assert that all the provided Strings
are contained in the response
expected
- list of expected stringsClientException
- @throws ClientException if the response content does not match one of the stringspublic String getSlingStatus()
public int getSlingStatusAsInt() throws NumberFormatException
NumberFormatException
- if sling status can't be parsed as a numberpublic 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.HttpResponse
public void setStatusLine(org.apache.http.StatusLine statusline)
setStatusLine
in interface org.apache.http.HttpResponse
public void setStatusLine(org.apache.http.ProtocolVersion ver, int code)
setStatusLine
in interface org.apache.http.HttpResponse
public void setStatusLine(org.apache.http.ProtocolVersion ver, int code, String reason)
setStatusLine
in interface org.apache.http.HttpResponse
public void setStatusCode(int code) throws IllegalStateException
setStatusCode
in interface org.apache.http.HttpResponse
IllegalStateException
public void setReasonPhrase(String reason) throws IllegalStateException
setReasonPhrase
in interface org.apache.http.HttpResponse
IllegalStateException
public org.apache.http.HttpEntity getEntity()
getEntity
in interface org.apache.http.HttpResponse
public void setEntity(org.apache.http.HttpEntity entity)
setEntity
in interface org.apache.http.HttpResponse
public Locale getLocale()
getLocale
in interface org.apache.http.HttpResponse
public void setLocale(Locale loc)
setLocale
in interface org.apache.http.HttpResponse
public org.apache.http.ProtocolVersion getProtocolVersion()
getProtocolVersion
in interface org.apache.http.HttpMessage
public boolean containsHeader(String name)
containsHeader
in interface org.apache.http.HttpMessage
public org.apache.http.Header[] getHeaders(String name)
getHeaders
in interface org.apache.http.HttpMessage
public org.apache.http.Header getFirstHeader(String name)
getFirstHeader
in interface org.apache.http.HttpMessage
public org.apache.http.Header getLastHeader(String name)
getLastHeader
in interface org.apache.http.HttpMessage
public org.apache.http.Header[] getAllHeaders()
getAllHeaders
in interface org.apache.http.HttpMessage
public void addHeader(org.apache.http.Header header)
addHeader
in interface org.apache.http.HttpMessage
public void addHeader(String name, String value)
addHeader
in interface org.apache.http.HttpMessage
public void setHeader(org.apache.http.Header header)
setHeader
in interface org.apache.http.HttpMessage
public void setHeader(String name, String value)
setHeader
in interface org.apache.http.HttpMessage
public void setHeaders(org.apache.http.Header[] headers)
setHeaders
in interface org.apache.http.HttpMessage
public void removeHeader(org.apache.http.Header header)
removeHeader
in interface org.apache.http.HttpMessage
public void removeHeaders(String name)
removeHeaders
in interface org.apache.http.HttpMessage
public org.apache.http.HeaderIterator headerIterator()
headerIterator
in interface org.apache.http.HttpMessage
public org.apache.http.HeaderIterator headerIterator(String name)
headerIterator
in interface org.apache.http.HttpMessage
public org.apache.http.params.HttpParams getParams()
getParams
in interface org.apache.http.HttpMessage
public void setParams(org.apache.http.params.HttpParams params)
setParams
in interface org.apache.http.HttpMessage
public void close() throws IOException
close
in interface Closeable
close
in interface AutoCloseable
IOException
Copyright © 2007–2018 The Apache Software Foundation. All rights reserved.