Package aQute.bnd.http
Class HttpRequest<T>
- java.lang.Object
-
- aQute.bnd.http.HttpRequest<T>
-
- Type Parameters:
T
-
public class HttpRequest<T> extends java.lang.Object
Builds up a request
-
-
Field Summary
Fields Modifier and Type Field Description (package private) boolean
cached
(package private) HttpClient
client
(package private) java.lang.reflect.Type
download
(package private) java.util.Map<java.lang.String,java.lang.String>
headers
(package private) java.lang.String
ifMatch
(package private) long
ifModifiedSince
(package private) java.lang.String
ifNoneMatch
(package private) long
ifUnmodifiedSince
(package private) boolean
isIdemPotent
(package private) long
maxStale
(package private) int
redirects
(package private) Reporter
reporter
(package private) int
retries
(package private) long
retryDelay
(package private) long
timeout
(package private) boolean
updateTag
(package private) java.lang.Object
upload
(package private) java.net.URL
url
(package private) java.io.File
useCacheFile
(package private) java.lang.String
verb
-
Constructor Summary
Constructors Constructor Description HttpRequest(HttpClient client)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description HttpRequest<T>
age(int n, java.util.concurrent.TimeUnit tu)
HttpRequest<java.lang.String>
asString()
HttpRequest<TaggedData>
asTag()
org.osgi.util.promise.Promise<T>
async(java.net.URI uri)
org.osgi.util.promise.Promise<T>
async(java.net.URL url)
HttpRequest<T>
delete()
Set the verb/method to deleteHttpRequest<T>
get()
Set the verb/method to get<X> HttpRequest<X>
get(TypeReference<X> type)
Convert the result to a specific type<X> HttpRequest<X>
get(java.lang.Class<X> type)
Convert the result to a specific typeHttpRequest<java.lang.Object>
get(java.lang.reflect.Type type)
Convert the result to a specific typeT
go(java.net.URI url)
T
go(java.net.URL url)
HttpRequest<T>
head()
Set the verb/method to headHttpRequest<T>
headers(java.lang.String key, java.lang.String value)
Add header to requestHttpRequest<T>
headers(java.util.Map<java.lang.String,java.lang.String> map)
Add headers to requestHttpRequest<T>
idemPotent(boolean isIdemPotent)
Idempotent MethodsHttpRequest<T>
ifMatch(java.lang.String etag)
HttpRequest<T>
ifModifiedSince(long epochTime)
HttpRequest<T>
ifNoneMatch(java.lang.String etag)
HttpRequest<T>
ifUnmodifiedSince(long ifNotModifiedSince)
boolean
isCache()
boolean
isTagResult()
HttpRequest<T>
maxRedirects(int n)
HttpRequest<T>
option()
Set the verb/method to optionHttpRequest<T>
post()
Set the verb/method to postHttpRequest<T>
put()
Set the verb/method to putHttpRequest<T>
report(Reporter reporter)
HttpRequest<T>
retries(int retries)
Set the number of retries.HttpRequest<T>
retryDelay(int retryDelay)
HttpRequest<T>
timeout(long timeoutInMs)
Set timeout in msHttpRequest<T>
timeout(long timeout, java.util.concurrent.TimeUnit unit)
java.lang.String
toString()
HttpRequest<T>
trace()
Set the verb/method to optionHttpRequest<T>
updateTag()
HttpRequest<T>
upload(java.lang.Object upload)
Set the object to upload.HttpRequest<java.io.File>
useCache()
HttpRequest<java.io.File>
useCache(long maxStale)
HttpRequest<java.io.File>
useCache(java.io.File file)
HttpRequest<java.io.File>
useCache(java.io.File file, long maxStale)
HttpRequest<T>
verb(java.lang.String verb)
Set the HTTP verb.
-
-
-
Field Detail
-
verb
java.lang.String verb
-
isIdemPotent
boolean isIdemPotent
-
upload
java.lang.Object upload
-
download
java.lang.reflect.Type download
-
headers
java.util.Map<java.lang.String,java.lang.String> headers
-
timeout
long timeout
-
client
HttpClient client
-
ifNoneMatch
java.lang.String ifNoneMatch
-
ifModifiedSince
long ifModifiedSince
-
ifUnmodifiedSince
long ifUnmodifiedSince
-
url
java.net.URL url
-
redirects
int redirects
-
ifMatch
java.lang.String ifMatch
-
cached
boolean cached
-
maxStale
long maxStale
-
reporter
Reporter reporter
-
useCacheFile
java.io.File useCacheFile
-
updateTag
boolean updateTag
-
retries
int retries
-
retryDelay
long retryDelay
-
-
Constructor Detail
-
HttpRequest
HttpRequest(HttpClient client)
-
-
Method Detail
-
get
public <X> HttpRequest<X> get(java.lang.Class<X> type)
Convert the result to a specific type
-
get
public <X> HttpRequest<X> get(TypeReference<X> type)
Convert the result to a specific type
-
get
public HttpRequest<java.lang.Object> get(java.lang.reflect.Type type)
Convert the result to a specific type
-
verb
public HttpRequest<T> verb(java.lang.String verb)
Set the HTTP verb. The methods GET, HEAD, PUT and DELETE are idempotent. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent.
-
put
public HttpRequest<T> put()
Set the verb/method to put
-
head
public HttpRequest<T> head()
Set the verb/method to head
-
get
public HttpRequest<T> get()
Set the verb/method to get
-
post
public HttpRequest<T> post()
Set the verb/method to post
-
option
public HttpRequest<T> option()
Set the verb/method to option
-
trace
public HttpRequest<T> trace()
Set the verb/method to option
-
delete
public HttpRequest<T> delete()
Set the verb/method to delete
-
upload
public HttpRequest<T> upload(java.lang.Object upload)
Set the object to upload. Can be of several types:- InputStream – copied verbatim
- String – content sent
- byte[] – content sent
- File – content sent
- Otherwise assumes DTO and encodes in JSON
-
headers
public HttpRequest<T> headers(java.util.Map<java.lang.String,java.lang.String> map)
Add headers to request
-
headers
public HttpRequest<T> headers(java.lang.String key, java.lang.String value)
Add header to request
-
timeout
public HttpRequest<T> timeout(long timeoutInMs)
Set timeout in ms
-
ifNoneMatch
public HttpRequest<T> ifNoneMatch(java.lang.String etag)
-
ifModifiedSince
public HttpRequest<T> ifModifiedSince(long epochTime)
-
maxRedirects
public HttpRequest<T> maxRedirects(int n)
-
go
public T go(java.net.URL url) throws java.lang.Exception
- Throws:
java.lang.Exception
-
go
public T go(java.net.URI url) throws java.lang.Exception
- Throws:
java.lang.Exception
-
age
public HttpRequest<T> age(int n, java.util.concurrent.TimeUnit tu)
-
async
public org.osgi.util.promise.Promise<T> async(java.net.URL url)
-
async
public org.osgi.util.promise.Promise<T> async(java.net.URI uri)
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
ifUnmodifiedSince
public HttpRequest<T> ifUnmodifiedSince(long ifNotModifiedSince)
-
ifMatch
public HttpRequest<T> ifMatch(java.lang.String etag)
-
asTag
public HttpRequest<TaggedData> asTag()
-
asString
public HttpRequest<java.lang.String> asString()
-
isCache
public boolean isCache()
-
useCache
public HttpRequest<java.io.File> useCache(long maxStale)
-
useCache
public HttpRequest<java.io.File> useCache()
-
useCache
public HttpRequest<java.io.File> useCache(java.io.File file)
-
useCache
public HttpRequest<java.io.File> useCache(java.io.File file, long maxStale)
-
report
public HttpRequest<T> report(Reporter reporter)
-
timeout
public HttpRequest<T> timeout(long timeout, java.util.concurrent.TimeUnit unit)
-
isTagResult
public boolean isTagResult()
-
updateTag
public HttpRequest<T> updateTag()
-
retries
public HttpRequest<T> retries(int retries)
Set the number of retries. Retries are only attempted when the method verb implies idempotency, or it is explicitly set to be idempotent, seeidemPotent(boolean)
.- Parameters:
retries
- number of retries, default is 3.- Returns:
- this
-
retryDelay
public HttpRequest<T> retryDelay(int retryDelay)
-
idemPotent
public HttpRequest<T> idemPotent(boolean isIdemPotent)
Idempotent MethodsMethods can also have the property of "idempotence" in that (aside from error or expiration issues) the side-effects of N > 0 identical requests is the same as for a single request. The methods GET, HEAD, PUT and DELETE share this property. Also, the methods OPTIONS and TRACE SHOULD NOT have side effects, and so are inherently idempotent.
The
verb(String)
method will set the idempotency according to this specification. This method can then override the default idempotency.- Parameters:
isIdemPotent
- if the to be used method is idempotent. (Is overridden if the method verb is set after this method!)- Returns:
- this
-
-