org.eclipse.webdav.http.client
Class HttpConnection

java.lang.Object
  extended by org.eclipse.webdav.http.client.HttpConnection
All Implemented Interfaces:
IStatusCodes

public class HttpConnection
extends Object
implements IStatusCodes

A connection to an HTTP/1.0 or HTTP/1.1 compatable server.

Note: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.


Nested Class Summary
 class HttpConnection.Header
          A request or response header.
 
Field Summary
protected  HttpConnection.Header internalHeader
           
protected  HttpConnection.Header requestHeader
           
protected  HttpConnection.Header responseHeader
           
protected  InputStream socketIn
           
protected  OutputStream socketOut
           
 
Fields inherited from interface org.eclipse.webdav.http.client.IStatusCodes
HTTP_ACCEPTED, HTTP_BAD_GATEWAY, HTTP_BAD_REQUEST, HTTP_CONFLICT, HTTP_CONTINUE, HTTP_CREATED, HTTP_EXPECTATION_FAILED, HTTP_FORBIDDEN, HTTP_GATEWAY_TIMEOUT, HTTP_GONE, HTTP_HTTP_VERSION_NOT_SUPPORTED, HTTP_INTERNAL_SERVER_ERROR, HTTP_LENGTH_REQUIRED, HTTP_METHOD_NOT_ALLOWED, HTTP_MOVED_PERMANENTLY, HTTP_MOVED_TEMPORARILY, HTTP_MULTIPLE_CHOICES, HTTP_NO_CONTENT, HTTP_NON_AUTHORITATIVE_INFORMATION, HTTP_NOT_ACCEPTABLE, HTTP_NOT_FOUND, HTTP_NOT_IMPLEMENTED, HTTP_NOT_MODIFIED, HTTP_OK, HTTP_PARTIAL_CONTENT, HTTP_PAYMENT_REQUIRED, HTTP_PRECONDITION_FAILED, HTTP_PROXY_AUTHENTICATION_REQUIRED, HTTP_REQUEST_TIMEOUT, HTTP_REQUEST_TOO_LONG, HTTP_REQUEST_URI_TOO_LONG, HTTP_REQUESTED_RANGE_NOT_SATISFIABLE, HTTP_RESET_CONTENT, HTTP_SEE_OTHER, HTTP_SERVICE_UNAVAILABLE, HTTP_SWITCHING_PROTOCOLS, HTTP_TEMPORARY_REDIRECT, HTTP_UNAUTHORIZED, HTTP_UNSUPPORTED_MEDIA_TYPE, HTTP_USE_PROXY
 
Constructor Summary
HttpConnection(URL resourceUrl)
          Creates a new connection on the specified resource.
HttpConnection(URL proxyServerUrl, URL resourceUrl)
          Creates a new connection on the specified resource.
 
Method Summary
 void clearRequestHeader()
          Clear the request header.
 void close()
          Close this connection.
 double getHttpVersion()
          Returns the version of HTTP this connection uses for communication with servers.
 InputStream getInputStream()
          Returns this connection's InputStream.
 OutputStream getOutputStream()
          Returns this connection's OutputStream.
 boolean getPersistent()
          Returns a boolean indicating whether this connection should remain open after each request.
 URL getProxyServerUrl()
          Returns the URL of the proxy server this connection uses to communicate with the origin server, or null if a proxy server is not used.
 int getReceiveBufferSize()
           
 String getRequestHeaderFieldValue(String fieldName)
          Returns the request header value associated with the given field name, or null if there is no such field name.
 String getRequestMethod()
          Returns the request method.
 URL getResourceUrl()
          Returns the URL of this connection's resource.
 String getResponseHeaderFieldName(int position)
          Returns the response header field name at the given position, or null if there is no field name at that position.
 String getResponseHeaderFieldValue(int position)
          Returns the response header field value at the given position, or null if there is no value at that position.
 String getResponseHeaderFieldValue(String fieldName)
          Returns the response header field value that is associated with the given field name, or null if there is no value associated with that field name.
 int getSendBufferSize()
           
 boolean getSendChunked()
          Returns a boolean indicating whether the request's body should be sent chunked encoded.
 int getSoLinger()
           
 int getSoTimeout()
           
 int getStatusCode()
          Returns the status code of the server's response.
 String getStatusMessage()
          Returns the status message of the server's response.
 boolean getTcpNoDelay()
           
 Date getTimestamp()
          Returns this connection's timestamp.
protected  void output(OutputStream stream, String output)
           
protected  void readHeader(HttpConnection.Header header)
           
protected  String readln()
           
protected  void readServerResponse()
           
protected  void sendRequest()
           
 void setHttpVersion(double version)
          Sets the version of HTTP this connection uses for communication with servers.
 void setPersistent(boolean close)
          Sets a boolean indicating whether this connection should remain open after each request.
 void setProxyServerUrl(URL proxyServerUrl)
          Sets the URL of the proxy server this connection uses to communicate with the origin server.
 void setReceiveBufferSize(int size)
           
 void setRequestHeaderField(String fieldName, String fieldValue)
          Sets the request header value associated with the given field.
 void setRequestMethod(String method)
          Sets the request method.
 void setResourceUrl(URL resourceUrl)
          Sets the URL of this connection's resource.
 void setSendBufferSize(int size)
           
 void setSendChunked(boolean chunked)
          Sets a boolean indicating whether the request's body should be sent chunked encoded.
 void setSocketFactory(ISocketFactory socketFactory)
          Sets the factory this connection uses to create sockets.
 void setSoLinger(boolean on, int linger)
           
 void setSoTimeout(int timeout)
           
 void setTcpNoDelay(boolean on)
           
 void setTimestamp(Date date)
          Sets this connection's timestamp.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

requestHeader

protected HttpConnection.Header requestHeader

responseHeader

protected HttpConnection.Header responseHeader

internalHeader

protected HttpConnection.Header internalHeader

socketIn

protected InputStream socketIn

socketOut

protected OutputStream socketOut
Constructor Detail

HttpConnection

public HttpConnection(URL resourceUrl)
Creates a new connection on the specified resource.

Parameters:
resourceUrl - the URL of a resource

HttpConnection

public HttpConnection(URL proxyServerUrl,
                      URL resourceUrl)
Creates a new connection on the specified resource. This connection communicates through the proxy at the given proxy server URL.

Parameters:
proxyServerUrl - the URL of a proxy server
resourceUrl - the URL of a resource
Method Detail

clearRequestHeader

public void clearRequestHeader()
Clear the request header.


close

public void close()
           throws IOException
Close this connection.

Throws:
IOException - if there is an I/O error closing the socket

getHttpVersion

public double getHttpVersion()
Returns the version of HTTP this connection uses for communication with servers. HTTP/1.1 is used by default.

Returns:
the version of HTTP this connection uses for communication with servers
See Also:
setHttpVersion(double)

getInputStream

public InputStream getInputStream()
                           throws IOException
Returns this connection's InputStream.

Returns:
this connection's InputStream
Throws:
IOException - if an I/O error occurs while sending the request

getOutputStream

public OutputStream getOutputStream()
                             throws IOException
Returns this connection's OutputStream.

Returns:
this connection's OutputStream
Throws:
IOException - if an I/O error occurs while sending the request

getPersistent

public boolean getPersistent()
Returns a boolean indicating whether this connection should remain open after each request.

Returns:
a boolean indicating whether this connection should remain open after each request
See Also:
setPersistent(boolean)

getProxyServerUrl

public URL getProxyServerUrl()
Returns the URL of the proxy server this connection uses to communicate with the origin server, or null if a proxy server is not used.

Returns:
the URL of the proxy server this connection uses to communicate with the origin server
See Also:
setProxyServerUrl(URL)

getReceiveBufferSize

public int getReceiveBufferSize()
                         throws IOException
Throws:
IOException
See Also:
Socket.getReceiveBufferSize(), setReceiveBufferSize(int)

getRequestHeaderFieldValue

public String getRequestHeaderFieldValue(String fieldName)
Returns the request header value associated with the given field name, or null if there is no such field name.

Parameters:
fieldName - the request header field name
Returns:
the request header value associated with the given field name
See Also:
setRequestHeaderField(String, String)

getRequestMethod

public String getRequestMethod()
Returns the request method. "GET" is used by default.

Returns:
the request method
See Also:
setRequestMethod(String)

getResourceUrl

public URL getResourceUrl()
Returns the URL of this connection's resource.

Returns:
the URL of this connection's resource
See Also:
setResourceUrl(URL)

getResponseHeaderFieldName

public String getResponseHeaderFieldName(int position)
                                  throws IOException
Returns the response header field name at the given position, or null if there is no field name at that position.

Parameters:
position - a position in the response header greater than or equal to zero
Returns:
the response header field name at the given postion
Throws:
IOException - if an I/O error occurs while sending the request
See Also:
getResponseHeaderFieldValue(int), getResponseHeaderFieldValue(String)

getResponseHeaderFieldValue

public String getResponseHeaderFieldValue(int position)
                                   throws IOException
Returns the response header field value at the given position, or null if there is no value at that position.

Parameters:
position - a position in the response header greater than or equal to zero
Returns:
the response header field value at the given postion
Throws:
IOException - if an I/O error occurs while sending the request
See Also:
getResponseHeaderFieldName(int), getResponseHeaderFieldValue(String)

getResponseHeaderFieldValue

public String getResponseHeaderFieldValue(String fieldName)
                                   throws IOException
Returns the response header field value that is associated with the given field name, or null if there is no value associated with that field name.

Parameters:
fieldName - the name of a response header field
Returns:
the response header field value that is associated with the given field name
Throws:
IOException - if an I/O error occurs while sending the request
See Also:
getResponseHeaderFieldValue(int), getResponseHeaderFieldName(int)

getSendBufferSize

public int getSendBufferSize()
                      throws IOException
Throws:
IOException
See Also:
Socket.getSendBufferSize(), setSendBufferSize(int)

getSendChunked

public boolean getSendChunked()
Returns a boolean indicating whether the request's body should be sent chunked encoded.

Returns:
a boolean indicating whether the request's body should be sent chunked encoded
See Also:
setSendChunked(boolean)

getSoLinger

public int getSoLinger()
See Also:
Socket.getSoLinger(), setSoLinger(boolean, int)

getSoTimeout

public int getSoTimeout()
See Also:
Socket.getSoTimeout(), setSoTimeout(int)

getStatusCode

public int getStatusCode()
                  throws IOException
Returns the status code of the server's response.

Returns:
the status code of the server's response
Throws:
IOException - if an I/O error occurs while sending the request
See Also:
getStatusMessage()

getStatusMessage

public String getStatusMessage()
                        throws IOException
Returns the status message of the server's response.

Returns:
the status message of the server's response
Throws:
IOException - if an I/O error occurs while sending the request
See Also:
getStatusCode()

getTcpNoDelay

public boolean getTcpNoDelay()
See Also:
Socket.getTcpNoDelay(), setTcpNoDelay(boolean)

getTimestamp

public Date getTimestamp()
Returns this connection's timestamp.

Returns:
this connection's timestamp
See Also:
setTimestamp(Date)

output

protected void output(OutputStream stream,
                      String output)
               throws IOException
Throws:
IOException

readHeader

protected void readHeader(HttpConnection.Header header)
                   throws IOException
Throws:
IOException

readln

protected String readln()
                 throws IOException
Throws:
IOException

readServerResponse

protected void readServerResponse()
                           throws IOException
Throws:
IOException

sendRequest

protected void sendRequest()
                    throws IOException
Throws:
IOException

setHttpVersion

public void setHttpVersion(double version)
Sets the version of HTTP this connection uses for communication with servers. HTTP/1.1 is used by default.

Parameters:
version - the version of HTTP this connection uses for communication with servers
See Also:
getHttpVersion()

setPersistent

public void setPersistent(boolean close)
Sets a boolean indicating whether this connection should remain open after each request.

Parameters:
close - a boolean indicating whether this connection should remain open after each request
See Also:
getPersistent()

setProxyServerUrl

public void setProxyServerUrl(URL proxyServerUrl)
Sets the URL of the proxy server this connection uses to communicate with the origin server. If null is given, no proxy server is used.

Parameters:
proxyServerUrl - the URL of a proxy server
See Also:
getProxyServerUrl()

setReceiveBufferSize

public void setReceiveBufferSize(int size)
                          throws IOException
Throws:
IOException
See Also:
Socket.setReceiveBufferSize(int), getReceiveBufferSize()

setRequestHeaderField

public void setRequestHeaderField(String fieldName,
                                  String fieldValue)
Sets the request header value associated with the given field.

Parameters:
fieldName - the request header field
fieldValue - the request header value
See Also:
getRequestHeaderFieldValue(String)

setRequestMethod

public void setRequestMethod(String method)
Sets the request method. "GET" is used by default.

Parameters:
method - the request method
See Also:
getRequestMethod()

setResourceUrl

public void setResourceUrl(URL resourceUrl)
Sets the URL of this connection's resource.

Parameters:
resourceUrl - the URL of this connection's resource
See Also:
getResourceUrl()

setSendBufferSize

public void setSendBufferSize(int size)
                       throws IOException
Throws:
IOException
See Also:
Socket.setSendBufferSize(int), getSendBufferSize()

setSendChunked

public void setSendChunked(boolean chunked)
Sets a boolean indicating whether the request's body should be sent chunked encoded.

Parameters:
chunked - a boolean indicating whether the request's body should be sent chunked encoded
See Also:
getSendChunked()

setSocketFactory

public void setSocketFactory(ISocketFactory socketFactory)
Sets the factory this connection uses to create sockets. If the given socket factory is null the default socket is used.

Parameters:
socketFactory - the factory this connection uses to create sockets

setSoLinger

public void setSoLinger(boolean on,
                        int linger)
                 throws IOException
Throws:
IOException
See Also:
Socket.setSoLinger(boolean, int), getSoLinger()

setSoTimeout

public void setSoTimeout(int timeout)
                  throws IOException
Throws:
IOException
See Also:
Socket.setSoTimeout(int), getSoTimeout()

setTcpNoDelay

public void setTcpNoDelay(boolean on)
                   throws IOException
Throws:
IOException
See Also:
Socket.setTcpNoDelay(boolean), getTcpNoDelay()

setTimestamp

public void setTimestamp(Date date)
Sets this connection's timestamp.

Parameters:
date - this connection's timestamp
See Also:
getTimestamp()


Copyright © 2001-2014 JBoss by Red Hat. All Rights Reserved.