gnu.java.net.protocol.http

Class HTTPURLConnection

Implemented Interfaces:
EventListener, HandshakeCompletedListener

public class HTTPURLConnection
extends HttpsURLConnection
implements HandshakeCompletedListener

A URLConnection that uses the HTTPConnection class.

Field Summary

Fields inherited from class javax.net.ssl.HttpsURLConnection

hostnameVerifier

Fields inherited from class java.net.HttpURLConnection

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_NOT_ACCEPTABLE, HTTP_NOT_AUTHORITATIVE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_NO_CONTENT, 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, responseMessage

Fields inherited from class java.net.URLConnection

allowUserInteraction, connected, doInput, doOutput, ifModifiedSince, url, useCaches

Constructor Summary

HTTPURLConnection(URL url)
Constructor.

Method Summary

Map
List> getRequestProperties()
void
addRequestProperty(String key, String value)
void
connect()
void
disconnect()
Closes the connection to the server.
String
getCipherSuite()
Returns the cipher name negotiated for this connection.
String
getContentType()
InputStream
getErrorStream()
This method allows the caller to retrieve any data that might have been sent despite the fact that an error occurred.
String
getHeaderField(int index)
String
getHeaderField(String name)
long
getHeaderFieldDate(String name, long def)
Returns the value of the named field parsed as date
String
getHeaderFieldKey(int index)
Map>
getHeaderFields()
InputStream
getInputStream()
Certificate[]
getLocalCertificates()
Returns the certificates used on the local side in this connection.
OutputStream
getOutputStream()
String
getRequestProperty(String key)
int
getResponseCode()
Gets the status code from an HTTP response message, or -1 if the response code could not be determined.
String
getResponseMessage()
Gets the HTTP response message, if any, returned along with the response code from a server.
Certificate[]
getServerCertificates()
Returns the certificates sent by the other party.
void
handshakeCompleted(HandshakeCompletedEvent event)
void
setReadTimeout(int timeout)
Set the read timeout, in milliseconds, or zero if the timeout is to be considered infinite.
void
setRequestMethod(String method)
Overrides the corresponding method in HttpURLConnection to permit arbitrary methods, as long as they're valid ASCII alphabetic characters.
void
setRequestProperty(String key, String value)
boolean
usingProxy()
Returns a boolean indicating whether or not this connection is going through a proxy

Methods inherited from class javax.net.ssl.HttpsURLConnection

getCipherSuite, getDefaultHostnameVerifier, getDefaultSSLSocketFactory, getHostnameVerifier, getLocalCertificates, getLocalPrincipal, getPeerPrincipal, getSSLSocketFactory, getServerCertificates, setDefaultHostnameVerifier, setDefaultSSLSocketFactory, setHostnameVerifier, setSSLSocketFactory

Methods inherited from class java.net.HttpURLConnection

disconnect, getErrorStream, getFollowRedirects, getHeaderFieldDate, getInstanceFollowRedirects, getPermission, getRequestMethod, getResponseCode, getResponseMessage, setFollowRedirects, setInstanceFollowRedirects, setRequestMethod, usingProxy

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, getHeaderFieldDate, getHeaderFieldInt, getHeaderFieldKey, getHeaderFields, getIfModifiedSince, getInputStream, getLastModified, getOutputStream, getPermission, 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, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructor Details

HTTPURLConnection

public HTTPURLConnection(URL url)
            throws IOException
Constructor.
Parameters:
url - the URL

Method Details

List> getRequestProperties

public MapList> getRequestProperties()

addRequestProperty

public void addRequestProperty(String key,
                               String value)
Overrides:
addRequestProperty in interface URLConnection

connect

public void connect()
            throws IOException
Overrides:
connect in interface URLConnection

disconnect

public void disconnect()
Closes the connection to the server.
Overrides:
disconnect in interface HttpURLConnection

getCipherSuite

public String getCipherSuite()
Returns the cipher name negotiated for this connection.
Overrides:
getCipherSuite in interface HttpsURLConnection
Returns:
The cipher name.
Throws:
IllegalStateException - If the connection has not yet been established.

getContentType

public String getContentType()
Overrides:
getContentType in interface URLConnection

getErrorStream

public InputStream getErrorStream()
This method allows the caller to retrieve any data that might have been sent despite the fact that an error occurred. For example, the HTML page sent along with a 404 File Not Found error. If the socket is not connected, or if no error occurred or no data was returned, this method returns null.
Overrides:
getErrorStream in interface HttpURLConnection
Returns:
An InputStream for reading error data.

getHeaderField

public String getHeaderField(int index)
Overrides:
getHeaderField in interface URLConnection

getHeaderField

public String getHeaderField(String name)
Overrides:
getHeaderField in interface URLConnection

getHeaderFieldDate

public long getHeaderFieldDate(String name,
                               long def)
Returns the value of the named field parsed as date
Overrides:
getHeaderFieldDate in interface HttpURLConnection
Parameters:
Returns:
the value of the header field

getHeaderFieldKey

public String getHeaderFieldKey(int index)
Overrides:
getHeaderFieldKey in interface URLConnection

getHeaderFields

public Map> getHeaderFields()
Overrides:
getHeaderFields in interface URLConnection

getInputStream

public InputStream getInputStream()
            throws IOException
Overrides:
getInputStream in interface URLConnection

getLocalCertificates

public Certificate[] getLocalCertificates()
Returns the certificates used on the local side in this connection.
Overrides:
getLocalCertificates in interface HttpsURLConnection
Returns:
The local certificates.
Throws:
IllegalStateException - If the connection has not yet been established.

getOutputStream

public OutputStream getOutputStream()
            throws IOException
Overrides:
getOutputStream in interface URLConnection

getRequestProperty

public String getRequestProperty(String key)
Overrides:
getRequestProperty in interface URLConnection

getResponseCode

public int getResponseCode()
            throws IOException
Gets the status code from an HTTP response message, or -1 if the response code could not be determined. Note that all valid response codes have class variables defined for them in this class.
Overrides:
getResponseCode in interface HttpURLConnection
Returns:
The response code
Throws:
IOException - If an error occurs

getResponseMessage

public String getResponseMessage()
            throws IOException
Gets the HTTP response message, if any, returned along with the response code from a server. Null if no response message was set or an error occured while connecting.
Overrides:
getResponseMessage in interface HttpURLConnection
Returns:
The response message
Throws:
IOException - If an error occurs

getServerCertificates

public Certificate[] getServerCertificates()
            throws SSLPeerUnverifiedException
Returns the certificates sent by the other party.
Overrides:
getServerCertificates in interface HttpsURLConnection
Returns:
The peer's certificates.
Throws:
IllegalStateException - If the connection has not yet been established.
SSLPeerUnverifiedException - If the peer could not be verified.

handshakeCompleted

public void handshakeCompleted(HandshakeCompletedEvent event)
Specified by:
handshakeCompleted in interface HandshakeCompletedListener

setReadTimeout

public void setReadTimeout(int timeout)
            throws IllegalArgumentException
Set the read timeout, in milliseconds, or zero if the timeout is to be considered infinite. Overloaded.
Overrides:
setReadTimeout in interface URLConnection

setRequestMethod

public void setRequestMethod(String method)
            throws ProtocolException
Overrides the corresponding method in HttpURLConnection to permit arbitrary methods, as long as they're valid ASCII alphabetic characters. This is to permit WebDAV and other HTTP extensions to function.
Overrides:
setRequestMethod in interface HttpURLConnection
Parameters:
method - the method

setRequestProperty

public void setRequestProperty(String key,
                               String value)
Overrides:
setRequestProperty in interface URLConnection

usingProxy

public boolean usingProxy()
Returns a boolean indicating whether or not this connection is going through a proxy
Overrides:
usingProxy in interface HttpURLConnection
Returns:
true if through a proxy, false otherwise

HTTPURLConnection.java -- Copyright (C) 2004, 2005, 2006 Free Software Foundation, Inc. This file is part of GNU Classpath. GNU Classpath is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2, or (at your option) any later version. GNU Classpath is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with GNU Classpath; see the file COPYING. If not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. Linking this library statically or dynamically with other modules is making a combined work based on this library. Thus, the terms and conditions of the GNU General Public License cover the whole combination. As a special exception, the copyright holders of this library give you permission to link this library with independent modules to produce an executable, regardless of the license terms of these independent modules, and to copy and distribute the resulting executable under terms of your choice, provided that you also meet, for each linked independent module, the terms and conditions of the license of that module. An independent module is a module which is not derived from or based on this library. If you modify this library, you may extend this exception to your version of the library, but you are not obligated to do so. If you do not wish to do so, delete this exception statement from your version.