com.gargoylesoftware.htmlunit
Class HttpWebConnection

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.HttpWebConnection
All Implemented Interfaces:
WebConnection

public class HttpWebConnection
extends java.lang.Object
implements WebConnection

Default implementation of WebConnection, using the HttpClient library to perform HTTP requests.

Version:
$Revision: 4789 $
Author:
Mike Bowler, Noboru Sinohara, David D. Kilzer, Marc Guillemot, Brad Clarke, Ahmed Ashour

Constructor Summary
HttpWebConnection(WebClient webClient)
          Creates a new HTTP web connection instance.
 
Method Summary
protected  org.apache.commons.httpclient.HttpClient createHttpClient()
          Creates the HttpClient that will be used by this WebConnection.
static DownloadedContent downloadContent(java.io.InputStream is)
          Reads the content of the stream and saves it in memory or on the file system.
protected  org.apache.commons.httpclient.HttpClient getHttpClient()
          Lazily initializes the internal HTTP client.
 WebResponse getResponse(WebRequestSettings settings)
          Submits a request and retrieves a response.
protected  int getTimeout()
          Returns the timeout to use for socket and connection timeouts for HttpConnectionManager.
 java.lang.String getVirtualHost()
          Gets the virtual host.
protected  WebResponseData newWebResponseDataInstance(java.lang.String statusMessage, java.util.List<org.apache.commons.httpclient.NameValuePair> headers, int statusCode, org.apache.commons.httpclient.HttpMethodBase method)
          Constructs an appropriate WebResponseData.
protected  WebResponse newWebResponseInstance(java.lang.String charset, WebResponseData responseData, long loadTime, WebRequestSettings requestSettings)
          Deprecated. As of 2.6, please use newWebResponseInstance(WebResponseData, long, WebRequestSettings)
protected  WebResponse newWebResponseInstance(WebResponseData responseData, long loadTime, WebRequestSettings requestSettings)
          Constructs an appropriate WebResponse.
protected  void onResponseGenerated(org.apache.commons.httpclient.HttpMethodBase httpMethod)
          Called when the response has been generated.
 void setVirtualHost(java.lang.String virtualHost)
          Sets the virtual host.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpWebConnection

public HttpWebConnection(WebClient webClient)
Creates a new HTTP web connection instance.

Parameters:
webClient - the WebClient that is using this connection
Method Detail

getResponse

public WebResponse getResponse(WebRequestSettings settings)
                        throws java.io.IOException
Submits a request and retrieves a response.

Specified by:
getResponse in interface WebConnection
Parameters:
settings - Settings to make the request with
Returns:
the response to the request defined by the specified request settings
Throws:
java.io.IOException - if an IO error occurs

onResponseGenerated

protected void onResponseGenerated(org.apache.commons.httpclient.HttpMethodBase httpMethod)
Called when the response has been generated. Default action is to release the HttpMethod's connection. Subclasses may override.

Parameters:
httpMethod - the httpMethod used

getHttpClient

protected org.apache.commons.httpclient.HttpClient getHttpClient()
Lazily initializes the internal HTTP client.

Returns:
the initialized HTTP client

getTimeout

protected int getTimeout()
Returns the timeout to use for socket and connection timeouts for HttpConnectionManager. Is overridden to 0 by StreamingWebConnection which keeps reading after a timeout and must have long running connections explicitly terminated.

Returns:
the WebClient's timeout

createHttpClient

protected org.apache.commons.httpclient.HttpClient createHttpClient()
Creates the HttpClient that will be used by this WebConnection. Extensions may override this method in order to create a customized HttpClient instance (e.g. with a custom HttpConnectionManager to perform some tracking; see feature request 1438216).

Returns:
the HttpClient that will be used by this WebConnection

setVirtualHost

public void setVirtualHost(java.lang.String virtualHost)
Sets the virtual host.

Parameters:
virtualHost - the virtualHost to set

getVirtualHost

public java.lang.String getVirtualHost()
Gets the virtual host.

Returns:
virtualHost The current virtualHost

downloadContent

public static DownloadedContent downloadContent(java.io.InputStream is)
                                         throws java.io.IOException
Reads the content of the stream and saves it in memory or on the file system.

Parameters:
is - the stream to read
Returns:
a wrapper around the downloaded content
Throws:
java.io.IOException - in case of read issues

newWebResponseDataInstance

protected WebResponseData newWebResponseDataInstance(java.lang.String statusMessage,
                                                     java.util.List<org.apache.commons.httpclient.NameValuePair> headers,
                                                     int statusCode,
                                                     org.apache.commons.httpclient.HttpMethodBase method)
                                              throws java.io.IOException
Constructs an appropriate WebResponseData. May be overridden by subclasses to return a specialized WebResponseData.

Parameters:
statusMessage - StatusMessage from the response
headers - response headers
statusCode - response status code
method - request method
Returns:
the WebResponseData to use for this response
Throws:
java.io.IOException - if there is a problem reading the response body

newWebResponseInstance

@Deprecated
protected WebResponse newWebResponseInstance(java.lang.String charset,
                                                        WebResponseData responseData,
                                                        long loadTime,
                                                        WebRequestSettings requestSettings)
Deprecated. As of 2.6, please use newWebResponseInstance(WebResponseData, long, WebRequestSettings)

Constructs an appropriate WebResponse. May be overridden by subclasses to return a specialized WebResponse.

Parameters:
responseData - Data that was send back
charset - Charset used if not returned in the response
requestSettings - the request settings used to get this response
loadTime - How long the response took to be sent
Returns:
the new WebResponse

newWebResponseInstance

protected WebResponse newWebResponseInstance(WebResponseData responseData,
                                             long loadTime,
                                             WebRequestSettings requestSettings)
Constructs an appropriate WebResponse. May be overridden by subclasses to return a specialized WebResponse.

Parameters:
responseData - Data that was send back
requestSettings - the request settings used to get this response
loadTime - How long the response took to be sent
Returns:
the new WebResponse


Copyright © 2002-2011 Gargoyle Software Inc.. All Rights Reserved.