public class MockHttpURLConnection extends HttpURLConnection
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
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
Constructors
MockHttpURLConnection(URL u)
public MockHttpURLConnection(URL u)
Parameter
Name | Description |
u | URL
the URL or null for none
|
Methods
public MockHttpURLConnection addHeader(String name, String value)
Sets a custom response header.
Parameters
Returns
connect()
Overrides
Exceptions
disconnect()
Overrides
doOutputCalled()
public final boolean doOutputCalled()
Returns whether #doOutput was called.
Returns
getChunkLength()
public int getChunkLength()
Returns
getErrorStream()
public InputStream getErrorStream()
Returns
Overrides
public String getHeaderField(String name)
Parameter
Returns
Overrides
public Map<String,List<String>> getHeaderFields()
Returns
Overrides
public InputStream getInputStream()
Returns
Overrides
Exceptions
getOutputStream()
public OutputStream getOutputStream()
Returns
Overrides
Exceptions
getResponseCode()
public int getResponseCode()
Returns
Overrides
Exceptions
isSetFixedLengthStreamingModeIntCalled()
public boolean isSetFixedLengthStreamingModeIntCalled()
Returns
isSetFixedLengthStreamingModeLongCalled()
public boolean isSetFixedLengthStreamingModeLongCalled()
Returns
setDoOutput(boolean dooutput)
public void setDoOutput(boolean dooutput)
Parameter
Overrides
public MockHttpURLConnection setErrorStream(InputStream is)
Sets the error stream.
To prevent incidental overwrite, only the first non-null assignment is honored.
Parameter
Returns
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
public MockHttpURLConnection setInputStream(InputStream is)
Sets the input stream.
To prevent incidental overwrite, only the first non-null assignment is honored.
Parameter
Returns
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
Returns
setResponseCode(int responseCode)
public MockHttpURLConnection setResponseCode(int responseCode)
Sets the HTTP response status code.
Parameter
Name | Description |
responseCode | int
|
Returns
usingProxy()
public boolean usingProxy()
Returns
Overrides