ix.util.http
Class HttpStringClient

java.lang.Object
  extended by ix.util.http.HttpObjectClient
      extended by ix.util.http.HttpStringClient

public class HttpStringClient
extends HttpObjectClient

Makes HTTP requests that can be regarded as sending a string and receiving one in reply. The string may of course contain XML if desired.

Certain reasonable assumptions are made about the requests:

Both can be changed by calling "set" methods.

At present, only POST requests can be made.

See Also:
HttpStringServlet, HttpServer

Field Summary
 
Fields inherited from class ix.util.http.HttpObjectClient
connectTimeout, readTimeout, requestCharsetName, requestContentType, util
 
Constructor Summary
HttpStringClient()
           
 
Method Summary
protected  java.lang.String decodeReceived(java.lang.String contents)
          Turns response contents into an object.
protected  byte[] encodeForSend(java.lang.Object obj)
          Turns an object into request contents.
static void main(java.lang.String[] argv)
          Main program for testing.
 java.lang.String sendGetRequest(java.net.URL url)
          Send a GET request and get an object in reply.
 java.lang.String sendRequest(java.net.URL url, java.lang.Object contentsToSend)
          Send a string and receive one in reply.
 
Methods inherited from class ix.util.http.HttpObjectClient
describeResponse, handleResponseCode, handleResponseCode, mainLoop, readReply, sendBytes, setConnectTimeout, setReadTimeout, setRequestCharsetName, setRequestContentType
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HttpStringClient

public HttpStringClient()
Method Detail

sendRequest

public java.lang.String sendRequest(java.net.URL url,
                                    java.lang.Object contentsToSend)
Send a string and receive one in reply. If an object that isn't a string is given as the contents to send, it is converted to a string by calling it's toString() method.

Overrides:
sendRequest in class HttpObjectClient
See Also:
HttpObjectClient.sendGetRequest(URL)

sendGetRequest

public java.lang.String sendGetRequest(java.net.URL url)
Description copied from class: HttpObjectClient
Send a GET request and get an object in reply. The usual I-X XML syntax should be used in the reply. To send an object using a POST request, use HttpObjectClient.sendRequest(URL, Object).

Overrides:
sendGetRequest in class HttpObjectClient

encodeForSend

protected byte[] encodeForSend(java.lang.Object obj)
                        throws java.io.UnsupportedEncodingException
Description copied from class: HttpObjectClient
Turns an object into request contents.

Overrides:
encodeForSend in class HttpObjectClient
Throws:
java.io.UnsupportedEncodingException
See Also:
HttpObjectClient.decodeReceived(String contents)

decodeReceived

protected java.lang.String decodeReceived(java.lang.String contents)
Description copied from class: HttpObjectClient
Turns response contents into an object. For example, the content might be an XML representation of an object.

Overrides:
decodeReceived in class HttpObjectClient
See Also:
HttpObjectClient.encodeForSend(Object contents)

main

public static void main(java.lang.String[] argv)
                 throws java.lang.Exception
Main program for testing.

Throws:
java.lang.Exception