Class MockHttpURLConnection (1.45.1)

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
Type Description
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
Type Description
byte[]

Constructors

MockHttpURLConnection(URL u)

public MockHttpURLConnection(URL u)
Parameter
Name Description
u URL

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
Name Description
name String
value String
Returns
Type Description
MockHttpURLConnection

connect()

public void connect()
Overrides
Exceptions
Type Description
IOException

disconnect()

public void disconnect()
Overrides

doOutputCalled()

public final boolean doOutputCalled()

Returns whether #doOutput was called.

Returns
Type Description
boolean

getChunkLength()

public int getChunkLength()
Returns
Type Description
int

getErrorStream()

public InputStream getErrorStream()
Returns
Type Description
InputStream
Overrides

getHeaderField(String name)

public String getHeaderField(String name)
Parameter
Name Description
name String
Returns
Type Description
String
Overrides

getHeaderFields()

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

getInputStream()

public InputStream getInputStream()
Returns
Type Description
InputStream
Overrides
Exceptions
Type Description
IOException

getOutputStream()

public OutputStream getOutputStream()
Returns
Type Description
OutputStream
Overrides
Exceptions
Type Description
IOException

getResponseCode()

public int getResponseCode()
Returns
Type Description
int
Overrides
Exceptions
Type Description
IOException

isSetFixedLengthStreamingModeIntCalled()

public boolean isSetFixedLengthStreamingModeIntCalled()
Returns
Type Description
boolean

isSetFixedLengthStreamingModeLongCalled()

public boolean isSetFixedLengthStreamingModeLongCalled()
Returns
Type Description
boolean

setDoOutput(boolean dooutput)

public void setDoOutput(boolean dooutput)
Parameter
Name Description
dooutput boolean
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
Name Description
is InputStream
Returns
Type Description
MockHttpURLConnection

setFixedLengthStreamingMode(int contentLength)

public void setFixedLengthStreamingMode(int contentLength)
Parameter
Name Description
contentLength int
Overrides

setFixedLengthStreamingMode(long contentLength)

public void setFixedLengthStreamingMode(long contentLength)
Parameter
Name Description
contentLength long
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
Name Description
is InputStream
Returns
Type Description
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
Name Description
outputStream OutputStream
Returns
Type Description
MockHttpURLConnection

setResponseCode(int responseCode)

public MockHttpURLConnection setResponseCode(int responseCode)

Sets the HTTP response status code.

Parameter
Name Description
responseCode int
Returns
Type Description
MockHttpURLConnection

usingProxy()

public boolean usingProxy()
Returns
Type Description
boolean
Overrides