Build 1.0_r1(from source)

java.net
Class HttpURLConnection

java.lang.Object
  extended by java.net.URLConnection
      extended by java.net.HttpURLConnection
Direct Known Subclasses:
HttpsURLConnection

public abstract class HttpURLConnection
extends URLConnection

This abstract subclass of URLConnection defines method for managing HTTP connection according to the description given by RFC 2068

See Also:
ContentHandler, URL, URLConnection, URLStreamHandler

Nested Class Summary
 
Nested classes/interfaces inherited from class java.net.URLConnection
URLConnection.DefaultContentHandler
 
Field Summary
protected  int chunkLength
           
protected  int fixedContentLength
           
static int HTTP_ACCEPTED
          Numeric status code, 202: Accepted
static int HTTP_BAD_GATEWAY
          Numeric status code, 502: Bad Gateway
static int HTTP_BAD_METHOD
          Numeric status code, 405: Bad Method
static int HTTP_BAD_REQUEST
          Numeric status code, 400: Bad Request
static int HTTP_CLIENT_TIMEOUT
          Numeric status code, 408: Client Timeout
static int HTTP_CONFLICT
          Numeric status code, 409: Conflict
static int HTTP_CREATED
          Numeric status code, 201: Created
static int HTTP_ENTITY_TOO_LARGE
          Numeric status code, 413: Entity too large
static int HTTP_FORBIDDEN
          Numeric status code, 403: Forbidden
static int HTTP_GATEWAY_TIMEOUT
          Numeric status code, 504: Gateway timeout
static int HTTP_GONE
          Numeric status code, 410: Gone
static int HTTP_INTERNAL_ERROR
          Numeric status code, 500: Internal error
static int HTTP_LENGTH_REQUIRED
          Numeric status code, 411: Length required
static int HTTP_MOVED_PERM
          Numeric status code, 301 Moved permanently
static int HTTP_MOVED_TEMP
          Numeric status code, 302: Moved temporarily
static int HTTP_MULT_CHOICE
          Numeric status code, 300: Multiple choices
static int HTTP_NO_CONTENT
          Numeric status code, 204: No content
static int HTTP_NOT_ACCEPTABLE
          Numeric status code, 406: Not acceptable
static int HTTP_NOT_AUTHORITATIVE
          Numeric status code, 203: Not authoritative
static int HTTP_NOT_FOUND
          Numeric status code, 404: Not found
static int HTTP_NOT_IMPLEMENTED
          Numeric status code, 501: Not implemented
static int HTTP_NOT_MODIFIED
          Numeric status code, 304: Not modified
static int HTTP_OK
          Numeric status code, 200: OK
static int HTTP_PARTIAL
          Numeric status code, 206: Partial
static int HTTP_PAYMENT_REQUIRED
          Numeric status code, 402: Payment required
static int HTTP_PRECON_FAILED
          Numeric status code, 412: Precondition failed
static int HTTP_PROXY_AUTH
          Numeric status code, 407: Proxy authentication required
static int HTTP_REQ_TOO_LONG
          Numeric status code, 414: Request too long
static int HTTP_RESET
          Numeric status code, 205: Reset
static int HTTP_SEE_OTHER
          Numeric status code, 303: See other
static int HTTP_SERVER_ERROR
          Deprecated. Use HTTP_INTERNAL_ERROR
static int HTTP_UNAUTHORIZED
          Numeric status code, 401: Unauthorized
static int HTTP_UNAVAILABLE
          Numeric status code, 503: Unavailable
static int HTTP_UNSUPPORTED_TYPE
          Numeric status code, 415: Unsupported type
static int HTTP_USE_PROXY
          Numeric status code, 305: Use proxy
static int HTTP_VERSION
          Numeric status code, 505: Version not supported
protected  boolean instanceFollowRedirects
           
protected  String method
           
protected  int responseCode
           
protected  String responseMessage
           
 
Fields inherited from class java.net.URLConnection
allowUserInteraction, connected, contentHandlers, defaultHandler, doInput, doOutput, ifModifiedSince, url, useCaches
 
Constructor Summary
protected HttpURLConnection(URL url)
          Constructs a HttpURLConnection pointing to the resource specified by the URL.
 
Method Summary
abstract  void disconnect()
          Closes the connection with the HTTP server
 InputStream getErrorStream()
          Returns a input stream from the server in the case of error such as the requested file (txt, htm, html) is not found on the remote server.
static boolean getFollowRedirects()
          Returns the value of followRedirects which indicates if this connection will follows a different URL redirected by the server.
 long getHeaderFieldDate(String field, long defaultValue)
          Returns the date value in the form of milliseconds since epoch corresponding to the field field.
 boolean getInstanceFollowRedirects()
          Returns if this connection follows redirects.
 Permission getPermission()
          Returns the permission object (in this case, SocketPermission) with the host and the port number as the target name and "resolve, connect" as the action list.
 String getRequestMethod()
          Returns the request method which will be used to make the request to the remote HTTP server.
 int getResponseCode()
          Returns the response code returned by the remote HTTP server
 String getResponseMessage()
          Returns the response message returned the remote HTTP server
 void setChunkedStreamingMode(int chunklen)
          If length of a HTTP request body is NOT known ahead, enable chunked transfer encoding to enable streaming without buffering.
 void setFixedLengthStreamingMode(int contentLength)
          If length of a HTTP request body is known ahead, sets fixed length to enable streaming without buffering.
static void setFollowRedirects(boolean auto)
          Sets the flag of whether this connection will follow redirects returned by the remote server.
 void setInstanceFollowRedirects(boolean followRedirects)
          Sets if this connection follows redirects.
 void setRequestMethod(String method)
          Sets the request command which will be sent to the remote HTTP server.
abstract  boolean usingProxy()
          Returns if this connection uses proxy.
 
Methods inherited from class java.net.URLConnection
addRequestProperty, connect, getAllowUserInteraction, getConnectTimeout, getContent, getContent, getContentEncoding, getContentLength, getContentType, getDate, getDefaultAllowUserInteraction, getDefaultRequestProperty, getDefaultUseCaches, getDoInput, getDoOutput, getExpiration, getFileNameMap, getHeaderField, getHeaderField, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getReadTimeout, getRequestProperties, getRequestProperty, getURL, getUseCaches, guessContentTypeFromName, guessContentTypeFromStream, setAllowUserInteraction, setConnectTimeout, setContentHandlerFactory, setDefaultAllowUserInteraction, setDefaultRequestProperty, setDefaultUseCaches, setDoInput, setDoOutput, setFileNameMap, setIfModifiedSince, setReadTimeout, setRequestProperty, setUseCaches, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

method

protected String method

responseCode

protected int responseCode

responseMessage

protected String responseMessage

instanceFollowRedirects

protected boolean instanceFollowRedirects

chunkLength

protected int chunkLength

fixedContentLength

protected int fixedContentLength

HTTP_ACCEPTED

public static final int HTTP_ACCEPTED
Numeric status code, 202: Accepted

See Also:
Constant Field Values

HTTP_BAD_GATEWAY

public static final int HTTP_BAD_GATEWAY
Numeric status code, 502: Bad Gateway

See Also:
Constant Field Values

HTTP_BAD_METHOD

public static final int HTTP_BAD_METHOD
Numeric status code, 405: Bad Method

See Also:
Constant Field Values

HTTP_BAD_REQUEST

public static final int HTTP_BAD_REQUEST
Numeric status code, 400: Bad Request

See Also:
Constant Field Values

HTTP_CLIENT_TIMEOUT

public static final int HTTP_CLIENT_TIMEOUT
Numeric status code, 408: Client Timeout

See Also:
Constant Field Values

HTTP_CONFLICT

public static final int HTTP_CONFLICT
Numeric status code, 409: Conflict

See Also:
Constant Field Values

HTTP_CREATED

public static final int HTTP_CREATED
Numeric status code, 201: Created

See Also:
Constant Field Values

HTTP_ENTITY_TOO_LARGE

public static final int HTTP_ENTITY_TOO_LARGE
Numeric status code, 413: Entity too large

See Also:
Constant Field Values

HTTP_FORBIDDEN

public static final int HTTP_FORBIDDEN
Numeric status code, 403: Forbidden

See Also:
Constant Field Values

HTTP_GATEWAY_TIMEOUT

public static final int HTTP_GATEWAY_TIMEOUT
Numeric status code, 504: Gateway timeout

See Also:
Constant Field Values

HTTP_GONE

public static final int HTTP_GONE
Numeric status code, 410: Gone

See Also:
Constant Field Values

HTTP_INTERNAL_ERROR

public static final int HTTP_INTERNAL_ERROR
Numeric status code, 500: Internal error

See Also:
Constant Field Values

HTTP_LENGTH_REQUIRED

public static final int HTTP_LENGTH_REQUIRED
Numeric status code, 411: Length required

See Also:
Constant Field Values

HTTP_MOVED_PERM

public static final int HTTP_MOVED_PERM
Numeric status code, 301 Moved permanently

See Also:
Constant Field Values

HTTP_MOVED_TEMP

public static final int HTTP_MOVED_TEMP
Numeric status code, 302: Moved temporarily

See Also:
Constant Field Values

HTTP_MULT_CHOICE

public static final int HTTP_MULT_CHOICE
Numeric status code, 300: Multiple choices

See Also:
Constant Field Values

HTTP_NO_CONTENT

public static final int HTTP_NO_CONTENT
Numeric status code, 204: No content

See Also:
Constant Field Values

HTTP_NOT_ACCEPTABLE

public static final int HTTP_NOT_ACCEPTABLE
Numeric status code, 406: Not acceptable

See Also:
Constant Field Values

HTTP_NOT_AUTHORITATIVE

public static final int HTTP_NOT_AUTHORITATIVE
Numeric status code, 203: Not authoritative

See Also:
Constant Field Values

HTTP_NOT_FOUND

public static final int HTTP_NOT_FOUND
Numeric status code, 404: Not found

See Also:
Constant Field Values

HTTP_NOT_IMPLEMENTED

public static final int HTTP_NOT_IMPLEMENTED
Numeric status code, 501: Not implemented

See Also:
Constant Field Values

HTTP_NOT_MODIFIED

public static final int HTTP_NOT_MODIFIED
Numeric status code, 304: Not modified

See Also:
Constant Field Values

HTTP_OK

public static final int HTTP_OK
Numeric status code, 200: OK

See Also:
Constant Field Values

HTTP_PARTIAL

public static final int HTTP_PARTIAL
Numeric status code, 206: Partial

See Also:
Constant Field Values

HTTP_PAYMENT_REQUIRED

public static final int HTTP_PAYMENT_REQUIRED
Numeric status code, 402: Payment required

See Also:
Constant Field Values

HTTP_PRECON_FAILED

public static final int HTTP_PRECON_FAILED
Numeric status code, 412: Precondition failed

See Also:
Constant Field Values

HTTP_PROXY_AUTH

public static final int HTTP_PROXY_AUTH
Numeric status code, 407: Proxy authentication required

See Also:
Constant Field Values

HTTP_REQ_TOO_LONG

public static final int HTTP_REQ_TOO_LONG
Numeric status code, 414: Request too long

See Also:
Constant Field Values

HTTP_RESET

public static final int HTTP_RESET
Numeric status code, 205: Reset

See Also:
Constant Field Values

HTTP_SEE_OTHER

public static final int HTTP_SEE_OTHER
Numeric status code, 303: See other

See Also:
Constant Field Values

HTTP_SERVER_ERROR

@Deprecated
public static final int HTTP_SERVER_ERROR
Deprecated. Use HTTP_INTERNAL_ERROR
See Also:
Constant Field Values

HTTP_USE_PROXY

public static final int HTTP_USE_PROXY
Numeric status code, 305: Use proxy

See Also:
Constant Field Values

HTTP_UNAUTHORIZED

public static final int HTTP_UNAUTHORIZED
Numeric status code, 401: Unauthorized

See Also:
Constant Field Values

HTTP_UNSUPPORTED_TYPE

public static final int HTTP_UNSUPPORTED_TYPE
Numeric status code, 415: Unsupported type

See Also:
Constant Field Values

HTTP_UNAVAILABLE

public static final int HTTP_UNAVAILABLE
Numeric status code, 503: Unavailable

See Also:
Constant Field Values

HTTP_VERSION

public static final int HTTP_VERSION
Numeric status code, 505: Version not supported

See Also:
Constant Field Values
Constructor Detail

HttpURLConnection

protected HttpURLConnection(URL url)
Constructs a HttpURLConnection pointing to the resource specified by the URL.

Parameters:
url - the URL of this connection
See Also:
URL, URLConnection
Method Detail

disconnect

public abstract void disconnect()
Closes the connection with the HTTP server

See Also:
URLConnection.connect(), URLConnection.connected

getErrorStream

public InputStream getErrorStream()
Returns a input stream from the server in the case of error such as the requested file (txt, htm, html) is not found on the remote server.

If the content type is not what stated above, FileNotFoundException is thrown.

Returns:
the error input stream returned by the server.

getFollowRedirects

public static boolean getFollowRedirects()
Returns the value of followRedirects which indicates if this connection will follows a different URL redirected by the server. It is enabled by default.

Returns:
The value of the flag
See Also:
setFollowRedirects(boolean)

getPermission

public Permission getPermission()
                         throws IOException
Returns the permission object (in this case, SocketPermission) with the host and the port number as the target name and "resolve, connect" as the action list.

Overrides:
getPermission in class URLConnection
Returns:
the permission object required for this connection
Throws:
IOException - if an IO exception occurs during the creation of the permission object.

getRequestMethod

public String getRequestMethod()
Returns the request method which will be used to make the request to the remote HTTP server. All possible methods of this HTTP implementation is listed in the class definition.

Returns:
the request method string
See Also:
method, setRequestMethod(java.lang.String)

getResponseCode

public int getResponseCode()
                    throws IOException
Returns the response code returned by the remote HTTP server

Returns:
the response code, -1 if no valid response code
Throws:
IOException - if there is an IO error during the retrieval.
See Also:
getResponseMessage()

getResponseMessage

public String getResponseMessage()
                          throws IOException
Returns the response message returned the remote HTTP server

Returns:
the response message. null if such response exists
Throws:
IOException - if there is an IO error during the retrieval.
See Also:
getResponseCode(), IOException

setFollowRedirects

public static void setFollowRedirects(boolean auto)
Sets the flag of whether this connection will follow redirects returned by the remote server. This method can only be called with the permission from the security manager

Parameters:
auto - The value to set
See Also:
SecurityManager.checkSetFactory()

setRequestMethod

public void setRequestMethod(String method)
                      throws ProtocolException
Sets the request command which will be sent to the remote HTTP server. This method can only be called before the connection is made.

Parameters:
method - The non-null string representing the method
Throws:
ProtocolException - Thrown when this is called after connected, or the method is not supported by this HTTP implementation.
See Also:
getRequestMethod(), method

usingProxy

public abstract boolean usingProxy()
Returns if this connection uses proxy.

Returns:
true if this connection supports proxy, false otherwise.

getInstanceFollowRedirects

public boolean getInstanceFollowRedirects()
Returns if this connection follows redirects.

Returns:
true if this connection follows redirects, false otherwise.

setInstanceFollowRedirects

public void setInstanceFollowRedirects(boolean followRedirects)
Sets if this connection follows redirects.

Parameters:
followRedirects - true if this connection should follows redirects, false otherwise.

getHeaderFieldDate

public long getHeaderFieldDate(String field,
                               long defaultValue)
Returns the date value in the form of milliseconds since epoch corresponding to the field field. Returns defaultValue if no such field can be found in the response header.

Overrides:
getHeaderFieldDate in class URLConnection
Parameters:
field - the field in question
defaultValue - the default value if no field is found
Returns:
milliseconds since epoch
See Also:
URLConnection.ifModifiedSince, URLConnection.setIfModifiedSince(long)

setFixedLengthStreamingMode

public void setFixedLengthStreamingMode(int contentLength)
If length of a HTTP request body is known ahead, sets fixed length to enable streaming without buffering. Sets after connection will cause an exception.

Parameters:
contentLength - the fixed length of the HTTP request body
Throws:
IllegalStateException - if already connected or other mode already set
IllegalArgumentException - if contentLength is less than zero
See Also:
setChunkedStreamingMode(int)

setChunkedStreamingMode

public void setChunkedStreamingMode(int chunklen)
If length of a HTTP request body is NOT known ahead, enable chunked transfer encoding to enable streaming without buffering. Notice that not all http servers support this mode. Sets after connection will cause an exception.

Parameters:
chunklen - the length of a chunk
Throws:
IllegalStateException - if already connected or other mode already set
See Also:
setFixedLengthStreamingMode(int)

Build 1.0_r1(from source)

Please submit a feedback, bug or feature