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.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description (package private) classHttpClient.HttpConnection<T>
-
Field Summary
Fields Modifier and Type Field Description private URLCachecache(package private) static JSONCodeccodecprivate java.util.List<URLConnectionHandler>connectionHandlersprivate ConnectionSettingsconnectionSettings(package private) static longFINAL_TIMEOUTprivate booleaninited(package private) static longINITIAL_TIMEOUT(package private) static org.slf4j.Loggerlogger(package private) static longMAX_RETRY_DELAYprivate java.util.concurrent.atomic.AtomicBooleanofflineprivate java.lang.ThreadLocal<java.net.PasswordAuthentication>passwordAuthenticationprivate org.osgi.util.promise.PromiseFactorypromiseFactoryprivate java.util.List<ProxyHandler>proxyHandlersprivate Registryregistryprivate Reporterreporter(package private) intretries(package private) longretryDelaystatic java.text.SimpleDateFormatsdfDeprecated.
-
Constructor Summary
Constructors Constructor Description HttpClient()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddProxyHandler(ProxyHandler proxyHandler)voidaddURLConnectionHandler(URLConnectionHandler handler)HttpRequest<java.lang.Object>build()URLCachecache()voidclose()java.io.InputStreamconnect(java.net.URL url)Connect to the specified URL.TaggedDataconnectTagged(java.net.URL url)Connect to the specified URL, also returning the ETag if available.TaggedDataconnectTagged(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 benullif the remote resource is unchanged.<T> TconnectWithProxy(ProxyHandler.ProxySetup proxySetup, java.util.concurrent.Callable<T> r)(package private) java.io.InputStreamcreateProgressWrappedStream(java.io.InputStream inputStream, java.lang.String name, int size, ProgressPlugin.Task task, long timeout)URLConnectionHandlerfindMatchingHandler(java.net.URL url)java.io.FilegetCacheFileFor(java.net.URI url)private java.util.Collection<? extends ProxyHandler>getProxyHandlers()ProxyHandler.ProxySetupgetProxySetup(java.net.URL url)ReportergetReporter()private java.util.Collection<? extends URLConnectionHandler>getURLConnectionHandlers()java.lang.StringgetUserFor(java.lang.String base)(package private) voidinit()booleanisOffline()java.net.URImakeDir(java.net.URI uri)org.osgi.util.promise.PromiseFactorypromiseFactory()voidreadSettings(Processor processor)voidreportSettings(java.util.Formatter out)HttpClientretries(int retries)HttpClientretryDelay(int retryDelay)<T> Tsend(HttpRequest<T> request)TaggedDatasend0(HttpRequest<?> request)(package private) <T> org.osgi.util.promise.Promise<T>sendAsync(HttpRequest<T> request)private <T> org.osgi.util.promise.Promise<T>sendAsync(HttpRequest<T> request, int retries, long delay)voidsetCache(java.io.File cache)voidsetLog(java.io.File log)voidsetOffline(java.util.concurrent.atomic.AtomicBoolean offline)voidsetRegistry(Registry registry)voidsetReporter(Reporter reporter)java.lang.StringtoName(java.net.URI url)java.lang.StringvalidateURI(java.net.URI u)Validate a URI to see if it is supported by this client
-
-
-
Field Detail
-
logger
static final org.slf4j.Logger logger
-
sdf
@Deprecated public static final java.text.SimpleDateFormat sdf
Deprecated.
-
INITIAL_TIMEOUT
static final long INITIAL_TIMEOUT
-
FINAL_TIMEOUT
static final long FINAL_TIMEOUT
-
MAX_RETRY_DELAY
static final long MAX_RETRY_DELAY
-
proxyHandlers
private final java.util.List<ProxyHandler> proxyHandlers
-
connectionHandlers
private final java.util.List<URLConnectionHandler> connectionHandlers
-
passwordAuthentication
private java.lang.ThreadLocal<java.net.PasswordAuthentication> passwordAuthentication
-
inited
private boolean inited
-
codec
static final JSONCodec codec
-
cache
private URLCache cache
-
registry
private Registry registry
-
reporter
private Reporter reporter
-
offline
private volatile java.util.concurrent.atomic.AtomicBoolean offline
-
promiseFactory
private final org.osgi.util.promise.PromiseFactory promiseFactory
-
connectionSettings
private ConnectionSettings connectionSettings
-
retries
int retries
-
retryDelay
long retryDelay
-
-
Method Detail
-
init
void init()
-
close
public void close()
- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable
-
connect
public java.io.InputStream connect(java.net.URL url) throws java.lang.ExceptionDescription copied from interface:URLConnectorConnect to the specified URL.- Specified by:
connectin interfaceURLConnector- Throws:
java.io.IOExceptionjava.lang.Exception
-
connectTagged
public TaggedData connectTagged(java.net.URL url) throws java.lang.Exception
Description copied from interface:URLConnectorConnect to the specified URL, also returning the ETag if available.- Specified by:
connectTaggedin interfaceURLConnector- Parameters:
url- The remote URL.- Returns:
- An instance of
TaggedData; note that theTaggedData.getTag()method may returnnullif 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:URLConnectorConnect to the specified URL while providing the last known tag for the remote resource; the response will benullif the remote resource is unchanged.- Specified by:
connectTaggedin interfaceURLConnector- Parameters:
url- The remote URL.tag- The last known tag value for the resource.- Returns:
- An instance of
TaggedData, ornullif 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()
-
sendAsync
<T> org.osgi.util.promise.Promise<T> sendAsync(HttpRequest<T> request)
-
sendAsync
private <T> org.osgi.util.promise.Promise<T> sendAsync(HttpRequest<T> request, int retries, long delay)
-
send
public <T> T send(HttpRequest<T> 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)
-
getURLConnectionHandlers
private java.util.Collection<? extends URLConnectionHandler> getURLConnectionHandlers()
-
getProxyHandlers
private java.util.Collection<? extends ProxyHandler> getProxyHandlers() throws java.lang.Exception
- Throws:
java.lang.Exception
-
createProgressWrappedStream
java.io.InputStream createProgressWrappedStream(java.io.InputStream inputStream, java.lang.String name, int size, ProgressPlugin.Task task, long timeout)
-
setCache
public void setCache(java.io.File cache)
-
setReporter
public void setReporter(Reporter reporter)
-
setRegistry
public void setRegistry(Registry registry)
-
addURLConnectionHandler
public void addURLConnectionHandler(URLConnectionHandler handler)
-
getReporter
public 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.MalformedURLExceptionjava.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.IOExceptionjava.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)
-
promiseFactory
public org.osgi.util.promise.PromiseFactory promiseFactory()
-
cache
public URLCache cache()
-
reportSettings
public void reportSettings(java.util.Formatter out)
-
retries
public HttpClient retries(int retries)
-
retryDelay
public HttpClient retryDelay(int retryDelay)
-
validateURI
public java.lang.String validateURI(java.net.URI u)
Validate a URI to see if it is supported by this client- Parameters:
u- the uri- Returns:
- null if ok, otherwise a reason why it is invalid
-
-