com.gargoylesoftware.htmlunit
Class HttpWebConnection

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

public class HttpWebConnection
extends Object
implements WebConnection

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

Version:
$Revision: 5942 $
Author:
Mike Bowler, Noboru Sinohara, David D. Kilzer, Marc Guillemot, Brad Clarke, Ahmed Ashour, Nicolas Belisle, Ronald Brill

Constructor Summary
HttpWebConnection(WebClient webClient)
          Creates a new HTTP web connection instance.
 
Method Summary
protected  AbstractHttpClient createHttpClient()
          Creates the HttpClient that will be used by this WebClient.
static DownloadedContent downloadContent(InputStream is)
          Reads the content of the stream and saves it in memory or on the file system.
protected  DownloadedContent downloadResponseBody(org.apache.http.HttpResponse httpResponse)
          Downloads the response body.
protected  AbstractHttpClient getHttpClient()
          Lazily initializes the internal HTTP client.
 WebResponse getResponse(WebRequest request)
          Submits a request and retrieves a response.
protected  int getTimeout()
          Returns the timeout to use for socket and connection timeouts for HttpConnectionManager.
 String getVirtualHost()
          Gets the virtual host.
protected  WebResponse newWebResponseInstance(WebResponseData responseData, long loadTime, WebRequest request)
          Constructs an appropriate WebResponse.
protected  void onResponseGenerated(HttpUriRequest httpMethod)
          Called when the response has been generated.
 void setUseInsecureSSL(boolean useInsecureSSL)
          If set to true, the client will accept connections to any host, regardless of whether they have valid certificates or not.
 void setVirtualHost(String virtualHost)
          Sets the virtual host.
 void shutdown()
          Shutdown the connection manager.
 
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(WebRequest request)
                        throws IOException
Submits a request and retrieves a response.

Specified by:
getResponse in interface WebConnection
Parameters:
request - the request
Returns:
the response to the request defined by the specified request
Throws:
IOException - if an IO error occurs

onResponseGenerated

protected void onResponseGenerated(HttpUriRequest 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 (can be null)

getHttpClient

protected AbstractHttpClient 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 AbstractHttpClient createHttpClient()
Creates the HttpClient that will be used by this WebClient. Extensions may override this method in order to create a customized HttpClient instance (e.g. with a custom ClientConnectionManager to perform some tracking; see feature request 1438216).

Returns:
the HttpClient that will be used by this WebConnection

setVirtualHost

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

Parameters:
virtualHost - the virtualHost to set

getVirtualHost

public String getVirtualHost()
Gets the virtual host.

Returns:
virtualHost The current virtualHost

downloadResponseBody

protected DownloadedContent downloadResponseBody(org.apache.http.HttpResponse httpResponse)
                                          throws IOException
Downloads the response body.

Parameters:
httpResponse - the web server's response
Returns:
a wrapper for the downloaded body.
Throws:
IOException - in case of problem reading/saving the body

downloadContent

public static DownloadedContent downloadContent(InputStream is)
                                         throws 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:
IOException - in case of read issues

newWebResponseInstance

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

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

setUseInsecureSSL

public void setUseInsecureSSL(boolean useInsecureSSL)
                       throws GeneralSecurityException
If set to true, the client will accept connections to any host, regardless of whether they have valid certificates or not. This is especially useful when you are trying to connect to a server with expired or corrupt certificates.

Parameters:
useInsecureSSL - whether or not to use insecure SSL
Throws:
GeneralSecurityException - if a security error occurs

shutdown

public void shutdown()
Shutdown the connection manager.



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