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, responseMessage
allowUserInteraction, 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, setSSLSocketFactory
getFollowRedirects, setFollowRedirects
getDefaultAllowUserInteraction, setContentHandlerFactory, setDefaultAllowUserInteraction
protected DelegateHttpsURLConnection delegate
protected HttpsURLConnectionImpl(URL u) throws IOException
IOException
public void addRequestProperty(String key, String value)
addRequestProperty
in class URLConnection
key
- 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 URLConnection
IOException
- if an I/O error occurs while opening the connection.URLConnection.connected
,
URLConnection.getConnectTimeout()
,
URLConnection.setConnectTimeout(int)
public void disconnect()
disconnect
in class HttpURLConnection
public 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 Object
obj
- the reference object with which to compare.true
if this object is the same as the obj argument; false
otherwise.Object.hashCode()
,
HashMap
public boolean getAllowUserInteraction()
URLConnection
allowUserInteraction
field for this object.getAllowUserInteraction
in class URLConnection
allowUserInteraction
field for this object.URLConnection.setAllowUserInteraction(boolean)
public int getConnectTimeout()
URLConnection
0 return implies that the option is disabled (i.e., timeout of infinity).
getConnectTimeout
in class URLConnection
int
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: where <contentType> is formed by taking the content-type string, replacing all slash characters with asun.net.www.content.<contentType>
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 URLConnection
instanceof
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
URLConnection
getContent
in class URLConnection
classes
- 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()
URLConnection
content-encoding
header field.getContentEncoding
in class URLConnection
null
if not known.URLConnection.getHeaderField(java.lang.String)
public int getContentLength()
URLConnection
content-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()
URLConnection
content-length
header field as a long.getContentLengthLong
in class URLConnection
-1
if the content
length is not known.public String getContentType()
URLConnection
content-type
header field.getContentType
in class URLConnection
null
if not known.URLConnection.getHeaderField(java.lang.String)
public boolean getDefaultUseCaches()
URLConnection
URLConnection
'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 URLConnection
URLConnection
's useCaches
flag.URLConnection.setDefaultUseCaches(boolean)
public boolean getDoInput()
URLConnection
URLConnection
's doInput
flag.getDoInput
in class URLConnection
URLConnection
's doInput
flag.URLConnection.setDoInput(boolean)
public boolean getDoOutput()
URLConnection
URLConnection
's doOutput
flag.getDoOutput
in class URLConnection
URLConnection
's doOutput
flag.URLConnection.setDoOutput(boolean)
public InputStream getErrorStream()
HttpURLConnection
This 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 HttpURLConnection
public String getHeaderField(int n)
getHeaderField
in class HttpURLConnection
n
- the index of the header fieldn
th header field, or null
if the value does not exist.HttpURLConnection.getHeaderFieldKey(int)
public String getHeaderField(String name)
getHeaderField
in class URLConnection
name
- 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 URLConnection
name
- 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 HttpURLConnection
n
- the index of the header fieldn
th 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 URLConnection
name
- 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 URLConnection
public InputStream getInputStream() throws IOException
URLConnection
getInputStream
in class URLConnection
IOException
- 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()
HttpURLConnection
HttpURLConnection
's instanceFollowRedirects
field.getInstanceFollowRedirects
in class HttpURLConnection
HttpURLConnection
's instanceFollowRedirects
field.HttpURLConnection.instanceFollowRedirects
,
HttpURLConnection.setInstanceFollowRedirects(boolean)
public OutputStream getOutputStream() throws IOException
URLConnection
getOutputStream
in class URLConnection
IOException
- if an I/O error occurs while creating the output stream.UnknownServiceException
- if the protocol does not support output.public Permission getPermission() throws IOException
HttpURLConnection
SocketPermission
object representing the permission necessary to connect to the destination
host and port.getPermission
in class HttpURLConnection
SocketPermission
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()
URLConnection
getReadTimeout
in class URLConnection
int
that indicates the read timeout value in millisecondsURLConnection.setReadTimeout(int)
,
InputStream.read()
public String getRequestMethod()
HttpURLConnection
getRequestMethod
in class HttpURLConnection
HttpURLConnection.setRequestMethod(java.lang.String)
public Map<String,List<String>> getRequestProperties()
getRequestProperties
in class URLConnection
IllegalStateException
- if already connectedpublic String getRequestProperty(String key)
URLConnection
getRequestProperty
in class URLConnection
key
- 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 HttpURLConnection
IOException
- if an error occurred connecting to the server.public String getResponseMessage() throws IOException
HttpURLConnection
HTTP/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 HttpURLConnection
null
IOException
- if an error occurred connecting to the server.public URL getURL()
URLConnection
URLConnection
's URL
field.getURL
in class URLConnection
URLConnection
's URL
field.URLConnection.url
public boolean getUseCaches()
URLConnection
URLConnection
's useCaches
field.getUseCaches
in class URLConnection
URLConnection
's useCaches
field.URLConnection.setUseCaches(boolean)
public int hashCode()
Object
HashMap
.
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 Object
Object.equals(java.lang.Object)
,
System.identityHashCode(java.lang.Object)
protected boolean isConnected()
public void setAllowUserInteraction(boolean allowuserinteraction)
URLConnection
allowUserInteraction
field of this URLConnection
.setAllowUserInteraction
in class URLConnection
allowuserinteraction
- the new value.URLConnection.getAllowUserInteraction()
public void setChunkedStreamingMode(int chunklen)
HttpURLConnection
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.
setChunkedStreamingMode
in class HttpURLConnection
chunklen
- 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)
URLConnection
Some non-standard implementation of this method may ignore the specified timeout. To see the connect timeout set, please call getConnectTimeout().
setConnectTimeout
in class URLConnection
timeout
- an int
that specifies the connect timeout value in millisecondsURLConnection.getConnectTimeout()
,
URLConnection.connect()
public void setDefaultUseCaches(boolean defaultusecaches)
URLConnection
useCaches
field to the specified value.setDefaultUseCaches
in class URLConnection
defaultusecaches
- the new value.URLConnection.getDefaultUseCaches()
public void setDoInput(boolean doinput)
URLConnection
doInput
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 URLConnection
doinput
- the new value.URLConnection.doInput
,
URLConnection.getDoInput()
public void setDoOutput(boolean dooutput)
URLConnection
doOutput
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 URLConnection
dooutput
- the new value.URLConnection.getDoOutput()
public void setFixedLengthStreamingMode(int contentLength)
HttpURLConnection
An 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 HttpURLConnection
contentLength
- The number of bytes which will be written to the OutputStream.HttpURLConnection.setChunkedStreamingMode(int)
public void setFixedLengthStreamingMode(long contentLength)
HttpURLConnection
An 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 HttpURLConnection
contentLength
- The number of bytes which will be written to the OutputStream.public void setInstanceFollowRedirects(boolean shouldFollow)
HttpURLConnection
HttpURLConnection
instance.
The default value comes from followRedirects, which defaults to true.
setInstanceFollowRedirects
in class HttpURLConnection
shouldFollow
- 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 accessedIOException
public void setReadTimeout(int timeout)
URLConnection
Some non-standard implementation of this method ignores the specified timeout. To see the read timeout set, please call getReadTimeout().
setReadTimeout
in class URLConnection
timeout
- an int
that specifies the timeout value to be used in millisecondsURLConnection.getReadTimeout()
,
InputStream.read()
public void setRequestMethod(String method) throws ProtocolException
HttpURLConnection
setRequestMethod
in class HttpURLConnection
method
- 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 URLConnection
value
- 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)
URLConnection
useCaches
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 URLConnection
usecaches
- a boolean
indicating whether or not to allow cachingURLConnection.getUseCaches()
public String toString()
URLConnection
String
representation of this URL connection.toString
in class URLConnection
URLConnection
.public boolean usingProxy()
HttpURLConnection
usingProxy
in class HttpURLConnection