|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectix.util.http.HttpObjectClient
public class HttpObjectClient
Makes HTTP requests that can be regarded as sending an object and receiving one in reply. The usual I-X XML encoding is used; however, it's possible to change that in a subclass.
Certain reasonable assumptions are made about the requests:
Connect and read timeouts may also be set.
Both POST and GET requests can be made.
HttpObjectServlet,
HttpServer,
XMLTranslator| Field Summary | |
|---|---|
protected int |
connectTimeout
|
protected int |
readTimeout
|
protected java.lang.String |
requestCharsetName
|
protected java.lang.String |
requestContentType
|
protected HttpUtilities |
util
|
| Constructor Summary | |
|---|---|
HttpObjectClient()
|
|
| Method Summary | |
|---|---|
protected java.lang.Object |
decodeReceived(java.lang.String contents)
Turns response contents into an object. |
protected void |
describeResponse(java.net.HttpURLConnection conn)
Utility method that produces debugging output that describes the response. |
protected byte[] |
encodeForSend(java.lang.Object contents)
Turns an object into request contents. |
protected boolean |
handleResponseCode(java.net.HttpURLConnection conn)
Checks whether the response is a success or a failure and whether there's content to be read. |
protected boolean |
handleResponseCode(int status,
java.lang.String message)
Checks whether the response is a success or a failure and whether there's content to be read. |
static void |
main(java.lang.String[] argv)
Main program for testing. |
protected static void |
mainLoop(java.lang.String[] argv,
HttpObjectClient http,
Fn1<java.lang.String,java.lang.Object> preprocess)
|
protected java.lang.String |
readReply(java.net.HttpURLConnection conn)
Utility method that reads a reply from the connection and returns it as a String. |
protected void |
sendBytes(byte[] bytes,
java.net.URL url,
java.net.HttpURLConnection conn)
Utility method that writes bytes to an HttpURLConnection. |
java.lang.Object |
sendGetRequest(java.net.URL url)
Send a GET request and get an object in reply. |
java.lang.Object |
sendRequest(java.net.URL url,
java.lang.Object contentsToSend)
Send an object and receive one in reply. |
void |
setConnectTimeout(int milliseconds)
Sets the timeout in millisecond for opening a communications link when sending a request. |
void |
setReadTimeout(int milliseconds)
Sets the timeout in millisecond for reading a response. |
void |
setRequestCharsetName(java.lang.String name)
Set the character set used when sending requests. |
void |
setRequestContentType(java.lang.String type)
Set the Content-Type used when sending requests. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected HttpUtilities util
protected java.lang.String requestContentType
protected java.lang.String requestCharsetName
protected int connectTimeout
protected int readTimeout
| Constructor Detail |
|---|
public HttpObjectClient()
| Method Detail |
|---|
public void setRequestContentType(java.lang.String type)
public void setRequestCharsetName(java.lang.String name)
public void setConnectTimeout(int milliseconds)
public void setReadTimeout(int milliseconds)
public java.lang.Object sendRequest(java.net.URL url,
java.lang.Object contentsToSend)
throws RethrownIOException
RethrownIOExceptionsendGetRequest(URL)
protected byte[] encodeForSend(java.lang.Object contents)
throws java.io.UnsupportedEncodingException
java.io.UnsupportedEncodingExceptiondecodeReceived(String contents)
protected void sendBytes(byte[] bytes,
java.net.URL url,
java.net.HttpURLConnection conn)
throws java.io.IOException
java.io.IOException
public java.lang.Object sendGetRequest(java.net.URL url)
throws RethrownIOException
sendRequest(URL, Object).
RethrownIOException
protected void describeResponse(java.net.HttpURLConnection conn)
throws java.io.IOException
java.io.IOException
protected boolean handleResponseCode(java.net.HttpURLConnection conn)
throws HttpRequestException,
java.io.IOException
handleResponseCode(int status, String message).
HttpRequestException
java.io.IOException
protected boolean handleResponseCode(int status,
java.lang.String message)
throws HttpRequestException
HttpRequestException; otherwise,
the true/false result indicates whether there's content
to be read or not. It's possible to have a successful
request that does not return any content; normally, the
response code is then NO_CONTENT (204).
As defined in the HttpObjectClient class, this method returns true if the status is HTTP_OK and throws an HttpRequestException if it isn't. Subclasses should override this method if they want to accept anything other than HTTP_OK or if they want to return false in some case.
HttpRequestException - for more serious failures.
protected java.lang.String readReply(java.net.HttpURLConnection conn)
throws java.io.EOFException,
java.io.IOException
java.io.EOFException
java.io.IOExceptionprotected java.lang.Object decodeReceived(java.lang.String contents)
encodeForSend(Object contents)
public static void main(java.lang.String[] argv)
throws java.lang.Exception
java.lang.Exception
protected static void mainLoop(java.lang.String[] argv,
HttpObjectClient http,
Fn1<java.lang.String,java.lang.Object> preprocess)
throws java.lang.Exception
java.lang.Exception
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||