com.gargoylesoftware.htmlunit.util
Class FalsifyingWebConnection

java.lang.Object
  extended by com.gargoylesoftware.htmlunit.util.WebConnectionWrapper
      extended by com.gargoylesoftware.htmlunit.util.FalsifyingWebConnection
All Implemented Interfaces:
WebConnection

public abstract class FalsifyingWebConnection
extends WebConnectionWrapper

Extension of WebConnectionWrapper providing facility methods to deliver something other than what the wrapped connection would deliver.

Version:
$Revision: 5679 $
Author:
Marc Guillemot

Constructor Summary
FalsifyingWebConnection(WebClient webClient)
          Constructs an instance and places itself as connection of the WebClient.
FalsifyingWebConnection(WebConnection webConnection)
          Constructs a WebConnection object wrapping provided WebConnection.
 
Method Summary
protected  WebResponse createWebResponse(WebRequest wr, String content, String contentType)
          Creates a faked WebResponse for the request with the provided content.
protected  WebResponse createWebResponse(WebRequest wr, String content, String contentType, int responseCode, String responseMessage)
          Creates a faked WebResponse for the request with the provided content.
protected  WebResponse deliverFromAlternateUrl(WebRequest webRequest, URL url)
          Delivers the content for an alternate URL as if it comes from the requested URL.
protected  WebResponse replaceContent(WebResponse wr, String newContent)
          Builds a WebResponse with new content, preserving all other information.
 
Methods inherited from class com.gargoylesoftware.htmlunit.util.WebConnectionWrapper
getResponse
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FalsifyingWebConnection

public FalsifyingWebConnection(WebConnection webConnection)
                        throws IllegalArgumentException
Constructs a WebConnection object wrapping provided WebConnection.

Parameters:
webConnection - the webConnection that does the real work
Throws:
IllegalArgumentException - if the connection is null

FalsifyingWebConnection

public FalsifyingWebConnection(WebClient webClient)
                        throws IllegalArgumentException
Constructs an instance and places itself as connection of the WebClient.

Parameters:
webClient - the WebClient which WebConnection should be wrapped
Throws:
IllegalArgumentException - if the WebClient is null
Method Detail

deliverFromAlternateUrl

protected WebResponse deliverFromAlternateUrl(WebRequest webRequest,
                                              URL url)
                                       throws IOException
Delivers the content for an alternate URL as if it comes from the requested URL.

Parameters:
webRequest - the original web request
url - the URL from which the content should be retrieved
Returns:
the response
Throws:
IOException - if a problem occurred

replaceContent

protected WebResponse replaceContent(WebResponse wr,
                                     String newContent)
                              throws IOException
Builds a WebResponse with new content, preserving all other information.

Parameters:
wr - the web response to adapt
newContent - the new content to place in the response
Returns:
a web response with the new content
Throws:
IOException - if an encoding problem occurred

createWebResponse

protected WebResponse createWebResponse(WebRequest wr,
                                        String content,
                                        String contentType)
                                 throws IOException
Creates a faked WebResponse for the request with the provided content.

Parameters:
wr - the web request for which a response should be created
content - the content to place in the response
contentType - the content type of the response
Returns:
a web response with the provided content
Throws:
IOException - if an encoding problem occurred

createWebResponse

protected WebResponse createWebResponse(WebRequest wr,
                                        String content,
                                        String contentType,
                                        int responseCode,
                                        String responseMessage)
                                 throws IOException
Creates a faked WebResponse for the request with the provided content.

Parameters:
wr - the web request for which a response should be created
content - the content to place in the response
contentType - the content type of the response
responseCode - the HTTP code for the response
responseMessage - the HTTP message for the response
Returns:
a web response with the provided content
Throws:
IOException - if an encoding problem occurred


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