public class StandardHttpClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
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 BufferedStream |
reader |
protected java.lang.StringBuffer |
sb |
protected Socket |
socket |
protected java.lang.String |
uri |
Constructor and 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) |
Modifier and Type | Method and Description |
---|---|
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
|
byte[] |
executeReturnBytes(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.
|
protected java.lang.StringBuffer |
privateReadResponse()
Used internally by readResponse and readResponseBytes.
|
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.
|
protected java.lang.Object |
readResponseBytes()
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) |
protected int port
protected java.lang.String uri
protected java.lang.String host
protected java.lang.String auth
protected Socket socket
protected BufferedStream reader
protected java.lang.String hostname
public Hashtable htHeader
public boolean keepAlive
protected java.lang.StringBuffer sb
public StandardHttpClient(java.lang.String hostname, int port, java.lang.String uri, int openTimeout, int readTimeout, int writeTimeout) throws UnknownHostException, XmlRpcException
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
- XmlRpcException
- If the connection to the server could not be madeUnknownHostException
public StandardHttpClient(java.lang.String hostname, int port, java.lang.String uri) throws UnknownHostException, XmlRpcException
hostname
- The server address to connect toport
- The port on the server we want to connect touri
- The connecting URI. Defaults to "/RPC2"XmlRpcException
- If the connection to the server could not be madeUnknownHostException
public void setBasicAuthentication(java.lang.String user, java.lang.String password)
user
- The username for the server. Passing null disables
authentication.password
- The password for the username account on the server. Passing
null disables authentication.protected void writeRequest(byte[] requestBody, int len) throws IOException
IOException
public java.lang.String readLine() throws IOException
IOException
protected void checkResponse() throws XmlRpcException, IOException
IOException
XmlRpcException
protected void parseHeader() throws IOException
IOException
protected java.lang.StringBuffer privateReadResponse() throws XmlRpcException, IOException
XmlRpcException
IOException
protected java.lang.String readResponse() throws XmlRpcException, IOException
returnAsBytes
- If true, the result can be casted to byte[]
, otherwise, it can be casted to String
.IOException
XmlRpcException
protected java.lang.Object readResponseBytes() throws XmlRpcException, IOException
returnAsBytes
- If true, the result can be casted to byte[]
, otherwise, it can be casted to String
.IOException
XmlRpcException
public java.lang.String execute(byte[] requestBody) throws XmlRpcException, IOException
requestBody
- The contents of the HTTP request. Headers are added
appropriately by this methodXmlRpcException
- If the server returns a status code other than 200 OKIOException
public byte[] executeReturnBytes(byte[] requestBody) throws XmlRpcException, IOException
requestBody
- The contents of the HTTP request. Headers are added
appropriately by this methodXmlRpcException
- If the server returns a status code other than 200 OKIOException
protected void closeConnection() throws IOException
IOException
protected java.lang.StringBuffer writeRequestHeader(int requestLength)