Class HttpRequest<T>

  • Type Parameters:
    T -

    public class HttpRequest<T>
    extends java.lang.Object
    Builds up a request
    • 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​(aQute.lib.converter.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 class java.lang.Object
      • ifUnmodifiedSince

        public HttpRequest<T> ifUnmodifiedSince​(long ifNotModifiedSince)
      • ifMatch

        public HttpRequest<T> ifMatch​(java.lang.String etag)
      • 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​(aQute.service.reporter.Reporter reporter)
      • timeout

        public HttpRequest<T> timeout​(long timeout,
                                      java.util.concurrent.TimeUnit unit)
      • isTagResult

        public boolean isTagResult()
      • 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, see idemPotent(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 Methods

        Methods 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