|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.ObjectCADI.Client.Network.HTTPClient
public class HTTPClient
This class implements a HTTP client.
| Field Summary | |
|---|---|
private java.lang.String |
accept
|
private ClientSocket |
clientSocket
It is the socket that will be used to send the client request to the server and to receive the response from the server. |
static byte[] |
CRLF
Is the carriage and return line. |
private java.lang.String |
host
Is the local host name. |
static java.lang.String |
HTTP_VERSION_11
Indicates the HTTP version. |
private HTTPRequest |
httpRequest
This object contains the HTTP request to be sent. |
private static java.util.Set |
httpRequestHeaders
|
private static java.lang.String[] |
httpRequestHeadersList
Allowed HTTP headers. |
private HTTPResponse |
httpResponse
This object contains the last response that has been received. |
private static java.util.Set<java.lang.String> |
httpResponseHeaders
|
private static java.lang.String[] |
httpResponseHeadersList
Allowed HTTP response headers. |
private HTTPResponseReader |
httpResponseReader
This attribute is used to read the http response in a easy way. |
private JPIPResponseFields |
jpipResponseFields
This object contains the decoded JPIP response fields of the last response. |
private JPIPResponseFieldsParser |
jpipResponseFieldsParser
This object contains the last received JPIP fields in the HTTP response. |
private static java.util.Set<java.lang.String> |
jpipResponseHeaders
|
private static java.lang.String[] |
jpipResponseHeadersList
Allowed JPIP headers in the HTTP response. |
private boolean |
keepAlive
Indicates if http keep alive mode is set. |
private CADILog |
log
Definition in Client.log |
private static int |
MAX_ATTEMPTS
Is the maximum number of attempts to send a request or receive a response |
private static java.util.Set |
methods
|
private static java.lang.String[] |
methodsList
Allowed HTTP methods |
private java.lang.String |
userAgent
Is the client user agent. |
| Constructor Summary | |
|---|---|
HTTPClient(CADILog log)
Constructor. |
|
| Method Summary | |
|---|---|
void |
close()
|
private void |
connect(java.lang.String server,
int port,
boolean force)
This method is used to open a socket with the remote host. |
private void |
createRequest(java.lang.String server,
int port,
java.lang.String path,
java.lang.String query,
boolean absolute)
|
HTTPResponse |
getHTTPResponse()
|
private java.util.Hashtable<java.lang.String,java.lang.String> |
getHTTPResponseHeaders()
Returns the HTTP response headers without the headers added by the JPIP protocol. |
HTTPResponseReader |
getHTTPResponseReader()
Returns the http response reader object. |
JPIPResponseFields |
getJPIPResponseFields()
Returns the jpipResponseFields object. |
private java.util.Hashtable<java.lang.String,java.lang.String> |
getJPIPResponseHeaders()
Returns the HTTP response headers that belongs to the JPIP protocol. |
int |
getPort()
Definition in Socket.getPort() |
java.lang.String |
getQuery()
Returns the decoded query component of the last request. |
java.lang.String |
getRemoteHost()
Definition in ClientSocket.getRemoteHost(). |
java.lang.String |
getRequestURI()
Returns the last requested URI. |
java.lang.String |
getResponseMessage()
Definition in HTTPResponse.getResponseMessage(). |
int |
getStatusCode()
Definition in HTTPResponse.getResponseCode(). |
boolean |
isKeepAlive()
Returns whether the HTTP keep alive feature is or not set. |
boolean |
isResponseBody()
Check if the HTTP response has a body or not. |
void |
list(java.io.PrintStream out)
Prints this HTTP Client out to the specified output stream. |
private void |
parseHTTPResponseHeaders(java.util.Hashtable<java.lang.String,java.lang.String> httpHeaders)
|
private void |
parseStatusLine(java.lang.String statusLine)
Parses the status line of the HTTP response. |
private void |
readResponseHeader(HTTPResponseReader httpResponseReader)
Decodes a http response which is recieved in the inputStream. |
void |
sendRequest(HTTPRequest httpRequest)
|
private void |
sendRequest(java.io.OutputStream os)
Sends the HTTP request through the output stream. |
private void |
sendRequest(java.io.OutputStream os,
HTTPRequest httpRequest)
Sends the HTTP request through the output stream. |
void |
sendRequest(java.lang.String requestURI)
|
void |
sendRequest(java.lang.String server,
int port,
HTTPRequest httpRequest)
|
void |
sendRequest(java.lang.String server,
int port,
HTTPRequest httpRequest,
java.lang.String proxyServer,
int proxyPort)
|
void |
sendRequest(java.lang.String server,
int port,
java.lang.String requestURI)
Sends a request URI to the server. |
void |
sendRequest(java.lang.String server,
int port,
java.lang.String requestURI,
java.lang.String proxyServer,
int proxyPort)
Sends a request URI to the server. |
void |
sendRequest(java.lang.String requestURI,
java.lang.String proxyServer,
int proxyPort)
Sends a request URI to the server. |
void |
setAccept(java.lang.String accept)
|
void |
setKeepAlive(boolean keepAlive)
Sets the HTTP keep alive feature. |
void |
setLocalHost(java.lang.String host)
Sets the client host name. |
private void |
setRequestMethod(java.lang.String method)
Sets the method that will be used to send the HTTP request. |
void |
setUserAgent(java.lang.String userAgent)
Sets the user agent name. |
java.lang.String |
toString()
For debugging purpose |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
|---|
private HTTPResponseReader httpResponseReader
private JPIPResponseFields jpipResponseFields
private boolean keepAlive
private java.lang.String host
private java.lang.String userAgent
private java.lang.String accept
private CADILog log
Client.log
private ClientSocket clientSocket
private static final int MAX_ATTEMPTS
public static final java.lang.String HTTP_VERSION_11
public static final byte[] CRLF
private HTTPRequest httpRequest
private static final java.lang.String[] methodsList
private static final java.util.Set methods
private static final java.lang.String[] httpRequestHeadersList
private static final java.util.Set httpRequestHeaders
httpRequestHeadersListprivate HTTPResponse httpResponse
HTTPResponseprivate JPIPResponseFieldsParser jpipResponseFieldsParser
private static final java.lang.String[] httpResponseHeadersList
NOTICE: The extended HTTP response headers to support the JPIP protocol are not included.
private static final java.util.Set<java.lang.String> httpResponseHeaders
httpResponseHeadersListprivate static final java.lang.String[] jpipResponseHeadersList
httpResponseHeadersprivate static final java.util.Set<java.lang.String> jpipResponseHeaders
jpipResponseHeadersList| Constructor Detail |
|---|
public HTTPClient(CADILog log)
| Method Detail |
|---|
public void sendRequest(java.lang.String requestURI)
throws java.io.IOException,
WarningException
requestURI -
java.io.IOException
WarningException
public void sendRequest(java.lang.String requestURI,
java.lang.String proxyServer,
int proxyPort)
throws java.io.IOException,
WarningException
requestURI - the request to send.
WarningException
java.io.IOExceptionsendRequest(String, int, String)
public void sendRequest(java.lang.String server,
int port,
java.lang.String requestURI)
throws java.io.IOException,
WarningException
server and port
parameters. Otherwise, a IllegalArgumentException
will be thrown.
The server and port parameters are optionals
when the requestURI is an absolute URI.
server - the name of the remote host.port - the port number on the remote host.requestURI - the request URI to send.
WarningException
java.io.IOExceptionsendRequest(String)
public void sendRequest(java.lang.String server,
int port,
java.lang.String requestURI,
java.lang.String proxyServer,
int proxyPort)
throws java.io.IOException,
WarningException
server and port
parameters. Otherwise, a IllegalArgumentException
will be thrown.
The server and port parameters are optionals
when the requestURI is an absolute URI.
server - the name of the remote host.port - the port number on the remote host.requestURI - the request URI to send.proxyServer - is the proxy server used to connect to the JPIP serverproxyPort - is the port in the proxy server
WarningException
java.io.IOExceptionsendRequest(String)
public void sendRequest(HTTPRequest httpRequest)
throws java.io.IOException,
WarningException
httpRequest -
java.io.IOException
WarningException
public void sendRequest(java.lang.String server,
int port,
HTTPRequest httpRequest)
throws java.io.IOException,
WarningException
server - port - httpRequest -
java.io.IOException
WarningException
public void sendRequest(java.lang.String server,
int port,
HTTPRequest httpRequest,
java.lang.String proxyServer,
int proxyPort)
throws java.io.IOException,
WarningException
server - port - httpRequest - proxyServer - proxyPort -
java.io.IOException
WarningExceptionpublic HTTPResponseReader getHTTPResponseReader()
HTTPResponseReaderpublic int getStatusCode()
HTTPResponse.getResponseCode().
public java.lang.String getResponseMessage()
HTTPResponse.getResponseMessage().
public HTTPResponse getHTTPResponse()
public JPIPResponseFields getJPIPResponseFields()
jpipResponseFields object.
jpipResponseFields object.public void setKeepAlive(boolean keepAlive)
keepAlive - if true the HTTP keep alive feature is set.
Otherwise, it is not set.public boolean isKeepAlive()
public void setUserAgent(java.lang.String userAgent)
userAgent - user agent name.public void setAccept(java.lang.String accept)
accept - public java.lang.String getRequestURI()
public java.lang.String getQuery()
public void setLocalHost(java.lang.String host)
host - the client host name.public java.lang.String getRemoteHost()
ClientSocket.getRemoteHost().
public int getPort()
Socket.getPort()
public boolean isResponseBody()
true whether HTTP response has a body. Otherwise,
returns false.public void close()
public java.lang.String toString()
toString in class java.lang.Objectpublic void list(java.io.PrintStream out)
out - an output stream.
private void connect(java.lang.String server,
int port,
boolean force)
throws java.io.IOException
server - port - force -
java.io.IOException
private void setRequestMethod(java.lang.String method)
throws java.net.ProtocolException
method - definition in HTTPRequest.method.
java.net.ProtocolException - if an error in the underlying protocol has
occurred.
private void createRequest(java.lang.String server,
int port,
java.lang.String path,
java.lang.String query,
boolean absolute)
server - port - path - query - absolute -
private void sendRequest(java.io.OutputStream os)
throws java.io.IOException
os - the output stream
java.io.IOException
private void sendRequest(java.io.OutputStream os,
HTTPRequest httpRequest)
throws java.io.IOException
os - the output streamhttpRequest -
java.io.IOException
private void readResponseHeader(HTTPResponseReader httpResponseReader)
throws WarningException,
java.io.IOException
httpResponseReader - definition in httpResponseReader.
WarningException - if an error is found while http response is
being decoded.
java.io.IOException - if there is none data to read from the input stream.
It might be because input stream is closed by remote host.
private void parseStatusLine(java.lang.String statusLine)
throws java.net.ProtocolException,
WarningException
statusLine - the status line of the HTTP response.
java.net.ProtocolException
WarningException
private void parseHTTPResponseHeaders(java.util.Hashtable<java.lang.String,java.lang.String> httpHeaders)
throws java.net.ProtocolException,
WarningException
httpHeaders -
java.net.ProtocolException
WarningExceptionprivate java.util.Hashtable<java.lang.String,java.lang.String> getHTTPResponseHeaders()
private java.util.Hashtable<java.lang.String,java.lang.String> getJPIPResponseHeaders()
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||