|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.eclipse.webdav.http.client.HttpClient
public class HttpClient
An HTTP 1.0 or 1.1 client. Single instances of this client enable users to talk with multiple origin servers. Moreover, connections to origin servers are maintained for reuse.
Conveniences are provided for managing proxy servers, handling authentication, and setting up request headers.
Here is some sample code:
HttpClient client = new HttpClient();
try {
Request request = null;
Response response = null;
try {
URL resourceUrl = new URL("http://hostname/index.html");
request = new Request("GET", resourceUrl, (Context) null);
response = client.invoke(request);
System.out.print(response);
InputStream is = response.getInputStream();
int c;
while ((c = is.read()) != -1) {
System.out.print((char) c);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (request != null) {
try {
request.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (response != null) {
try {
response.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
} finally {
client.close();
}
Note: This class/interface is part of an interim API that is still under development and expected to change significantly before reaching stability. It is being made available at this early stage to solicit feedback from pioneering adopters on the understanding that any code that uses this API will almost certainly be broken (repeatedly) as the API evolves.
Nested Class Summary | |
---|---|
class |
HttpClient.ConnectionsRecycler
The ConnectionsRecycler manages a collection of
persistent HttpConnection s. |
Field Summary |
---|
Constructor Summary | |
---|---|
HttpClient()
Creates a new HttpClient . |
Method Summary | |
---|---|
void |
addProxyServerException(String pattern)
Adds the given proxy server exception pattern to this client. |
void |
close()
Closes this client. |
long |
getConnectionTimeout()
|
IContext |
getContext(URL originServerUrl)
Returns the context for the origin server at the given URL . |
IContext |
getDefaultContext()
Returns the default context. |
URL |
getDefaultProxyServerUrl()
Returns the URL of the default proxy server which is
used for all servers that do not have their proxy server set and
do not match a proxy server exception. |
double |
getHttpVersion()
Returns the version of HTTP this client uses for communication with servers. |
int |
getMaxRedirects()
Returns the maximum number of URL location redirects. |
int |
getMaxRetries()
Returns the maximum number of times a request is retried after an IOException occurs. |
Enumeration |
getOriginServerUrls()
Returns an Enumeration over the origin server
URL s known to this client. |
Enumeration |
getProxyServerExceptions()
Returns an Enumeration over this client's proxy server
exception patterns. |
URL |
getProxyServerUrl(URL originServerUrl)
Returns the URL of the proxy server that the origin
server at the given URL uses, or null if
no proxy server is used. |
int |
getSoTimeout()
Returns the socket read timeout (in milliseconds) for this client. |
Response |
invoke(Request request)
Sends the given request to the server and returns the server's response. |
void |
removeProxyServerException(String pattern)
Removes the given proxy server exception pattern from this client. |
void |
setAuthenticator(IAuthenticator authenticator)
Sets the authenticator. |
void |
setConnectionTimeout(long connectionTimeout)
|
void |
setContext(URL originServerUrl,
IContext context)
Set the context for the origin server at the given URL . |
void |
setDefaultContext(IContext context)
Sets the default context which is used by all servers that do not already have a context set. |
void |
setDefaultProxyServerUrl(URL proxyServerUrl)
Sets the URL of the default proxy server that is used by
all servers that do not have their proxy server set and do not match
a proxy server exception pattern. |
void |
setHttpVersion(double httpVersion)
Sets the version of HTTP this client uses for communication with servers. |
void |
setMaxRedirects(int maxRedirects)
Sets the maximum number of URL location redirects. |
void |
setMaxRetries(int maxRetries)
Sets the maximum number of times a request is retried after an IOException occurs. |
void |
setProxyServerUrl(URL originServerUrl,
URL proxyServerUrl)
Sets the URL of the proxy server that this client uses
to communicate with the origin server at the given URL . |
void |
setSocketFactory(ISocketFactory socketFactory)
Sets the factory that this client uses to create sockets. |
void |
setSoTimeout(int timeout)
Sets the socket read timeout (in milliseconds) for this client. |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Constructor Detail |
---|
public HttpClient()
HttpClient
.
Method Detail |
---|
public void addProxyServerException(String pattern)
pattern
- a proxy server exception pattern, for example:
"*.company.com".getDefaultProxyServerUrl()
,
getProxyServerExceptions()
,
getProxyServerUrl(URL)
,
removeProxyServerException(String)
,
setDefaultProxyServerUrl(URL)
,
setProxyServerUrl(URL, URL)
public void close()
public long getConnectionTimeout()
public IContext getContext(URL originServerUrl)
URL
.
originServerUrl
- the URL
of an origin server
URL
getDefaultContext()
,
#setDefaultContext(Context)
,
#setContext(URL, Context)
public IContext getDefaultContext()
null
.
null
getContext(URL)
,
#setContext(URL, Context)
,
#setDefaultContext(Context)
public URL getDefaultProxyServerUrl()
URL
of the default proxy server which is
used for all servers that do not have their proxy server set and
do not match a proxy server exception. If the default proxy server
URL
is null
, no default proxy server is
used. Initially the default proxy server URL
is
null
.
URL
of the default proxy server, or
null
addProxyServerException(String)
,
getProxyServerExceptions()
,
getProxyServerUrl(URL)
,
removeProxyServerException(String)
,
setDefaultProxyServerUrl(URL)
,
setProxyServerUrl(URL, URL)
public double getHttpVersion()
setHttpVersion(double)
public int getMaxRedirects()
URL
location redirects. The
maximum is 4 by default.
URL
location redirectspublic int getMaxRetries()
IOException
occurs. The maximum is 1 by default.
setMaxRetries(int)
public Enumeration getOriginServerUrls()
Enumeration
over the origin server
URL
s known to this client. The known origin server
URL
s are gleaned from this client's mapped contexts and
mapped proxy server URL
s.
Enumeration
over the origin server
URL
s known to this clientgetContext(URL)
,
#setContext(URL, Context)
,
getProxyServerUrl(URL)
,
setProxyServerUrl(URL, URL)
public Enumeration getProxyServerExceptions()
Enumeration
over this client's proxy server
exception patterns.
Enumeration
over this client's proxy server
exception patternsaddProxyServerException(String)
,
getDefaultProxyServerUrl()
,
getProxyServerUrl(URL)
,
removeProxyServerException(String)
,
setDefaultProxyServerUrl(URL)
,
setProxyServerUrl(URL, URL)
public URL getProxyServerUrl(URL originServerUrl)
URL
of the proxy server that the origin
server at the given URL
uses, or null
if
no proxy server is used.
originServerUrl
- the URL of an origin server
- Returns:
- the
URL
of a proxy server, or null
- See Also:
addProxyServerException(String)
,
getDefaultProxyServerUrl()
,
getProxyServerExceptions()
,
removeProxyServerException(String)
,
setDefaultProxyServerUrl(URL)
,
setProxyServerUrl(URL, URL)
public int getSoTimeout()
setSoTimeout(int)
public Response invoke(Request request) throws IOException
request
- the request to send to the server
IOException
- if an I/O error occurs. Reasons include:
public void removeProxyServerException(String pattern)
pattern
- a proxy server exception patternaddProxyServerException(String)
,
getDefaultProxyServerUrl()
,
getProxyServerExceptions()
,
getProxyServerUrl(URL)
,
setDefaultProxyServerUrl(URL)
,
setProxyServerUrl(URL, URL)
public void setAuthenticator(IAuthenticator authenticator)
null
protected resources cannot be
accessed. The authenticator is null
by default.
authenticator
- the authenticator, or null
public void setConnectionTimeout(long connectionTimeout)
public void setContext(URL originServerUrl, IContext context)
URL
.
If the given context is null
, the context for the
specified origin server is removed.
originServerUrl
- the URL
of an origin servercontext
- the context for the specified origin servergetContext(URL)
,
getDefaultContext()
,
#setDefaultContext(Context)
public void setDefaultContext(IContext context)
context
- the default contextgetContext(URL)
,
getDefaultContext()
,
#setContext(URL, Context)
public void setDefaultProxyServerUrl(URL proxyServerUrl)
URL
of the default proxy server that is used by
all servers that do not have their proxy server set and do not match
a proxy server exception pattern. If the given proxy server
URL
is null
, no default proxy server is
used.
proxyServerUrl
- the URL
of the default proxy serveraddProxyServerException(String)
,
getDefaultProxyServerUrl()
,
getProxyServerExceptions()
,
getProxyServerUrl(URL)
,
removeProxyServerException(String)
,
setProxyServerUrl(URL, URL)
public void setHttpVersion(double httpVersion)
httpVersion
- the version of HTTP this client uses for
communication with serversgetHttpVersion()
public void setMaxRedirects(int maxRedirects)
URL
location redirects. The
maximum is 4 by default.
maxRedirects
- the maximum number of URL
redirectspublic void setMaxRetries(int maxRetries)
IOException
occurs. The maximum is 1 by default.
maxRetries
- the maximum number of times a request is retried
after an IOException
occursgetMaxRetries()
public void setProxyServerUrl(URL originServerUrl, URL proxyServerUrl)
URL
of the proxy server that this client uses
to communicate with the origin server at the given URL
.
If the proxy server URL
is null
, the
default proxy server is used if the specified origin server does not
match a proxy server exception pattern.
originServerUrl
- the URL
of on origin serverproxyServerUrl
- the URL
of a proxy server, or
null
addProxyServerException(String)
,
getDefaultProxyServerUrl()
,
getProxyServerExceptions()
,
getProxyServerUrl(URL)
,
removeProxyServerException(String)
,
setDefaultProxyServerUrl(URL)
public void setSocketFactory(ISocketFactory socketFactory)
socketFactory
- the factory that this client uses to create
socketspublic void setSoTimeout(int timeout)
timeout
- the socket read timeoutgetSoTimeout()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |