Package aQute.bnd.http
Class HttpClient
- java.lang.Object
-
- aQute.bnd.http.HttpClient
-
- All Implemented Interfaces:
URLConnector
,java.io.Closeable
,java.lang.AutoCloseable
public class HttpClient extends java.lang.Object implements java.io.Closeable, URLConnector
A simple Http Client that inter-works with the bnd registry. It provides an easy way to construct a URL request. The request is then decorated with third parties that are in the bnd registry for proxies and authentication models.
-
-
Field Summary
Fields Modifier and Type Field Description static java.text.SimpleDateFormat
sdf
-
Constructor Summary
Constructors Constructor Description HttpClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addProxyHandler(ProxyHandler proxyHandler)
void
addURLConnectionHandler(URLConnectionHandler handler)
HttpRequest<java.lang.Object>
build()
void
close()
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 benull
if the remote resource is unchanged.<T> T
connectWithProxy(ProxyHandler.ProxySetup proxySetup, java.util.concurrent.Callable<T> r)
URLConnectionHandler
findMatchingHandler(java.net.URL url)
java.io.File
getCacheFileFor(java.net.URI url)
ProxyHandler.ProxySetup
getProxySetup(java.net.URL url)
aQute.service.reporter.Reporter
getReporter()
java.lang.String
getUserFor(java.lang.String base)
boolean
isOffline()
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)
void
setLog(java.io.File log)
void
setOffline(java.util.concurrent.atomic.AtomicBoolean offline)
void
setRegistry(Registry registry)
void
setReporter(aQute.service.reporter.Reporter reporter)
java.lang.String
toName(java.net.URI url)
-
-
-
Method Detail
-
close
public void close()
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
-
connect
public java.io.InputStream connect(java.net.URL url) throws java.lang.Exception
Description copied from interface:URLConnector
Connect to the specified URL.- Specified by:
connect
in interfaceURLConnector
- Throws:
java.io.IOException
java.lang.Exception
-
connectTagged
public TaggedData connectTagged(java.net.URL url) throws java.lang.Exception
Description copied from interface:URLConnector
Connect to the specified URL, also returning the ETag if available.- Specified by:
connectTagged
in interfaceURLConnector
- Parameters:
url
- The remote URL.- Returns:
- An instance of
TaggedData
; note that theTaggedData.getTag()
method may returnnull
if the resource has no tag. - Throws:
java.io.IOException
- @since 1.1java.lang.Exception
-
connectTagged
public TaggedData connectTagged(java.net.URL url, java.lang.String tag) throws java.lang.Exception
Description copied from interface:URLConnector
Connect to the specified URL while providing the last known tag for the remote resource; the response will benull
if the remote resource is unchanged.- Specified by:
connectTagged
in interfaceURLConnector
- Parameters:
url
- The remote URL.tag
- The last known tag value for the resource.- Returns:
- An instance of
TaggedData
, ornull
if the resource has not modified (i.e., if it has the same tag value). - Throws:
java.io.IOException
- @since 1.1java.lang.Exception
-
build
public HttpRequest<java.lang.Object> build()
-
send
public java.lang.Object send(HttpRequest<?> request) throws java.lang.Exception
- Throws:
java.lang.Exception
-
send0
public TaggedData send0(HttpRequest<?> request) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getProxySetup
public ProxyHandler.ProxySetup getProxySetup(java.net.URL url) throws java.lang.Exception
- Throws:
java.lang.Exception
-
connectWithProxy
public <T> T connectWithProxy(ProxyHandler.ProxySetup proxySetup, java.util.concurrent.Callable<T> r) throws java.lang.Exception
- Throws:
java.lang.Exception
-
findMatchingHandler
public URLConnectionHandler findMatchingHandler(java.net.URL url) throws java.lang.Exception
- Throws:
java.lang.Exception
-
setCache
public void setCache(java.io.File cache)
-
setReporter
public void setReporter(aQute.service.reporter.Reporter reporter)
-
setRegistry
public void setRegistry(Registry registry)
-
addURLConnectionHandler
public void addURLConnectionHandler(URLConnectionHandler handler)
-
getReporter
public aQute.service.reporter.Reporter getReporter()
-
addProxyHandler
public void addProxyHandler(ProxyHandler proxyHandler)
-
setLog
public void setLog(java.io.File log) throws java.io.IOException
- Throws:
java.io.IOException
-
getUserFor
public java.lang.String getUserFor(java.lang.String base) throws java.net.MalformedURLException, java.lang.Exception
- Throws:
java.net.MalformedURLException
java.lang.Exception
-
toName
public java.lang.String toName(java.net.URI url) throws java.lang.Exception
- Throws:
java.lang.Exception
-
getCacheFileFor
public java.io.File getCacheFileFor(java.net.URI url) throws java.lang.Exception
- Throws:
java.lang.Exception
-
readSettings
public void readSettings(Processor processor) throws java.io.IOException, java.lang.Exception
- Throws:
java.io.IOException
java.lang.Exception
-
makeDir
public java.net.URI makeDir(java.net.URI uri) throws java.net.URISyntaxException
- Throws:
java.net.URISyntaxException
-
isOffline
public boolean isOffline()
-
setOffline
public void setOffline(java.util.concurrent.atomic.AtomicBoolean offline)
-
-