Class HttpTransaction


  • public class HttpTransaction
    extends Object
    Handle HTTP based search operations. Send (POST or GET) a query to the server, read up the response. The response text and HTTP details (status, character set, etc) are made available to caller.
    • Constructor Detail

      • HttpTransaction

        public HttpTransaction()
        Default constructor
    • Method Detail

      • initialize

        public void initialize​(URL url,
                               List cookieList)
        Initialize.
      • initialize

        public void initialize​(List cookieList)
        Initialize
      • setTransactionType

        public void setTransactionType​(String type)
        Set the transaction type
        Parameters:
        type - (GET or POST)
      • setFollowRedirects

        public void setFollowRedirects​(boolean follow)
        Honor redirects?
        Parameters:
        follow - Set as true to follow any redirects suggested
      • setParameter

        public void setParameter​(String name,
                                 String value)
        Set up a name=value pair
        Parameters:
        name - Parameter name
        value - Parameter value
      • getParameter

        public String getParameter​(String name)
        Get a named parameter
        Parameters:
        name - Parameter name
        Returns:
        Parameter value
      • getParameterName

        public String getParameterName​(String value)
        Get parameter the name of first occurance of the supplied value
        Parameters:
        value - Parameter value
        Returns:
        Parameter name
      • clearParameters

        public void clearParameters()
        Empty the parameter list
      • getResponseCode

        public int getResponseCode()
        Get the response status
        Returns:
        The HTTP response code
      • getUrl

        public String getUrl()
        Get the URL text sent to the server
        Returns:
        URL string
      • setPreserveBaseUrlFile

        public void setPreserveBaseUrlFile​(boolean state)
        Set the "preserve URL file" flag
        Parameters:
        state - true to preserve the URL file portion (default is false)
      • getResponseBytes

        public byte[] getResponseBytes()
        Get the unfiltered response as sent by the server (debug)
        Returns:
        Response text as recieved
      • getResponseString

        public String getResponseString()
        Get the character-set-encoded String rendition of the server response
        Returns:
        Response text as recieved
      • getResponseHeaders

        public CaseBlindHashMap getResponseHeaders()
        Get all HTTP response headers
        Returns:
        CaseBlindHashMap of response-field/value pairs
      • getResponseHeader

        public String getResponseHeader​(String key)
        Get a named HTTP response
        Returns:
        Response value
      • getResponseCookies

        public List getResponseCookies()
        Get all provided cookies
        Returns:
        CaseBlindHashMap of response-field/value pairs
      • getResponseCharacterSet

        public String getResponseCharacterSet()
        Get the response document character set (supplied by the server)
        Returns:
        The character set (as a String, default to iso-8859-1)
      • setDefaultCharacterSet

        public void setDefaultCharacterSet​(String cs)
        Set the default character set
        Parameters:
        cs - Character set (utf-8, etc) Note: the character set defaults to DEFAULTCS (above) if not overridden
      • getDefaultCharacterSet

        public String getDefaultCharacterSet()
        Get the default character set (use if none supplied by server)
        Returns:
        The character set (iso-8859-1, utf-8, etc)
      • setInputCharacterSet

        public void setInputCharacterSet​(String cs)
        Set the input character set
        Parameters:
        cs - Character set (utf-8, etc) Note: the character set defaults to DEFAULTCS (above) if not overridden
      • getInputCharacterSet

        public String getInputCharacterSet()
        Get the default character set (use if none supplied by server)
        Returns:
        The character set (iso-8859-1, utf-8, etc)
      • doTransaction

        public int doTransaction​(String url)
                          throws IOException,
                                 DomException
        Perform one command transaction - add parameters and build the URL
        Parameters:
        url - URL string to server-side resource
        Returns:
        HTTP response code
        Throws:
        IOException
        DomException