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