public class HttpsURLConnectionImpl extends HttpsURLConnection
| Modifier and Type | Field and Description |
|---|---|
protected DelegateHttpsURLConnection |
delegate |
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_UNAUTHORIZED, HTTP_UNAVAILABLE, HTTP_UNSUPPORTED_TYPE, HTTP_USE_PROXY, HTTP_VERSION, instanceFollowRedirects, method, responseCode, responseMessageallowUserInteraction, connected, doInput, doOutput, url, useCaches| Modifier | Constructor and Description |
|---|---|
protected |
HttpsURLConnectionImpl(URL u) |
| Modifier and Type | Method and Description |
|---|---|
void |
addRequestProperty(String key,
String value)
Adds a general request property specified by a key-value pair.
|
void |
connect()
Implements the HTTP protocol handler's "connect" method,
establishing an SSL connection to the server as necessary.
|
void |
disconnect()
Disconnect from the server.
|
boolean |
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
boolean |
getAllowUserInteraction()
Returns the value of the
allowUserInteraction field for this object. |
int |
getConnectTimeout()
Returns setting for connect timeout.
|
Object |
getContent()
Retrieves the contents of this URL connection.
|
Object |
getContent(Class[] classes)
Retrieves the contents of this URL connection.
|
String |
getContentEncoding()
Returns the value of the
content-encoding header field. |
int |
getContentLength()
Returns the value of the
content-length header field. |
long |
getContentLengthLong()
Returns the value of the
content-length header field as a long. |
String |
getContentType()
Returns the value of the
content-type header field. |
boolean |
getDefaultUseCaches()
Returns the default value of a
URLConnection's useCaches flag. |
boolean |
getDoInput()
Returns the value of this
URLConnection's doInput flag. |
boolean |
getDoOutput()
Returns the value of this
URLConnection's doOutput flag. |
InputStream |
getErrorStream()
Returns the error stream if the connection failed but the server sent useful data nonetheless.
|
String |
getHeaderField(int n)
Gets a header field by index.
|
String |
getHeaderField(String name)
Gets a header field by name.
|
int |
getHeaderFieldInt(String name,
int Default)
Returns the value of the named field parsed as a number.
|
String |
getHeaderFieldKey(int n)
Gets a header field by index.
|
long |
getHeaderFieldLong(String name,
long Default)
Returns the value of the named field parsed as a number.
|
Map<String,List<String>> |
getHeaderFields()
Returns an unmodifiable Map of the header fields.
|
InputStream |
getInputStream()
Returns an input stream that reads from this open connection.
|
boolean |
getInstanceFollowRedirects()
Returns the value of this
HttpURLConnection's instanceFollowRedirects field. |
OutputStream |
getOutputStream()
Returns an output stream that writes to this connection.
|
Permission |
getPermission()
Returns a
SocketPermission object representing the permission necessary to connect to the destination
host and port. |
int |
getReadTimeout()
Returns setting for read timeout.
|
String |
getRequestMethod()
Get the request method.
|
Map<String,List<String>> |
getRequestProperties()
Returns an unmodifiable Map of general request
properties for this connection.
|
String |
getRequestProperty(String key)
Returns the value of the named general request property for this connection.
|
int |
getResponseCode()
Overwrite super class method
|
String |
getResponseMessage()
Gets the HTTP response message, if any, returned along with the response code from a server.
|
URL |
getURL()
Returns the value of this
URLConnection's URL field. |
boolean |
getUseCaches()
Returns the value of this
URLConnection's useCaches field. |
int |
hashCode()
Returns a hash code value for the object.
|
protected boolean |
isConnected()
Used by subclass to access "connected" variable.
|
void |
setAllowUserInteraction(boolean allowuserinteraction)
Set the value of the
allowUserInteraction field of this URLConnection. |
void |
setChunkedStreamingMode(int chunklen)
This method is used to enable streaming of a HTTP request body without internal buffering, when the content
length is not known in advance.
|
protected void |
setConnected(boolean conn)
Used by subclass to access "connected" variable.
|
void |
setConnectTimeout(int timeout)
Sets a specified timeout value, in milliseconds, to be used when opening a communications link to the resource
referenced by this URLConnection.
|
void |
setDefaultUseCaches(boolean defaultusecaches)
Sets the default value of the
useCaches field to the specified value. |
void |
setDoInput(boolean doinput)
Sets the value of the
doInput field for this URLConnection to the specified value. |
void |
setDoOutput(boolean dooutput)
Sets the value of the
doOutput field for this URLConnection to the specified value. |
void |
setFixedLengthStreamingMode(int contentLength)
This method is used to enable streaming of a HTTP request body without internal buffering, when the content
length is known in advance.
|
void |
setFixedLengthStreamingMode(long contentLength)
This method is used to enable streaming of a HTTP request body without internal buffering, when the content
length is known in advance.
|
void |
setInstanceFollowRedirects(boolean shouldFollow)
Sets whether HTTP redirects (requests with response code 3xx) should be automatically followed by this
HttpURLConnection instance. |
protected void |
setNewClient(URL url)
Create a new HttpClient object, bypassing the cache of
HTTP client objects/connections.
|
void |
setReadTimeout(int timeout)
Sets the read timeout to a specified timeout, in milliseconds.
|
void |
setRequestMethod(String method)
Set the method for the URL request, one of:
GET
POST
HEAD
OPTIONS
PUT
DELETE
TRACE
are legal, subject to protocol restrictions.
|
void |
setRequestProperty(String key,
String value)
Sets request property.
|
void |
setUseCaches(boolean usecaches)
Sets the value of the
useCaches field of this URLConnection to the specified value. |
String |
toString()
Returns a
String representation of this URL connection. |
boolean |
usingProxy()
Indicates if the connection is going through a proxy.
|
getDefaultSSLSocketFactory, getSSLSocketFactory, setDefaultSSLSocketFactory, setSSLSocketFactorygetFollowRedirects, setFollowRedirectsgetDefaultAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteractionprotected DelegateHttpsURLConnection delegate
protected HttpsURLConnectionImpl(URL u) throws IOException
IOExceptionpublic void addRequestProperty(String key, String value)
addRequestProperty in class URLConnectionkey - the keyword by which the request is known (e.g., "accept").value - the value associated with it.getRequestProperties()public void connect()
throws IOException
connect in class URLConnectionIOException - if an I/O error occurs while opening the connection.URLConnection.connected,
URLConnection.getConnectTimeout(),
URLConnection.setConnectTimeout(int)public void disconnect()
disconnect in class HttpURLConnectionpublic boolean equals(Object obj)
Object
The equals method implements an equivalence relation on non-null object references:
x, x.equals(x)
should return true.
x and y,
x.equals(y) should return true if and only if y.equals(x) returns
true.
x, y, and
z, if x.equals(y) returns true and y.equals(z) returns
true, then x.equals(z) should return true.
x and y, multiple
invocations of x.equals(y) consistently return true or consistently return
false, provided no information used in equals comparisons on the objects is
modified.
x, x.equals(null) should return
false.
The equals method for class Object implements the most discriminating possible
equivalence relation on objects; that is, for any non-null reference values x and
y, this method returns true if and only if x and y refer to the
same object (x == y has the value true).
Note that it is generally necessary to override the hashCode method whenever this method
is overridden, so as to maintain the general contract for the hashCode method, which
states that equal objects must have equal hash codes.
equals in class Objectobj - the reference object with which to compare.true if this object is the same as the obj argument; false otherwise.Object.hashCode(),
HashMappublic boolean getAllowUserInteraction()
URLConnectionallowUserInteraction field for this object.getAllowUserInteraction in class URLConnectionallowUserInteraction field for this object.URLConnection.setAllowUserInteraction(boolean)public int getConnectTimeout()
URLConnection0 return implies that the option is disabled (i.e., timeout of infinity).
getConnectTimeout in class URLConnectionint that indicates the connect timeout value in millisecondsURLConnection.setConnectTimeout(int),
URLConnection.connect()public Object getContent() throws IOException
URLConnection
This method first determines the content type of the object by calling the getContentType method. If this
is the first time that the application has seen that specific content type, a content handler for that content
type is created:
setContentHandlerFactory
method, the createContentHandler method of that instance is called with the content type as an argument;
the result is a content handler for that content type.
createContentHandler method
returns null, then the application loads the class named:
sun.net.www.content.<contentType>
where <contentType> is formed by taking the content-type string, replacing all slash
characters with a period ('.'), and all other non-alphanumeric characters with the underscore character '
_'. The alphanumeric characters are specifically the 26 uppercase ASCII letters 'A' through '
Z', the 26 lowercase ASCII letters 'a' through 'z', and the 10 ASCII digits '0'
through '9'. If the specified class does not exist, or is not a subclass of ContentHandler, then
an UnknownServiceException is thrown.
getContent in class URLConnectioninstanceof operator should be used to determine the specific kind of
object returned.IOException - if an I/O error occurs while getting the content.UnknownServiceException - if the protocol does not support the content type.ContentHandlerFactory.createContentHandler(java.lang.String),
URLConnection.getContentType(),
URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)public Object getContent(Class[] classes) throws IOException
URLConnectiongetContent in class URLConnectionclasses - the Class array indicating the requested typesinstanceof operator should be used to determine the
specific kind of object returned.IOException - if an I/O error occurs while getting the content.UnknownServiceException - if the protocol does not support the content type.URLConnection.getContent(),
ContentHandlerFactory.createContentHandler(java.lang.String),
URLConnection.getContent(java.lang.Class[]),
URLConnection.setContentHandlerFactory(java.net.ContentHandlerFactory)public String getContentEncoding()
URLConnectioncontent-encoding header field.getContentEncoding in class URLConnectionnull if not known.URLConnection.getHeaderField(java.lang.String)public int getContentLength()
URLConnectioncontent-length header field.
Note: getContentLengthLong() should be preferred over this method, since
it returns a long instead and is therefore more portable.
getContentLength in class URLConnection-1 if the content
length is not known, or if the content length is greater than Integer.MAX_VALUE.public long getContentLengthLong()
URLConnectioncontent-length header field as a long.getContentLengthLong in class URLConnection-1 if the content
length is not known.public String getContentType()
URLConnectioncontent-type header field.getContentType in class URLConnectionnull if not known.URLConnection.getHeaderField(java.lang.String)public boolean getDefaultUseCaches()
URLConnectionURLConnection's useCaches flag.
Ths default is "sticky", being a part of the static state of all URLConnections. This flag applies to the next, and all following URLConnections that are created.
getDefaultUseCaches in class URLConnectionURLConnection's useCaches flag.URLConnection.setDefaultUseCaches(boolean)public boolean getDoInput()
URLConnectionURLConnection's doInput flag.getDoInput in class URLConnectionURLConnection's doInput flag.URLConnection.setDoInput(boolean)public boolean getDoOutput()
URLConnectionURLConnection's doOutput flag.getDoOutput in class URLConnectionURLConnection's doOutput flag.URLConnection.setDoOutput(boolean)public InputStream getErrorStream()
HttpURLConnectionThis method will not cause a connection to be initiated. If the connection was not connected, or if the server did not have an error while connecting or if the server had an error but no error data was sent, this method will return null. This is the default.
getErrorStream in class HttpURLConnectionpublic String getHeaderField(int n)
getHeaderField in class HttpURLConnectionn - the index of the header fieldnth header field, or null if the value does not exist.HttpURLConnection.getHeaderFieldKey(int)public String getHeaderField(String name)
getHeaderField in class URLConnectionname - the name of the header fieldnull if there is no such field in the header.public int getHeaderFieldInt(String name, int Default)
URLConnection
This form of getHeaderField exists because some connection types (e.g., http-ng) have pre-parsed
headers. Classes for that connection type can override this method and short-circuit the parsing.
getHeaderFieldInt in class URLConnectionname - the name of the header field.Default - the default value.Default value is returned if the field is
missing or malformed.public String getHeaderFieldKey(int n)
getHeaderFieldKey in class HttpURLConnectionn - the index of the header fieldnth header field, or null if the key does not exist.public long getHeaderFieldLong(String name, long Default)
URLConnection
This form of getHeaderField exists because some connection types (e.g., http-ng) have pre-parsed
headers. Classes for that connection type can override this method and short-circuit the parsing.
getHeaderFieldLong in class URLConnectionname - the name of the header field.Default - the default value.Default value is returned if the field is
missing or malformed.public Map<String,List<String>> getHeaderFields()
getHeaderFields in class URLConnectionpublic InputStream getInputStream() throws IOException
URLConnectiongetInputStream in class URLConnectionIOException - if an I/O error occurs while creating the input stream.UnknownServiceException - if the protocol does not support input.URLConnection.setReadTimeout(int),
URLConnection.getReadTimeout()public boolean getInstanceFollowRedirects()
HttpURLConnectionHttpURLConnection's instanceFollowRedirects field.getInstanceFollowRedirects in class HttpURLConnectionHttpURLConnection's instanceFollowRedirects field.HttpURLConnection.instanceFollowRedirects,
HttpURLConnection.setInstanceFollowRedirects(boolean)public OutputStream getOutputStream() throws IOException
URLConnectiongetOutputStream in class URLConnectionIOException - if an I/O error occurs while creating the output stream.UnknownServiceException - if the protocol does not support output.public Permission getPermission() throws IOException
HttpURLConnectionSocketPermission object representing the permission necessary to connect to the destination
host and port.getPermission in class HttpURLConnectionSocketPermission object representing the permission necessary to connect to the destination
host and port.IOException - if an error occurs while computing the permission.public int getReadTimeout()
URLConnectiongetReadTimeout in class URLConnectionint that indicates the read timeout value in millisecondsURLConnection.setReadTimeout(int),
InputStream.read()public String getRequestMethod()
HttpURLConnectiongetRequestMethod in class HttpURLConnectionHttpURLConnection.setRequestMethod(java.lang.String)public Map<String,List<String>> getRequestProperties()
getRequestProperties in class URLConnectionIllegalStateException - if already connectedpublic String getRequestProperty(String key)
URLConnectiongetRequestProperty in class URLConnectionkey - the keyword by which the request is known (e.g., "Accept").URLConnection.setRequestProperty(java.lang.String, java.lang.String)public int getResponseCode()
throws IOException
getResponseCode in class HttpURLConnectionIOException - if an error occurred connecting to the server.public String getResponseMessage() throws IOException
HttpURLConnectionHTTP/1.0 200 OK HTTP/1.0 404 Not FoundExtracts the Strings "OK" and "Not Found" respectively. Returns null if none could be discerned from the responses (the result was not valid HTTP).
getResponseMessage in class HttpURLConnectionnullIOException - if an error occurred connecting to the server.public URL getURL()
URLConnectionURLConnection's URL field.getURL in class URLConnectionURLConnection's URL field.URLConnection.urlpublic boolean getUseCaches()
URLConnectionURLConnection's useCaches field.getUseCaches in class URLConnectionURLConnection's useCaches field.URLConnection.setUseCaches(boolean)public int hashCode()
ObjectHashMap.
The general contract of hashCode is:
hashCode method must consistently return the same integer, provided no
information used in equals comparisons on the object is modified. This integer need not
remain consistent from one execution of an application to another execution of the same
application.
equals(Object) method, then calling the
hashCode method on each of the two objects must produce the same integer result.
Object.equals(java.lang.Object) method, then calling the hashCode
method on each of the two objects must produce distinct integer results. However, the programmer
should be aware that producing distinct integer results for unequal objects may improve the
performance of hash tables.
As much as is reasonably practical, the hashCode method defined by class Object does
return distinct integers for distinct objects. (This is typically implemented by converting the
internal address of the object into an integer, but this implementation technique is not required
by the JavaTM programming language.)
hashCode in class ObjectObject.equals(java.lang.Object),
System.identityHashCode(java.lang.Object)protected boolean isConnected()
public void setAllowUserInteraction(boolean allowuserinteraction)
URLConnectionallowUserInteraction field of this URLConnection.setAllowUserInteraction in class URLConnectionallowuserinteraction - the new value.URLConnection.getAllowUserInteraction()public void setChunkedStreamingMode(int chunklen)
HttpURLConnectionWhen output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.
This method must be called before the URLConnection is connected.
setChunkedStreamingMode in class HttpURLConnectionchunklen - The number of bytes to write in each chunk. If chunklen is less than or equal to zero, a default value
will be used.HttpURLConnection.setFixedLengthStreamingMode(int)protected void setConnected(boolean conn)
public void setConnectTimeout(int timeout)
URLConnectionSome non-standard implementation of this method may ignore the specified timeout. To see the connect timeout set, please call getConnectTimeout().
setConnectTimeout in class URLConnectiontimeout - an int that specifies the connect timeout value in millisecondsURLConnection.getConnectTimeout(),
URLConnection.connect()public void setDefaultUseCaches(boolean defaultusecaches)
URLConnectionuseCaches field to the specified value.setDefaultUseCaches in class URLConnectiondefaultusecaches - the new value.URLConnection.getDefaultUseCaches()public void setDoInput(boolean doinput)
URLConnectiondoInput field for this URLConnection to the specified value.
A URL connection can be used for input and/or output. Set the DoInput flag to true if you intend to use the URL connection for input, false if not. The default is true.
setDoInput in class URLConnectiondoinput - the new value.URLConnection.doInput,
URLConnection.getDoInput()public void setDoOutput(boolean dooutput)
URLConnectiondoOutput field for this URLConnection to the specified value.
A URL connection can be used for input and/or output. Set the DoOutput flag to true if you intend to use the URL connection for output, false if not. The default is false.
setDoOutput in class URLConnectiondooutput - the new value.URLConnection.getDoOutput()public void setFixedLengthStreamingMode(int contentLength)
HttpURLConnectionAn exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount.
When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.
This method must be called before the URLConnection is connected.
NOTE: HttpURLConnection.setFixedLengthStreamingMode(long) is recommended instead of this method as it allows larger
content lengths to be set.
setFixedLengthStreamingMode in class HttpURLConnectioncontentLength - The number of bytes which will be written to the OutputStream.HttpURLConnection.setChunkedStreamingMode(int)public void setFixedLengthStreamingMode(long contentLength)
HttpURLConnectionAn exception will be thrown if the application attempts to write more data than the indicated content-length, or if the application closes the OutputStream before writing the indicated amount.
When output streaming is enabled, authentication and redirection cannot be handled automatically. A HttpRetryException will be thrown when reading the response if authentication or redirection are required. This exception can be queried for the details of the error.
This method must be called before the URLConnection is connected.
The content length set by invoking this method takes precedence over any value set by
HttpURLConnection.setFixedLengthStreamingMode(int).
setFixedLengthStreamingMode in class HttpURLConnectioncontentLength - The number of bytes which will be written to the OutputStream.public void setInstanceFollowRedirects(boolean shouldFollow)
HttpURLConnectionHttpURLConnection instance.
The default value comes from followRedirects, which defaults to true.
setInstanceFollowRedirects in class HttpURLConnectionshouldFollow - a boolean indicating whether or not to follow HTTP redirects.HttpURLConnection.instanceFollowRedirects,
HttpURLConnection.getInstanceFollowRedirects()protected void setNewClient(URL url) throws IOException
url - the URL being accessedIOExceptionpublic void setReadTimeout(int timeout)
URLConnectionSome non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().
setReadTimeout in class URLConnectiontimeout - an int that specifies the timeout value to be used in millisecondsURLConnection.getReadTimeout(),
InputStream.read()public void setRequestMethod(String method) throws ProtocolException
HttpURLConnectionsetRequestMethod in class HttpURLConnectionmethod - the HTTP methodProtocolException - if the method cannot be reset or if the requested method isn't valid for HTTP.HttpURLConnection.getRequestMethod()public void setRequestProperty(String key, String value)
setRequestProperty in class URLConnectionvalue - the value to be setkey - the keyword by which the request is known (e.g., "Accept").URLConnection.getRequestProperty(java.lang.String)public void setUseCaches(boolean usecaches)
URLConnectionuseCaches field of this URLConnection to the specified value.
Some protocols do caching of documents. Occasionally, it is important to be able to "tunnel through" and ignore the caches (e.g., the "reload" button in a browser). If the UseCaches flag on a connection is true, the connection is allowed to use whatever caches it can. If false, caches are to be ignored. The default value comes from DefaultUseCaches, which defaults to true.
setUseCaches in class URLConnectionusecaches - a boolean indicating whether or not to allow cachingURLConnection.getUseCaches()public String toString()
URLConnectionString representation of this URL connection.toString in class URLConnectionURLConnection.public boolean usingProxy()
HttpURLConnectionusingProxy in class HttpURLConnection