Class MockLowLevelHttpRequest (1.41.8)

public class MockLowLevelHttpRequest extends LowLevelHttpRequest

Beta
Mock for LowLevelHttpRequest.

Implementation is not thread-safe.

Inheritance

java.lang.Object > LowLevelHttpRequest > MockLowLevelHttpRequest

Constructors

MockLowLevelHttpRequest()

public MockLowLevelHttpRequest()

MockLowLevelHttpRequest(String url)

public MockLowLevelHttpRequest(String url)
Parameter
NameDescription
urlString

Request URL or null for none

Methods

addHeader(String name, String value)

public void addHeader(String name, String value)

Adds a header to the HTTP request.

Note that multiple headers of the same name need to be supported, in which case #addHeader will be called for each instance of the header.

Parameters
NameDescription
nameString
valueString
Overrides Exceptions
TypeDescription
IOException

execute()

public LowLevelHttpResponse execute()

Executes the request and returns a low-level HTTP response object.

Returns
TypeDescription
LowLevelHttpResponse
Overrides Exceptions
TypeDescription
IOException

getContentAsString()

public String getContentAsString()

Returns HTTP content as a string, taking care of any encodings of the content if necessary.

Returns an empty string if there is no HTTP content.

Returns
TypeDescription
String
Exceptions
TypeDescription
IOException

getFirstHeaderValue(String name)

public String getFirstHeaderValue(String name)

Returns the value of the first header of the given name or null for none.

Parameter
NameDescription
nameString

header name (may be any case)

Returns
TypeDescription
String

getHeaderValues(String name)

public List<String> getHeaderValues(String name)

Returns the unmodifiable list of values of the headers of the given name (may be empty).

Parameter
NameDescription
nameString

header name (may be any case)

Returns
TypeDescription
List<String>

getHeaders()

public Map<String,List<String>> getHeaders()

Returns an unmodifiable view of the map of lowercase header name to values.

Note that unlike this method, #getFirstHeaderValue(String) and #getHeaderValues(String) are not case sensitive with respect to the input header name.

Returns
TypeDescription
Map<String,List<String>>

getResponse()

public MockLowLevelHttpResponse getResponse()

HTTP response to return from #execute().

Returns
TypeDescription
MockLowLevelHttpResponse

getUrl()

public String getUrl()

Returns the request URL or null for none.

Returns
TypeDescription
String

setResponse(MockLowLevelHttpResponse response)

public MockLowLevelHttpRequest setResponse(MockLowLevelHttpResponse response)

Sets the HTTP response to return from #execute().

By default this is a new instance of MockLowLevelHttpResponse.

Parameter
NameDescription
responseMockLowLevelHttpResponse
Returns
TypeDescription
MockLowLevelHttpRequest

setUrl(String url)

public MockLowLevelHttpRequest setUrl(String url)

Sets the request URL or null for none.

Parameter
NameDescription
urlString
Returns
TypeDescription
MockLowLevelHttpRequest