public class MockLowLevelHttpResponse extends LowLevelHttpResponse
Constructors
MockLowLevelHttpResponse()
public MockLowLevelHttpResponse()
Methods
addHeader(String name, String value)
public MockLowLevelHttpResponse addHeader(String name, String value)
Adds a header to the response.
Name | Description |
name | String header name |
value | String header value |
Type | Description |
MockLowLevelHttpResponse |
disconnect()
public void disconnect()
Default implementation does nothing, but subclasses may override to attempt to abort the connection or release allocated system resources for this connection.
Type | Description |
IOException |
getContent()
public InputStream getContent()
Returns the HTTP response content input stream or null
for none.
Type | Description |
InputStream |
Type | Description |
IOException |
getContentEncoding()
public String getContentEncoding()
Returns the content encoding (for example "gzip"
) or null
for none.
Type | Description |
String |
getContentLength()
public long getContentLength()
Returns the content length or 0
for none.
Type | Description |
long |
getContentType()
public final String getContentType()
Returns the content type or null
for none.
Type | Description |
String |
getHeaderCount()
public int getHeaderCount()
Returns the number of HTTP response headers.
Note that multiple headers of the same name need to be supported, in which case each header value is treated as a separate header.
Type | Description |
int |
getHeaderName(int index)
public String getHeaderName(int index)
Returns the HTTP response header name at the given zero-based index.
Name | Description |
index | int |
Type | Description |
String |
getHeaderNames()
public final List<String> getHeaderNames()
Returns the list of header names of HTTP response.
Type | Description |
List<String> |
getHeaderValue(int index)
public String getHeaderValue(int index)
Returns the HTTP response header value at the given zero-based index.
Name | Description |
index | int |
Type | Description |
String |
getHeaderValues()
public final List<String> getHeaderValues()
Returns the list of header values of HTTP response.
Default value is an empty list.
Type | Description |
List<String> |
getReasonPhrase()
public String getReasonPhrase()
Returns the HTTP reason phrase or null
for none.
Type | Description |
String |
getStatusCode()
public int getStatusCode()
Returns the response status code or <=0
for none.
Type | Description |
int |
getStatusLine()
public String getStatusLine()
Returns the response status line or null
for none.
Type | Description |
String |
isDisconnected()
public boolean isDisconnected()
Returns whether #disconnect() has been called.
Type | Description |
boolean |
setContent(byte[] byteContent)
public MockLowLevelHttpResponse setContent(byte[] byteContent)
Sets the response content to the given byte array.
Name | Description |
byteContent | byte[] content byte array, or If the byte array is |
Type | Description |
MockLowLevelHttpResponse |
setContent(InputStream content)
public MockLowLevelHttpResponse setContent(InputStream content)
Sets the input stream content of HTTP response or null
for none.
Name | Description |
content | InputStream |
Type | Description |
MockLowLevelHttpResponse |
setContent(String stringContent)
public MockLowLevelHttpResponse setContent(String stringContent)
Sets the response content to the given content string.
If the input string is null
, it will set the content to null
. Else, it will
use TestableByteArrayInputStream with the UTF-8 encoded string content.
Name | Description |
stringContent | String content string or |
Type | Description |
MockLowLevelHttpResponse |
setContentEncoding(String contentEncoding)
public MockLowLevelHttpResponse setContentEncoding(String contentEncoding)
Sets the content encoding or null
for none.
Name | Description |
contentEncoding | String |
Type | Description |
MockLowLevelHttpResponse |
setContentLength(long contentLength)
public MockLowLevelHttpResponse setContentLength(long contentLength)
Sets the content length or -1
for unknown.
By default it is -1
.
Name | Description |
contentLength | long |
Type | Description |
MockLowLevelHttpResponse |
setContentType(String contentType)
public MockLowLevelHttpResponse setContentType(String contentType)
Sets the content type of HTTP response or null
for none.
Name | Description |
contentType | String |
Type | Description |
MockLowLevelHttpResponse |
setHeaderNames(List<String> headerNames)
public MockLowLevelHttpResponse setHeaderNames(List<String> headerNames)
Sets the list of header names of HTTP response.
Default value is an empty list.
Name | Description |
headerNames | List<String> |
Type | Description |
MockLowLevelHttpResponse |
setHeaderValues(List<String> headerValues)
public MockLowLevelHttpResponse setHeaderValues(List<String> headerValues)
Sets the list of header values of HTTP response.
Name | Description |
headerValues | List<String> |
Type | Description |
MockLowLevelHttpResponse |
setReasonPhrase(String reasonPhrase)
public MockLowLevelHttpResponse setReasonPhrase(String reasonPhrase)
Sets the HTTP reason phrase or null
for none.
Name | Description |
reasonPhrase | String |
Type | Description |
MockLowLevelHttpResponse |
setStatusCode(int statusCode)
public MockLowLevelHttpResponse setStatusCode(int statusCode)
Sets the status code of HTTP response.
Default value is 200
.
Name | Description |
statusCode | int |
Type | Description |
MockLowLevelHttpResponse |
setZeroContent()
public MockLowLevelHttpResponse setZeroContent()
Sets the content to null
and the content length to 0. Note that the result will have a
content length header whose value is 0.
Type | Description |
MockLowLevelHttpResponse |