Class MockLowLevelHttpResponse (1.41.8)

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
NameDescription
nameString

header name

valueString

header value

Returns
TypeDescription
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
TypeDescription
IOException

getContent()

public InputStream getContent()

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

Returns
TypeDescription
InputStream
Overrides Exceptions
TypeDescription
IOException

getContentEncoding()

public String getContentEncoding()

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

Returns
TypeDescription
String
Overrides

getContentLength()

public long getContentLength()

Returns the content length or 0 for none.

Returns
TypeDescription
long
Overrides

getContentType()

public final String getContentType()

Returns the content type or null for none.

Returns
TypeDescription
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
TypeDescription
int
Overrides

getHeaderName(int index)

public String getHeaderName(int index)

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

Parameter
NameDescription
indexint
Returns
TypeDescription
String
Overrides

getHeaderNames()

public final List<String> getHeaderNames()

Returns the list of header names of HTTP response.

Returns
TypeDescription
List<String>

getHeaderValue(int index)

public String getHeaderValue(int index)

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

Parameter
NameDescription
indexint
Returns
TypeDescription
String
Overrides

getHeaderValues()

public final List<String> getHeaderValues()

Returns the list of header values of HTTP response.

Default value is an empty list.

Returns
TypeDescription
List<String>

getReasonPhrase()

public String getReasonPhrase()

Returns the HTTP reason phrase or null for none.

Returns
TypeDescription
String
Overrides

getStatusCode()

public int getStatusCode()

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

Returns
TypeDescription
int
Overrides

getStatusLine()

public String getStatusLine()

Returns the response status line or null for none.

Returns
TypeDescription
String
Overrides

isDisconnected()

public boolean isDisconnected()

Returns whether #disconnect() has been called.

Returns
TypeDescription
boolean

setContent(byte[] byteContent)

public MockLowLevelHttpResponse setContent(byte[] byteContent)

Sets the response content to the given byte array.

Parameter
NameDescription
byteContentbyte[]

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
TypeDescription
MockLowLevelHttpResponse

setContent(InputStream content)

public MockLowLevelHttpResponse setContent(InputStream content)

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

Parameter
NameDescription
contentInputStream
Returns
TypeDescription
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
NameDescription
stringContentString

content string or null for none

Returns
TypeDescription
MockLowLevelHttpResponse

setContentEncoding(String contentEncoding)

public MockLowLevelHttpResponse setContentEncoding(String contentEncoding)

Sets the content encoding or null for none.

Parameter
NameDescription
contentEncodingString
Returns
TypeDescription
MockLowLevelHttpResponse

setContentLength(long contentLength)

public MockLowLevelHttpResponse setContentLength(long contentLength)

Sets the content length or -1 for unknown.

By default it is -1.

Parameter
NameDescription
contentLengthlong
Returns
TypeDescription
MockLowLevelHttpResponse

setContentType(String contentType)

public MockLowLevelHttpResponse setContentType(String contentType)

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

Parameter
NameDescription
contentTypeString
Returns
TypeDescription
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
NameDescription
headerNamesList<String>
Returns
TypeDescription
MockLowLevelHttpResponse

setHeaderValues(List<String> headerValues)

public MockLowLevelHttpResponse setHeaderValues(List<String> headerValues)

Sets the list of header values of HTTP response.

Parameter
NameDescription
headerValuesList<String>
Returns
TypeDescription
MockLowLevelHttpResponse

setReasonPhrase(String reasonPhrase)

public MockLowLevelHttpResponse setReasonPhrase(String reasonPhrase)

Sets the HTTP reason phrase or null for none.

Parameter
NameDescription
reasonPhraseString
Returns
TypeDescription
MockLowLevelHttpResponse

setStatusCode(int statusCode)

public MockLowLevelHttpResponse setStatusCode(int statusCode)

Sets the status code of HTTP response.

Default value is 200.

Parameter
NameDescription
statusCodeint
Returns
TypeDescription
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
TypeDescription
MockLowLevelHttpResponse