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