Class WebConnectionWrapper

  • All Implemented Interfaces:
    java.lang.AutoCloseable, WebConnection
    Direct Known Subclasses:
    DebuggingWebConnection, FalsifyingWebConnection

    public class WebConnectionWrapper
    extends java.lang.Object
    implements WebConnection

    Provides a convenient implementation of the WebConnection interface that can be subclassed by developers wishing to adapt a particular WebConnection.

    This class implements the Wrapper or Decorator pattern. Methods default to calling through to the wrapped web connection object.

    • Constructor Detail

      • WebConnectionWrapper

        public WebConnectionWrapper​(WebConnection webConnection)
                             throws java.lang.IllegalArgumentException
        Constructs a WebConnection object wrapping provided WebConnection.
        Parameters:
        webConnection - the webConnection that does the real work
        Throws:
        java.lang.IllegalArgumentException - if the connection is null
      • WebConnectionWrapper

        public WebConnectionWrapper​(WebClient webClient)
                             throws java.lang.IllegalArgumentException
        Constructs a WebConnection object wrapping the connection of the WebClient and places itself as connection of the WebClient.
        Parameters:
        webClient - the WebClient which WebConnection should be wrapped
        Throws:
        java.lang.IllegalArgumentException - if the WebClient is null
    • Method Detail

      • getResponse

        public WebResponse getResponse​(WebRequest request)
                                throws java.io.IOException
        Submits a request and retrieves a response. The default behavior of this method is to return WebConnection.getResponse(WebRequest) on the wrapped connection object.
        Specified by:
        getResponse in interface WebConnection
        Parameters:
        request - the request
        Returns:
        the response to the request defined by the specified request
        Throws:
        java.io.IOException - if an IO error occurs
      • getWrappedWebConnection

        public WebConnection getWrappedWebConnection()
        Gets the wrapped WebConnection.
        Returns:
        the wrapped connection
      • close

        public void close()
                   throws java.io.IOException
        The default behavior of this method is to return WebConnection.close() on the wrapped connection object.
        Specified by:
        close in interface java.lang.AutoCloseable
        Specified by:
        close in interface WebConnection
        Throws:
        java.io.IOException