superwaba.ext.xplat.webservice
Class StandardHttpClient

java.lang.Object
  |
  +--superwaba.ext.xplat.webservice.StandardHttpClient
Direct Known Subclasses:
CompressedHttpClient

public class StandardHttpClient
extends java.lang.Object

Provides client-side HTTP communication


Field Summary
protected  java.lang.String auth
           
protected  java.lang.String host
           
protected  java.lang.String hostname
           
 Hashtable htHeader
          The header contents, with both key and value lowercased.
 boolean keepAlive
          Sets the keep-alive flag.
protected  int port
           
protected static java.lang.StringBuffer sb
           
protected  Socket socket
           
protected  java.lang.String uri
           
 
Constructor Summary
StandardHttpClient(java.lang.String hostname, int port, java.lang.String uri)
           
 
Method Summary
protected  void checkResponse()
          Checks if the response of the server has status 200
protected  void closeConnection()
          Terminates the server connection
 java.lang.String execute(byte[] requestBody)
          Executes a HTTP request to the connected server
protected  void parseHeader()
          Places all the returning values frm the header in a hashtable for easy access.
 java.lang.String readLine()
          Reads a line from the socket, retrying up to four times, with a 250ms delay between the tries.
protected  java.lang.String readResponse()
          Reads all the lines and place them in a single contiguous String.
 void setBasicAuthentication(java.lang.String user, java.lang.String password)
          Base64 encodes the username and password given for basic server authentication
protected  void writeRequest(byte[] requestBody, int len)
          Writes the header followed by the given request body
protected  java.lang.StringBuffer writeRequestHeader(int requestLength)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

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

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 static java.lang.StringBuffer sb
Constructor Detail

StandardHttpClient

public StandardHttpClient(java.lang.String hostname,
                          int port,
                          java.lang.String uri)
                   throws XmlRpcException
Parameters:
hostname - The server address to connect to
port - The port on the server we want to connect to
uri - The connecting URI. Defaults to "/RPC2"
Throws:
XmlRpcException - If the connection to the server could not be made
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)
Writes the header followed by the given request body

readLine

public java.lang.String readLine()
Reads a line from the socket, retrying up to four times, with a 250ms delay between the tries.
Since:
SuperWaba 5.68

checkResponse

protected void checkResponse()
                      throws XmlRpcException
Checks if the response of the server has status 200

parseHeader

protected void parseHeader()
Places all the returning values frm the header in a hashtable for easy access. Already parses the keepAlive flag.

readResponse

protected java.lang.String readResponse()
                                 throws XmlRpcException
Reads all the lines and place them in a single contiguous String.

execute

public java.lang.String execute(byte[] requestBody)
                         throws XmlRpcException
Executes 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 OK

closeConnection

protected void closeConnection()
Terminates the server connection

writeRequestHeader

protected java.lang.StringBuffer writeRequestHeader(int requestLength)