Class MockHttpURLConnection
java.lang.Object
java.net.URLConnection
java.net.HttpURLConnection
com.google.api.client.testing.http.javanet.MockHttpURLConnection
- Since:
- 1.11
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanWhetherURLConnection.doOutputwas called.static final byte[]Deprecated.As of 1.20.private InputStreamThe error stream.static final byte[]Deprecated.As of 1.20.private InputStreamThe input stream.private OutputStreamprivate booleanWhethersetFixedLengthStreamingMode(int)was called.private booleanWhethersetFixedLengthStreamingMode(long)was called.Fields inherited from class HttpURLConnection
chunkLength, fixedContentLength, fixedContentLengthLong, HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_METHOD, HTTP_BAD_REQUEST, HTTP_CLIENT_TIMEOUT, HTTP_CONFLICT, HTTP_CREATED, HTTP_ENTITY_TOO_LARGE, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_INTERNAL_ERROR, HTTP_LENGTH_REQUIRED, HTTP_MOVED_PERM, HTTP_MOVED_TEMP, HTTP_MULT_CHOICE, HTTP_NO_CONTENT, HTTP_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL, HTTP_PAYMENT_REQUIRED, HTTP_PRECON_FAILED, HTTP_PROXY_AUTH, HTTP_REQ_TOO_LONG, HTTP_RESET, HTTP_SEE_OTHER, HTTP_SERVER_ERROR, HTTP_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessageFields inherited from class URLConnection
allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets a custom response header.voidconnect()voidfinal booleanReturns whetherURLConnection.doOutputwas called.intgetHeaderField(String name) intbooleanbooleanvoidsetDoOutput(boolean dooutput) Sets the error stream.voidsetFixedLengthStreamingMode(int contentLength) voidsetFixedLengthStreamingMode(long contentLength) Sets the input stream.setOutputStream(OutputStream outputStream) Sets the output stream ornullto throw anUnknownServiceExceptionwhengetOutputStream()is called.setResponseCode(int responseCode) Sets the HTTP response status code.booleanMethods inherited from class HttpURLConnection
getFollowRedirects, getHeaderField, getHeaderFieldDate, getHeaderFieldKey, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseMessage, setChunkedStreamingMode, setFollowRedirects, setInstanceFollowRedirects, setRequestMethodMethods inherited from class URLConnection
addRequestProperty, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentLengthLong, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderFieldInt, getHeaderFieldLong, getIfModifiedSince, getLastModified, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
-
Field Details
-
doOutputCalled
private boolean doOutputCalledWhetherURLConnection.doOutputwas called. -
setFixedLengthStreamingModeIntCalled
private boolean setFixedLengthStreamingModeIntCalledWhethersetFixedLengthStreamingMode(int)was called. -
setFixedLengthStreamingModeLongCalled
private boolean setFixedLengthStreamingModeLongCalledWhethersetFixedLengthStreamingMode(long)was called. -
outputStream
-
INPUT_BUF
Deprecated.As of 1.20. UsesetInputStream(InputStream)instead.The input byte array which represents the content when the status code is less then400. -
ERROR_BUF
Deprecated.As of 1.20. UsesetErrorStream(InputStream)instead.The error byte array which represents the content when the status code is greater or equal to400. -
inputStream
The input stream. -
errorStream
The error stream. -
headers
-
-
Constructor Details
-
MockHttpURLConnection
- Parameters:
u- the URL ornullfor none
-
-
Method Details
-
disconnect
public void disconnect()- Specified by:
disconnectin classHttpURLConnection
-
usingProxy
public boolean usingProxy()- Specified by:
usingProxyin classHttpURLConnection
-
connect
- Specified by:
connectin classURLConnection- Throws:
IOException
-
getResponseCode
- Overrides:
getResponseCodein classHttpURLConnection- Throws:
IOException
-
setDoOutput
public void setDoOutput(boolean dooutput) - Overrides:
setDoOutputin classURLConnection
-
getOutputStream
- Overrides:
getOutputStreamin classURLConnection- Throws:
IOException
-
doOutputCalled
public final boolean doOutputCalled()Returns whetherURLConnection.doOutputwas called. -
setOutputStream
Sets the output stream ornullto throw anUnknownServiceExceptionwhengetOutputStream()is called.By default it is
null. -
setResponseCode
Sets the HTTP response status code. -
addHeader
Sets a custom response header.- Since:
- 1.20
-
setInputStream
Sets the input stream.To prevent incidental overwrite, only the first non-null assignment is honored.
- Since:
- 1.20
-
setErrorStream
Sets the error stream.To prevent incidental overwrite, only the first non-null assignment is honored.
- Since:
- 1.20
-
getInputStream
- Overrides:
getInputStreamin classURLConnection- Throws:
IOException
-
getErrorStream
- Overrides:
getErrorStreamin classHttpURLConnection
-
getHeaderFields
- Overrides:
getHeaderFieldsin classURLConnection
-
getHeaderField
- Overrides:
getHeaderFieldin classURLConnection
-
getChunkLength
public int getChunkLength() -
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(int contentLength) - Overrides:
setFixedLengthStreamingModein classHttpURLConnection
-
setFixedLengthStreamingMode
public void setFixedLengthStreamingMode(long contentLength) - Overrides:
setFixedLengthStreamingModein classHttpURLConnection
-
isSetFixedLengthStreamingModeIntCalled
public boolean isSetFixedLengthStreamingModeIntCalled() -
isSetFixedLengthStreamingModeLongCalled
public boolean isSetFixedLengthStreamingModeLongCalled()
-