org.faceless.util
Class HttpRequestWriter

java.lang.Object
  extended by org.faceless.util.HttpRequestWriter

public class HttpRequestWriter
extends Object

Represents an outgoing HTTP Request. More flexible than the java.net.URL class, this class has improved error handling and better access to the details of the request.

See Also:
HttpRequestReader, HttpResponseReader

Constructor Summary
HttpRequestWriter(HttpRequestReader request)
          Create a new HttpRequestWriter request which is an outgoing version of the specified HttpRequestReader.
HttpRequestWriter(String targeturl)
          Create a new HttpRequestWriter request to the specified URL.
 
Method Summary
 void addDateHeader(String name, long val)
          Adds a response header with the given name and date-value.
 void addHeader(String name, String value)
          Adds a response header with the given name and value.
 void addIntHeader(String name, int val)
          Sets a response header with the given name and integer value.
 void clearHeader(String name)
          Remove a header from the request.
 void close()
          Close the connection and free any resources associated with it
 boolean containsHeader(String name)
          Returns a boolean indicating whether the named response header has already been set.
 void finalize()
           
 String getHeader(String name)
          Returns the value of the header if it's set, or null if it's not
 HttpResponseReader getResponse()
          Open the connection to the URL and read it in.
 HttpResponseReader getResponse(int timeout)
          Open the connection to the URL and read it in.
 String getURL()
          Get the URL this request was originally set to retrieve
 void setDateHeader(String name, long val)
          Sets a response header with the given name and date-value.
 void setFollowRedirects(boolean follow)
          Whether to follow redirects in the response.
 void setHeader(String name, String value)
          Sets a response header with the given name and value.
 void setIntHeader(String name, int val)
          Adds a response header with the given name and integer value.
 void setURL(String targeturl)
          Set the target URL of this request
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpRequestWriter

public HttpRequestWriter(String targeturl)
                  throws IOException
Create a new HttpRequestWriter request to the specified URL. The URL is not opened.

Throws:
IOException

HttpRequestWriter

public HttpRequestWriter(HttpRequestReader request)
                  throws IOException
Create a new HttpRequestWriter request which is an outgoing version of the specified HttpRequestReader. The URL is left unchanged, and should probably be set via the setURL(java.lang.String) method.

Throws:
IOException
Method Detail

setURL

public void setURL(String targeturl)
            throws IOException
Set the target URL of this request

Throws:
IOException

setFollowRedirects

public void setFollowRedirects(boolean follow)
Whether to follow redirects in the response. A redirect occurs when the HTTP response includes a 300 level response code and the Location header is specified. The default is true.

Parameters:
follow - whether to follow redirects

getResponse

public HttpResponseReader getResponse()
                               throws IOException
Open the connection to the URL and read it in.

Throws:
IOException

getResponse

public HttpResponseReader getResponse(int timeout)
                               throws IOException
Open the connection to the URL and read it in.

Parameters:
timeout - the number of ms to wait for a connection or a response
Throws:
IOException

getURL

public String getURL()
Get the URL this request was originally set to retrieve


close

public void close()
Close the connection and free any resources associated with it


finalize

public void finalize()
Overrides:
finalize in class Object

setHeader

public void setHeader(String name,
                      String value)
Sets a response header with the given name and value. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Parameters:
name - the name of the header
value - the header value

getHeader

public String getHeader(String name)
Returns the value of the header if it's set, or null if it's not

Parameters:
name - the name of the header

addHeader

public void addHeader(String name,
                      String value)
Adds a response header with the given name and value. This method allows response headers to have multiple values.

Parameters:
name - the name of the header
value - the additional header value

clearHeader

public void clearHeader(String name)
Remove a header from the request. All values associated with this header name will be removed.

Parameters:
name - the name of the header

containsHeader

public boolean containsHeader(String name)
Returns a boolean indicating whether the named response header has already been set.

Parameters:
name - the header name
Returns:
true if the named response header has already been set; false otherwise

setDateHeader

public void setDateHeader(String name,
                          long val)
Sets a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Parameters:
name - the name of the header to set
value - the assigned date value

addDateHeader

public void addDateHeader(String name,
                          long val)
Adds a response header with the given name and date-value. The date is specified in terms of milliseconds since the epoch. This method allows response headers to have multiple values.

Parameters:
name - the name of the header to set
value - the additional date value

addIntHeader

public void addIntHeader(String name,
                         int val)
Sets a response header with the given name and integer value. If the header had already been set, the new value overwrites the previous one. The containsHeader method can be used to test for the presence of a header before setting its value.

Parameters:
name - the name of the header
value - the assigned integer value

setIntHeader

public void setIntHeader(String name,
                         int val)
Adds a response header with the given name and integer value. This method allows response headers to have multiple values.

Parameters:
name - the name of the header
value - the assigned integer value


Copyright © 2001-2004 Big Faceless Organization