Class MockHttpURLConnection (1.43.0)

public class MockHttpURLConnection extends HttpURLConnection

Beta
Mock for HttpURLConnection.

Implementation is not thread-safe.

Inheritance

java.lang.Object > java.net.URLConnection > HttpURLConnection > MockHttpURLConnection

Static Fields

ERROR_BUF (deprecated)

public static final byte[] ERROR_BUF

Deprecated. As of 1.20. Use #setErrorStream(InputStream) instead.

The error byte array which represents the content when the status code is greater or equal to 400.

Field Value
TypeDescription
byte[]

INPUT_BUF (deprecated)

public static final byte[] INPUT_BUF

Deprecated. As of 1.20. Use #setInputStream(InputStream) instead.

The input byte array which represents the content when the status code is less then 400.

Field Value
TypeDescription
byte[]

Constructors

MockHttpURLConnection(URL u)

public MockHttpURLConnection(URL u)
Parameter
NameDescription
uURL

the URL or null for none

Methods

addHeader(String name, String value)

public MockHttpURLConnection addHeader(String name, String value)

Sets a custom response header.

Parameters
NameDescription
nameString
valueString
Returns
TypeDescription
MockHttpURLConnection

connect()

public void connect()
Overrides Exceptions
TypeDescription
IOException

disconnect()

public void disconnect()
Overrides

doOutputCalled()

public final boolean doOutputCalled()

Returns whether #doOutput was called.

Returns
TypeDescription
boolean

getChunkLength()

public int getChunkLength()
Returns
TypeDescription
int

getErrorStream()

public InputStream getErrorStream()
Returns
TypeDescription
InputStream
Overrides

getHeaderField(String name)

public String getHeaderField(String name)
Parameter
NameDescription
nameString
Returns
TypeDescription
String
Overrides

getHeaderFields()

public Map<String,List<String>> getHeaderFields()
Returns
TypeDescription
Map<String,List<String>>
Overrides

getInputStream()

public InputStream getInputStream()
Returns
TypeDescription
InputStream
Overrides Exceptions
TypeDescription
IOException

getOutputStream()

public OutputStream getOutputStream()
Returns
TypeDescription
OutputStream
Overrides Exceptions
TypeDescription
IOException

getResponseCode()

public int getResponseCode()
Returns
TypeDescription
int
Overrides Exceptions
TypeDescription
IOException

isSetFixedLengthStreamingModeIntCalled()

public boolean isSetFixedLengthStreamingModeIntCalled()
Returns
TypeDescription
boolean

isSetFixedLengthStreamingModeLongCalled()

public boolean isSetFixedLengthStreamingModeLongCalled()
Returns
TypeDescription
boolean

setDoOutput(boolean dooutput)

public void setDoOutput(boolean dooutput)
Parameter
NameDescription
dooutputboolean
Overrides

setErrorStream(InputStream is)

public MockHttpURLConnection setErrorStream(InputStream is)

Sets the error stream.

To prevent incidental overwrite, only the first non-null assignment is honored.

Parameter
NameDescription
isInputStream
Returns
TypeDescription
MockHttpURLConnection

setFixedLengthStreamingMode(int contentLength)

public void setFixedLengthStreamingMode(int contentLength)
Parameter
NameDescription
contentLengthint
Overrides

setFixedLengthStreamingMode(long contentLength)

public void setFixedLengthStreamingMode(long contentLength)
Parameter
NameDescription
contentLengthlong
Overrides

setInputStream(InputStream is)

public MockHttpURLConnection setInputStream(InputStream is)

Sets the input stream.

To prevent incidental overwrite, only the first non-null assignment is honored.

Parameter
NameDescription
isInputStream
Returns
TypeDescription
MockHttpURLConnection

setOutputStream(OutputStream outputStream)

public MockHttpURLConnection setOutputStream(OutputStream outputStream)

Sets the output stream or null to throw an UnknownServiceException when #getOutputStream() is called.

By default it is null.

Parameter
NameDescription
outputStreamOutputStream
Returns
TypeDescription
MockHttpURLConnection

setResponseCode(int responseCode)

public MockHttpURLConnection setResponseCode(int responseCode)

Sets the HTTP response status code.

Parameter
NameDescription
responseCodeint
Returns
TypeDescription
MockHttpURLConnection

usingProxy()

public boolean usingProxy()
Returns
TypeDescription
boolean
Overrides