public class HttpClient extends java.lang.Object implements java.io.Closeable, URLConnector
| Modifier and Type | Field and Description |
|---|---|
private URLCache |
cache |
private static JSONCodec |
codec |
private java.util.List<URLConnectionHandler> |
connectionHandlers |
private static java.lang.ThreadLocal<java.text.DateFormat> |
HTTP_DATE_FORMATTER |
private static int |
HTTP_PERMANENT_REDIRECT |
private static int |
HTTP_TEMPORARY_REDIRECT |
private boolean |
inited |
private static org.slf4j.Logger |
logger |
private java.util.concurrent.atomic.AtomicBoolean |
offline |
private java.lang.ThreadLocal<java.net.PasswordAuthentication> |
passwordAuthentication |
private java.util.List<ProxyHandler> |
proxyHandlers |
private Registry |
registry |
private Reporter |
reporter |
static java.text.SimpleDateFormat |
sdf |
| Constructor and Description |
|---|
HttpClient() |
| Modifier and Type | Method and Description |
|---|---|
void |
addProxyHandler(ProxyHandler proxyHandler) |
void |
addURLConnectionHandler(URLConnectionHandler handler) |
HttpRequest<java.lang.Object> |
build() |
void |
close() |
private void |
configureHttpConnection(java.lang.String verb,
java.net.HttpURLConnection hcon) |
java.io.InputStream |
connect(java.net.URL url)
Connect to the specified URL.
|
TaggedData |
connectTagged(java.net.URL url)
Connect to the specified URL, also returning the ETag if available.
|
TaggedData |
connectTagged(java.net.URL url,
java.lang.String tag)
Connect to the specified URL while providing the last known tag for the
remote resource; the response will be
null if the remote resource
is unchanged. |
<T> T |
connectWithProxy(ProxyHandler.ProxySetup proxySetup,
java.util.concurrent.Callable<T> r) |
private java.lang.Object |
convert(java.lang.reflect.Type type,
java.io.File in,
TaggedData tag) |
private java.lang.Object |
convert(java.lang.reflect.Type ref,
java.io.InputStream in) |
private java.io.InputStream |
createProgressWrappedStream(java.io.InputStream inputStream,
java.lang.String name,
int size,
ProgressPlugin.Task task,
long timeout) |
(package private) java.lang.Object |
doCached(HttpRequest<?> request) |
(package private) TaggedData |
doCached0(HttpRequest<?> request) |
private TaggedData |
doConnect(java.lang.Object put,
java.lang.reflect.Type ref,
java.net.URLConnection con,
java.net.HttpURLConnection hcon,
HttpRequest<?> request,
ProgressPlugin.Task task) |
private void |
doOutput(java.lang.Object put,
java.net.URLConnection con,
HttpRequest<?> rq) |
private java.lang.String |
entitytag(java.lang.String entity) |
URLConnectionHandler |
findMatchingHandler(java.net.URL url) |
java.io.File |
getCacheFileFor(java.net.URI url) |
private java.net.URLConnection |
getProxiedAndConfiguredConnection(java.net.URL url,
ProxyHandler.ProxySetup proxy) |
private java.util.Collection<? extends ProxyHandler> |
getProxyHandlers() |
ProxyHandler.ProxySetup |
getProxySetup(java.net.URL url) |
Reporter |
getReporter() |
(package private) ProgressPlugin.Task |
getTask(HttpRequest<?> request) |
private java.util.Collection<? extends URLConnectionHandler> |
getURLConnectionHandlers() |
java.lang.String |
getUserFor(java.lang.String base) |
private java.io.InputStream |
handleContentEncoding(java.net.HttpURLConnection con,
java.io.InputStream in) |
private static java.text.DateFormat |
httpDateFormat() |
(package private) void |
init() |
boolean |
isOffline() |
(package private) boolean |
isUpdateInfo(java.net.URLConnection con,
HttpRequest<?> request,
int code) |
java.net.URI |
makeDir(java.net.URI uri) |
void |
readSettings(Processor processor) |
java.lang.Object |
send(HttpRequest<?> request) |
TaggedData |
send0(HttpRequest<?> request) |
void |
setCache(java.io.File cache) |
private void |
setHeaders(java.util.Map<java.lang.String,java.lang.String> headers,
java.net.URLConnection con) |
void |
setLog(java.io.File log) |
void |
setOffline(java.util.concurrent.atomic.AtomicBoolean offline) |
void |
setRegistry(Registry registry) |
void |
setReporter(Reporter reporter) |
java.lang.String |
toName(java.net.URI url) |
private static final org.slf4j.Logger logger
public static final java.text.SimpleDateFormat sdf
private static final java.lang.ThreadLocal<java.text.DateFormat> HTTP_DATE_FORMATTER
private static final int HTTP_TEMPORARY_REDIRECT
private static final int HTTP_PERMANENT_REDIRECT
private final java.util.List<ProxyHandler> proxyHandlers
private final java.util.List<URLConnectionHandler> connectionHandlers
private java.lang.ThreadLocal<java.net.PasswordAuthentication> passwordAuthentication
private boolean inited
private static JSONCodec codec
private URLCache cache
private Registry registry
private Reporter reporter
private volatile java.util.concurrent.atomic.AtomicBoolean offline
void init()
private static java.text.DateFormat httpDateFormat()
public void close()
close in interface java.io.Closeableclose in interface java.lang.AutoCloseablepublic java.io.InputStream connect(java.net.URL url)
throws java.lang.Exception
URLConnectorconnect in interface URLConnectorjava.io.IOExceptionjava.lang.Exceptionpublic TaggedData connectTagged(java.net.URL url) throws java.lang.Exception
URLConnectorconnectTagged in interface URLConnectorurl - The remote URL.TaggedData; note that the
TaggedData.getTag() method may return
null if the resource has no tag.java.io.IOException - @since 1.1java.lang.Exceptionpublic TaggedData connectTagged(java.net.URL url, java.lang.String tag) throws java.lang.Exception
URLConnectornull if the remote resource
is unchanged.connectTagged in interface URLConnectorurl - The remote URL.tag - The last known tag value for the resource.TaggedData, or null if the
resource has not modified (i.e., if it has the same tag value).java.io.IOException - @since 1.1java.lang.Exceptionpublic HttpRequest<java.lang.Object> build()
public java.lang.Object send(HttpRequest<?> request) throws java.lang.Exception
java.lang.Exceptionjava.lang.Object doCached(HttpRequest<?> request) throws java.lang.Exception, java.io.IOException
java.lang.Exceptionjava.io.IOExceptionTaggedData doCached0(HttpRequest<?> request) throws java.lang.Exception, java.io.IOException
java.lang.Exceptionjava.io.IOExceptionpublic TaggedData send0(HttpRequest<?> request) throws java.lang.Exception
java.lang.ExceptionProgressPlugin.Task getTask(HttpRequest<?> request)
private java.lang.String entitytag(java.lang.String entity)
public ProxyHandler.ProxySetup getProxySetup(java.net.URL url) throws java.lang.Exception
java.lang.Exceptionpublic <T> T connectWithProxy(ProxyHandler.ProxySetup proxySetup, java.util.concurrent.Callable<T> r) throws java.lang.Exception
java.lang.Exceptionprivate java.net.URLConnection getProxiedAndConfiguredConnection(java.net.URL url,
ProxyHandler.ProxySetup proxy)
throws java.io.IOException,
java.lang.Exception
java.io.IOExceptionjava.lang.Exceptionpublic URLConnectionHandler findMatchingHandler(java.net.URL url) throws java.lang.Exception
java.lang.Exceptionprivate java.util.Collection<? extends URLConnectionHandler> getURLConnectionHandlers() throws java.lang.Exception
java.lang.Exceptionprivate java.util.Collection<? extends ProxyHandler> getProxyHandlers() throws java.lang.Exception
java.lang.Exceptionprivate java.io.InputStream createProgressWrappedStream(java.io.InputStream inputStream,
java.lang.String name,
int size,
ProgressPlugin.Task task,
long timeout)
private TaggedData doConnect(java.lang.Object put, java.lang.reflect.Type ref, java.net.URLConnection con, java.net.HttpURLConnection hcon, HttpRequest<?> request, ProgressPlugin.Task task) throws java.io.IOException, java.lang.Exception
java.io.IOExceptionjava.lang.Exceptionboolean isUpdateInfo(java.net.URLConnection con,
HttpRequest<?> request,
int code)
private java.lang.Object convert(java.lang.reflect.Type type,
java.io.File in,
TaggedData tag)
throws java.io.IOException,
java.lang.Exception
java.io.IOExceptionjava.lang.Exceptionprivate java.lang.Object convert(java.lang.reflect.Type ref,
java.io.InputStream in)
throws java.io.IOException,
java.lang.Exception
java.io.IOExceptionjava.lang.Exceptionprivate java.io.InputStream handleContentEncoding(java.net.HttpURLConnection con,
java.io.InputStream in)
throws java.io.IOException
java.io.IOExceptionprivate void doOutput(java.lang.Object put,
java.net.URLConnection con,
HttpRequest<?> rq)
throws java.io.IOException,
java.lang.Exception
java.io.IOExceptionjava.lang.Exceptionprivate void configureHttpConnection(java.lang.String verb,
java.net.HttpURLConnection hcon)
throws java.net.ProtocolException
java.net.ProtocolExceptionprivate void setHeaders(java.util.Map<java.lang.String,java.lang.String> headers,
java.net.URLConnection con)
public void setCache(java.io.File cache)
public void setReporter(Reporter reporter)
public void setRegistry(Registry registry)
public void addURLConnectionHandler(URLConnectionHandler handler)
public Reporter getReporter()
public void addProxyHandler(ProxyHandler proxyHandler)
public void setLog(java.io.File log)
throws java.io.IOException
java.io.IOExceptionpublic java.lang.String getUserFor(java.lang.String base)
throws java.net.MalformedURLException,
java.lang.Exception
java.net.MalformedURLExceptionjava.lang.Exceptionpublic java.lang.String toName(java.net.URI url)
throws java.lang.Exception
java.lang.Exceptionpublic java.io.File getCacheFileFor(java.net.URI url)
throws java.lang.Exception
java.lang.Exceptionpublic void readSettings(Processor processor) throws java.io.IOException, java.lang.Exception
java.io.IOExceptionjava.lang.Exceptionpublic java.net.URI makeDir(java.net.URI uri)
throws java.net.URISyntaxException
java.net.URISyntaxExceptionpublic boolean isOffline()
public void setOffline(java.util.concurrent.atomic.AtomicBoolean offline)