Class MockLowLevelHttpResponse (1.44.2)

public class MockLowLevelHttpResponse extends LowLevelHttpResponse

Beta
Mock for LowLevelHttpResponse.

Implementation is not thread-safe.

Inheritance

java.lang.Object > LowLevelHttpResponse > MockLowLevelHttpResponse

Constructors

MockLowLevelHttpResponse()

public MockLowLevelHttpResponse()

Methods

addHeader(String name, String value)

public MockLowLevelHttpResponse addHeader(String name, String value)

Adds a header to the response.

Parameters
Name Description
name String

header name

value String

header value

Returns
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.

Overrides
Exceptions
Type Description
IOException

getContent()

public InputStream getContent()

Returns the HTTP response content input stream or null for none.

Returns
Type Description
InputStream
Overrides
Exceptions
Type Description
IOException

getContentEncoding()

public String getContentEncoding()

Returns the content encoding (for example "gzip") or null for none.

Returns
Type Description
String
Overrides

getContentLength()

public long getContentLength()

Returns the content length or 0 for none.

Returns
Type Description
long
Overrides

getContentType()

public final String getContentType()

Returns the content type or null for none.

Returns
Type Description
String
Overrides

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.

Returns
Type Description
int
Overrides

getHeaderName(int index)

public String getHeaderName(int index)

Returns the HTTP response header name at the given zero-based index.

Parameter
Name Description
index int
Returns
Type Description
String
Overrides

getHeaderNames()

public final List<String> getHeaderNames()

Returns the list of header names of HTTP response.

Returns
Type Description
List<String>

getHeaderValue(int index)

public String getHeaderValue(int index)

Returns the HTTP response header value at the given zero-based index.

Parameter
Name Description
index int
Returns
Type Description
String
Overrides

getHeaderValues()

public final List<String> getHeaderValues()

Returns the list of header values of HTTP response.

Default value is an empty list.

Returns
Type Description
List<String>

getReasonPhrase()

public String getReasonPhrase()

Returns the HTTP reason phrase or null for none.

Returns
Type Description
String
Overrides

getStatusCode()

public int getStatusCode()

Returns the response status code or <=0 for none.

Returns
Type Description
int
Overrides

getStatusLine()

public String getStatusLine()

Returns the response status line or null for none.

Returns
Type Description
String
Overrides

isDisconnected()

public boolean isDisconnected()

Returns whether #disconnect() has been called.

Returns
Type Description
boolean

setContent(byte[] byteContent)

public MockLowLevelHttpResponse setContent(byte[] byteContent)

Sets the response content to the given byte array.

Parameter
Name Description
byteContent byte[]

content byte array, or null for none.

If the byte array is null, the method invokes #setZeroContent. Otherwise, byteContent is wrapped in a TestableByteArrayInputStream and becomes this MockLowLevelHttpResponse's contents.

Returns
Type Description
MockLowLevelHttpResponse

setContent(InputStream content)

public MockLowLevelHttpResponse setContent(InputStream content)

Sets the input stream content of HTTP response or null for none.

Parameter
Name Description
content InputStream
Returns
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.

Parameter
Name Description
stringContent String

content string or null for none

Returns
Type Description
MockLowLevelHttpResponse

setContentEncoding(String contentEncoding)

public MockLowLevelHttpResponse setContentEncoding(String contentEncoding)

Sets the content encoding or null for none.

Parameter
Name Description
contentEncoding String
Returns
Type Description
MockLowLevelHttpResponse

setContentLength(long contentLength)

public MockLowLevelHttpResponse setContentLength(long contentLength)

Sets the content length or -1 for unknown.

By default it is -1.

Parameter
Name Description
contentLength long
Returns
Type Description
MockLowLevelHttpResponse

setContentType(String contentType)

public MockLowLevelHttpResponse setContentType(String contentType)

Sets the content type of HTTP response or null for none.

Parameter
Name Description
contentType String
Returns
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.

Parameter
Name Description
headerNames List<String>
Returns
Type Description
MockLowLevelHttpResponse

setHeaderValues(List<String> headerValues)

public MockLowLevelHttpResponse setHeaderValues(List<String> headerValues)

Sets the list of header values of HTTP response.

Parameter
Name Description
headerValues List<String>
Returns
Type Description
MockLowLevelHttpResponse

setReasonPhrase(String reasonPhrase)

public MockLowLevelHttpResponse setReasonPhrase(String reasonPhrase)

Sets the HTTP reason phrase or null for none.

Parameter
Name Description
reasonPhrase String
Returns
Type Description
MockLowLevelHttpResponse

setStatusCode(int statusCode)

public MockLowLevelHttpResponse setStatusCode(int statusCode)

Sets the status code of HTTP response.

Default value is 200.

Parameter
Name Description
statusCode int
Returns
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.

Returns
Type Description
MockLowLevelHttpResponse