Package totalcross.xml.rpc
Class StandardHttpClient
- java.lang.Object
-
- totalcross.xml.rpc.StandardHttpClient
-
- Direct Known Subclasses:
CompressedHttpClient
public class StandardHttpClient extends java.lang.ObjectProvides client-side HTTP communication
-
-
Field Summary
Fields Modifier and Type Field Description protected java.lang.Stringauthprotected java.lang.Stringhostprotected java.lang.StringhostnameHashtablehtHeaderThe header contents, with both key and value lowercased.booleankeepAliveSets the keep-alive flag.protected intportprotected BufferedStreamreaderprotected java.lang.StringBuffersbprotected Socketsocketprotected java.lang.Stringuri
-
Constructor Summary
Constructors Constructor Description StandardHttpClient(java.lang.String hostname, int port, java.lang.String uri)StandardHttpClient(java.lang.String hostname, int port, java.lang.String uri, int openTimeout, int readTimeout, int writeTimeout)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcheckResponse()Checks if the response of the server has status 200protected voidcloseConnection()Terminates the server connectionjava.lang.Stringexecute(byte[] requestBody)Executes a HTTP request to the connected serverbyte[]executeReturnBytes(byte[] requestBody)Executes a HTTP request to the connected server.protected voidparseHeader()Places all the returning values frm the header in a hashtable for easy access.protected java.lang.StringBufferprivateReadResponse()Used internally by readResponse and readResponseBytes.java.lang.StringreadLine()Reads a line from the socket, retrying up to four times, with a 250ms delay between the tries.protected java.lang.StringreadResponse()Reads all the lines and place them in a single contiguous String.protected java.lang.ObjectreadResponseBytes()Reads all the lines and place them in a single contiguous String.voidsetBasicAuthentication(java.lang.String user, java.lang.String password)Base64 encodes the username and password given for basic server authenticationprotected voidwriteRequest(byte[] requestBody, int len)Writes the header followed by the given request bodyprotected java.lang.StringBufferwriteRequestHeader(int requestLength)
-
-
-
Field Detail
-
port
protected int port
-
uri
protected java.lang.String uri
-
host
protected java.lang.String host
-
auth
protected java.lang.String auth
-
socket
protected Socket socket
-
reader
protected BufferedStream reader
-
hostname
protected java.lang.String hostname
-
htHeader
public Hashtable htHeader
The header contents, with both key and value lowercased.
-
keepAlive
public boolean keepAlive
Sets the keep-alive flag. If this is false, the connection to the server will be closed at each execution.
-
sb
protected java.lang.StringBuffer sb
-
-
Constructor Detail
-
StandardHttpClient
public StandardHttpClient(java.lang.String hostname, int port, java.lang.String uri, int openTimeout, int readTimeout, int writeTimeout) throws UnknownHostException, XmlRpcException- Parameters:
hostname- The server address to connect toport- The port on the server we want to connect touri- The connecting URI. Defaults to "/RPC2"openTimeout-readTimeout-writeTimeout-- Throws:
XmlRpcException- If the connection to the server could not be madeUnknownHostException
-
StandardHttpClient
public StandardHttpClient(java.lang.String hostname, int port, java.lang.String uri) throws UnknownHostException, XmlRpcException- Parameters:
hostname- The server address to connect toport- The port on the server we want to connect touri- The connecting URI. Defaults to "/RPC2"- Throws:
XmlRpcException- If the connection to the server could not be madeUnknownHostException
-
-
Method Detail
-
setBasicAuthentication
public void setBasicAuthentication(java.lang.String user, java.lang.String password)Base64 encodes the username and password given for basic server authentication- Parameters:
user- The username for the server. Passing null disables authentication.password- The password for the username account on the server. Passing null disables authentication.
-
writeRequest
protected void writeRequest(byte[] requestBody, int len) throws IOExceptionWrites the header followed by the given request body- Throws:
IOException
-
readLine
public java.lang.String readLine() throws IOExceptionReads a line from the socket, retrying up to four times, with a 250ms delay between the tries.- Throws:
IOException- Since:
- SuperWaba 5.68
-
checkResponse
protected void checkResponse() throws XmlRpcException, IOExceptionChecks if the response of the server has status 200- Throws:
IOExceptionXmlRpcException
-
parseHeader
protected void parseHeader() throws IOExceptionPlaces all the returning values frm the header in a hashtable for easy access. Already parses the keepAlive flag.- Throws:
IOException
-
privateReadResponse
protected java.lang.StringBuffer privateReadResponse() throws XmlRpcException, IOExceptionUsed internally by readResponse and readResponseBytes.- Throws:
XmlRpcExceptionIOException
-
readResponse
protected java.lang.String readResponse() throws XmlRpcException, IOExceptionReads all the lines and place them in a single contiguous String.- Parameters:
returnAsBytes- If true, the result can be casted tobyte[], otherwise, it can be casted toString.- Throws:
IOExceptionXmlRpcException
-
readResponseBytes
protected java.lang.Object readResponseBytes() throws XmlRpcException, IOExceptionReads all the lines and place them in a single contiguous String.- Parameters:
returnAsBytes- If true, the result can be casted tobyte[], otherwise, it can be casted toString.- Throws:
IOExceptionXmlRpcException
-
execute
public java.lang.String execute(byte[] requestBody) throws XmlRpcException, IOExceptionExecutes a HTTP request to the connected server- Parameters:
requestBody- The contents of the HTTP request. Headers are added appropriately by this method- Throws:
XmlRpcException- If the server returns a status code other than 200 OKIOException
-
executeReturnBytes
public byte[] executeReturnBytes(byte[] requestBody) throws XmlRpcException, IOExceptionExecutes a HTTP request to the connected server.- Parameters:
requestBody- The contents of the HTTP request. Headers are added appropriately by this method- Throws:
XmlRpcException- If the server returns a status code other than 200 OKIOException- Since:
- TotalCross 1.23
-
closeConnection
protected void closeConnection() throws IOExceptionTerminates the server connection- Throws:
IOException
-
writeRequestHeader
protected java.lang.StringBuffer writeRequestHeader(int requestLength)
-
-