public class HTTPClient
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.ArrayList<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 |
debug
Is a feature whose content is not defined.
|
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 |
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 |
static java.lang.String[] |
methodsList
Allowed HTTP methods
|
private java.lang.String |
userAgent
Is the client user agent.
|
private java.lang.String |
via |
Constructor and Description |
---|
HTTPClient(java.lang.String host,
boolean keepAlive,
CADILog log)
Constructor.
|
HTTPClient(java.lang.String host,
java.lang.String userAgent,
boolean keepAlive,
CADILog log)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
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) |
HTTPRequest |
getHTTPRequest()
Returns the
httpRequest attribute. |
HTTPResponse |
getHTTPResponse() |
private java.util.HashMap<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.HashMap<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.HashMap<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.util.ArrayList<java.lang.String> accept) |
void |
setDebug(java.lang.String debug)
Sets the debug feature.
|
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.
|
void |
setVia(java.lang.String via)
Sets the
via attribute. |
java.lang.String |
toString()
For debugging purpose
|
private HTTPResponseReader httpResponseReader
private JPIPResponseFields jpipResponseFields
private boolean keepAlive
private java.lang.String host
private java.lang.String userAgent
private java.lang.String debug
private java.lang.String via
private java.util.ArrayList<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
public static final java.lang.String[] methodsList
private static final java.util.Set methods
public static final java.lang.String[] httpRequestHeadersList
private static final java.util.Set httpRequestHeaders
httpRequestHeadersList
private HTTPResponse httpResponse
HTTPResponse
private 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
httpResponseHeadersList
private static final java.lang.String[] jpipResponseHeadersList
httpResponseHeaders
private static final java.util.Set<java.lang.String> jpipResponseHeaders
jpipResponseHeadersList
public HTTPClient(java.lang.String host, boolean keepAlive, CADILog log)
keepAlive
- log
- public HTTPClient(java.lang.String host, java.lang.String userAgent, boolean keepAlive, CADILog log)
keepAlive
- log
- 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.IOException
sendRequest(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.IOException
sendRequest(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 serverWarningException
java.io.IOException
sendRequest(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
WarningException
public HTTPRequest getHTTPRequest()
httpRequest
attribute.httpRequest
.public HTTPResponseReader getHTTPResponseReader()
HTTPResponseReader
public 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 setDebug(java.lang.String debug)
debug
- public void setVia(java.lang.String via)
via
attribute.via
- definition in via
.public void setAccept(java.util.ArrayList<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.Object
public 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 streamjava.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.HashMap<java.lang.String,java.lang.String> httpHeaders) throws java.net.ProtocolException, WarningException
httpHeaders
- java.net.ProtocolException
WarningException
private java.util.HashMap<java.lang.String,java.lang.String> getHTTPResponseHeaders()
private java.util.HashMap<java.lang.String,java.lang.String> getJPIPResponseHeaders()
CADI - Copyright (C) 2007
This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Group on Interactive Coding of Images (GICI) (contact)