jimm.twice.util
Class HttpTalker

java.lang.Object
  extended byjimm.twice.util.HttpTalker

public class HttpTalker
extends java.lang.Object

Handles request and request/receive communications with an HTTP server. This class exists so we can replace instances during testing.


Field Summary
protected static java.lang.String DEFAULT_LOGGER_PREFIX
           
protected static HttpTalker instance
           
protected  java.lang.String loggerPrefix
           
protected static int TEMP_FILE_BUFSIZ
           
protected static java.lang.String TEMP_FILE_PREFIX
           
protected static java.lang.String TEMP_FILE_SUFFIX
           
 
Constructor Summary
HttpTalker()
           
 
Method Summary
static HttpTalker getInstance()
          Returns an instance of instanceClassNameK, which is HttpTalker by default.
 java.io.File getURL(java.net.URL url)
          Retrieves the contents of a URL, stores it in a temp file, and returns the file.
protected  java.io.File readIntoTempFile(java.io.InputStream source)
           
 java.io.File sendPayload(SoapEnvelope payload, java.net.URL url)
          Sends a payload, saves the XML response to a temp file, and returns the temp file.
static void setInstance(HttpTalker talker)
          Sets class name for getInstance() to return.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TEMP_FILE_PREFIX

protected static final java.lang.String TEMP_FILE_PREFIX
See Also:
Constant Field Values

TEMP_FILE_SUFFIX

protected static final java.lang.String TEMP_FILE_SUFFIX
See Also:
Constant Field Values

DEFAULT_LOGGER_PREFIX

protected static final java.lang.String DEFAULT_LOGGER_PREFIX
See Also:
Constant Field Values

TEMP_FILE_BUFSIZ

protected static final int TEMP_FILE_BUFSIZ
See Also:
Constant Field Values

instance

protected static HttpTalker instance

loggerPrefix

protected java.lang.String loggerPrefix
Constructor Detail

HttpTalker

public HttpTalker()
Method Detail

getInstance

public static HttpTalker getInstance()
Returns an instance of instanceClassNameK, which is HttpTalker by default.

Returns:
an HttpTalker

setInstance

public static void setInstance(HttpTalker talker)
Sets class name for getInstance() to return.


sendPayload

public java.io.File sendPayload(SoapEnvelope payload,
                                java.net.URL url)
                         throws java.io.IOException
Sends a payload, saves the XML response to a temp file, and returns the temp file.

Tech note: the order of the HTTP I/O fault (get output, write output, get input, read input) is used by the HttpURLConnection class to decide that a POST is appropriate instead of a GET.

If an IOException exception is caught, it is logged and rethrown.

Parameters:
payload - the payload we want to send
Returns:
a file containing the response XML
Throws:
java.io.IOException

getURL

public java.io.File getURL(java.net.URL url)
                    throws java.io.IOException
Retrieves the contents of a URL, stores it in a temp file, and returns the file. No ICE message is sent first; we use HTTP GET to retrieve the URL's contents.

The file returned is a temp file, marked for deletion upon exit. It is still a good idea to delete the file when you are done with it.

If an IOException exception is caught, it is logged and rethrown.

Parameters:
url - the URL to GET
Returns:
a temp XML file containing the contents of the URL
Throws:
java.io.IOException

readIntoTempFile

protected java.io.File readIntoTempFile(java.io.InputStream source)
                                 throws java.io.IOException
Throws:
java.io.IOException