Class AhcWSRequest

  • All Implemented Interfaces:
    play.libs.ws.StandaloneWSRequest, WSRequest

    public class AhcWSRequest
    extends Object
    implements WSRequest
    A Play WS request backed by AsyncHTTPClient implementation.
    • Method Detail

      • get

        public CompletionStage<WSResponse> get()
        Description copied from interface: WSRequest
        Perform a GET on the request asynchronously.
        Specified by:
        get in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        get in interface WSRequest
        Returns:
        a promise to the response
      • patch

        public CompletionStage<WSResponse> patch​(play.libs.ws.BodyWritable body)
        Description copied from interface: WSRequest
        Perform a PATCH on the request asynchronously.
        Specified by:
        patch in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        patch in interface WSRequest
        Parameters:
        body - represented as BodyWritable
        Returns:
        a promise to the response
      • patch

        public CompletionStage<WSResponse> patch​(String string)
        Description copied from interface: WSRequest
        Perform a PATCH on the request asynchronously.
        Specified by:
        patch in interface WSRequest
        Parameters:
        string - represented as String
        Returns:
        a promise to the response
      • patch

        public CompletionStage<WSResponse> patch​(com.fasterxml.jackson.databind.JsonNode jsonNode)
        Description copied from interface: WSRequest
        Perform a PATCH on the request asynchronously.
        Specified by:
        patch in interface WSRequest
        Parameters:
        jsonNode - represented as JSON
        Returns:
        a promise to the response
      • patch

        public CompletionStage<WSResponse> patch​(Document doc)
        Description copied from interface: WSRequest
        Perform a PATCH on the request asynchronously.
        Specified by:
        patch in interface WSRequest
        Parameters:
        doc - represented as a Document
        Returns:
        a promise to the response
      • patch

        public CompletionStage<WSResponse> patch​(File file)
        Description copied from interface: WSRequest
        Perform a PATCH on the request asynchronously.
        Specified by:
        patch in interface WSRequest
        Parameters:
        file - represented as a File
        Returns:
        a promise to the response
      • post

        public CompletionStage<WSResponse> post​(play.libs.ws.BodyWritable body)
        Description copied from interface: WSRequest
        Perform a POST on the request asynchronously.
        Specified by:
        post in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        post in interface WSRequest
        Parameters:
        body - represented as body writable
        Returns:
        a promise to the response
      • post

        public CompletionStage<WSResponse> post​(String string)
        Description copied from interface: WSRequest
        Perform a POST on the request asynchronously.
        Specified by:
        post in interface WSRequest
        Parameters:
        string - represented as String
        Returns:
        a promise to the response
      • post

        public CompletionStage<WSResponse> post​(com.fasterxml.jackson.databind.JsonNode json)
        Description copied from interface: WSRequest
        Perform a POST on the request asynchronously.
        Specified by:
        post in interface WSRequest
        Parameters:
        json - represented as JSON
        Returns:
        a promise to the response
      • post

        public CompletionStage<WSResponse> post​(Document doc)
        Description copied from interface: WSRequest
        Perform a POST on the request asynchronously.
        Specified by:
        post in interface WSRequest
        Parameters:
        doc - represented as a Document
        Returns:
        a promise to the response
      • post

        public CompletionStage<WSResponse> post​(File file)
        Description copied from interface: WSRequest
        Perform a POST on the request asynchronously.
        Specified by:
        post in interface WSRequest
        Parameters:
        file - represented as a File
        Returns:
        a promise to the response
      • put

        public CompletionStage<WSResponse> put​(play.libs.ws.BodyWritable body)
        Description copied from interface: WSRequest
        Perform a PUT on the request asynchronously.
        Specified by:
        put in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        put in interface WSRequest
        Parameters:
        body - represented as BodyWritable
        Returns:
        a promise to the response
      • put

        public CompletionStage<WSResponse> put​(String string)
        Description copied from interface: WSRequest
        Perform a PUT on the request asynchronously.
        Specified by:
        put in interface WSRequest
        Parameters:
        string - represented as String
        Returns:
        a promise to the response
      • put

        public CompletionStage<WSResponse> put​(com.fasterxml.jackson.databind.JsonNode json)
        Description copied from interface: WSRequest
        Perform a PUT on the request asynchronously.
        Specified by:
        put in interface WSRequest
        Parameters:
        json - represented as JSON
        Returns:
        a promise to the response
      • put

        public CompletionStage<WSResponse> put​(Document doc)
        Description copied from interface: WSRequest
        Perform a PUT on the request asynchronously.
        Specified by:
        put in interface WSRequest
        Parameters:
        doc - represented as a Document
        Returns:
        a promise to the response
      • put

        public CompletionStage<WSResponse> put​(File file)
        Description copied from interface: WSRequest
        Perform a PUT on the request asynchronously.
        Specified by:
        put in interface WSRequest
        Parameters:
        file - represented as a File
        Returns:
        a promise to the response
      • delete

        public CompletionStage<WSResponse> delete()
        Description copied from interface: WSRequest
        Perform a DELETE on the request asynchronously.
        Specified by:
        delete in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        delete in interface WSRequest
        Returns:
        a promise to the response
      • head

        public CompletionStage<WSResponse> head()
        Description copied from interface: WSRequest
        Perform a HEAD on the request asynchronously.
        Specified by:
        head in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        head in interface WSRequest
        Returns:
        a promise to the response
      • options

        public CompletionStage<WSResponse> options()
        Description copied from interface: WSRequest
        Perform an OPTIONS on the request asynchronously.
        Specified by:
        options in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        options in interface WSRequest
        Returns:
        a promise to the response
      • execute

        public CompletionStage<WSResponse> execute​(String method)
        Description copied from interface: WSRequest
        Execute an arbitrary method on the request asynchronously.
        Specified by:
        execute in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        execute in interface WSRequest
        Parameters:
        method - The method to execute
        Returns:
        a promise to the response
      • execute

        public CompletionStage<WSResponse> execute()
        Description copied from interface: WSRequest
        Execute an arbitrary method on the request asynchronously. Should be used with setMethod().
        Specified by:
        execute in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        execute in interface WSRequest
        Returns:
        a promise to the response
      • stream

        public CompletionStage<WSResponse> stream()
        Description copied from interface: WSRequest
        Execute this request and stream the response body.
        Specified by:
        stream in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        stream in interface WSRequest
        Returns:
        a promise to the streaming response
      • setMethod

        public WSRequest setMethod​(String method)
        Description copied from interface: WSRequest
        Sets the HTTP method this request should use, where the no args execute() method is invoked.
        Specified by:
        setMethod in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setMethod in interface WSRequest
        Parameters:
        method - the HTTP method.
        Returns:
        the modified WSRequest.
      • setBody

        public WSRequest setBody​(play.libs.ws.BodyWritable bodyWritable)
        Description copied from interface: WSRequest
        Set the body this request should use.
        Specified by:
        setBody in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setBody in interface WSRequest
        Parameters:
        bodyWritable - the body of the request.
        Returns:
        the modified WSRequest.
      • setBody

        public WSRequest setBody​(String string)
        Description copied from interface: WSRequest
        Set the body this request should use.
        Specified by:
        setBody in interface WSRequest
        Parameters:
        string - the body of the request.
        Returns:
        the modified WSRequest.
      • setBody

        public WSRequest setBody​(com.fasterxml.jackson.databind.JsonNode json)
        Description copied from interface: WSRequest
        Set the body this request should use.
        Specified by:
        setBody in interface WSRequest
        Parameters:
        json - the body of the request.
        Returns:
        the modified WSRequest.
      • setBody

        public WSRequest setBody​(File file)
        Description copied from interface: WSRequest
        Set the body this request should use.
        Specified by:
        setBody in interface WSRequest
        Parameters:
        file - the body of the request.
        Returns:
        the modified WSRequest.
      • setBody

        public <U> WSRequest setBody​(Source<ByteString,​U> source)
        Description copied from interface: WSRequest
        Set the body this request should use.
        Specified by:
        setBody in interface WSRequest
        Parameters:
        source - the body of the request.
        Returns:
        the modified WSRequest.
      • setHeader

        @Deprecated
        public WSRequest setHeader​(String name,
                                   String value)
        Deprecated.
        use addHeader(name, value)
        Description copied from interface: WSRequest
        Adds a header to the request. Note that duplicate headers are allowed by the HTTP specification, and removing a header is not available through this API.
        Specified by:
        setHeader in interface WSRequest
        Parameters:
        name - the header name
        value - the header value
        Returns:
        the modified WSRequest.
      • setHeaders

        public WSRequest setHeaders​(Map<String,​List<String>> headers)
        Description copied from interface: WSRequest
        Sets all of the headers on the request.
        Specified by:
        setHeaders in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setHeaders in interface WSRequest
        Parameters:
        headers - the headers
        Returns:
        the modified WSRequest.
      • addHeader

        public WSRequest addHeader​(String name,
                                   String value)
        Description copied from interface: WSRequest
        Adds a header to the request. Note that duplicate headers are allowed by the HTTP specification, and removing a header is not available through this API.
        Specified by:
        addHeader in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        addHeader in interface WSRequest
        Parameters:
        name - the header name
        value - the header value
        Returns:
        the modified WSRequest.
      • setQueryString

        public WSRequest setQueryString​(String query)
        Description copied from interface: WSRequest
        Sets the query string to query.
        Specified by:
        setQueryString in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setQueryString in interface WSRequest
        Parameters:
        query - the fully formed query string
        Returns:
        the modified WSRequest.
      • setQueryParameter

        @Deprecated
        public WSRequest setQueryParameter​(String name,
                                           String value)
        Deprecated.
        Use addQueryParameter
        Description copied from interface: WSRequest
        Sets a query parameter with the given name, this can be called repeatedly. Duplicate query parameters are allowed.
        Specified by:
        setQueryParameter in interface WSRequest
        Parameters:
        name - the query parameter name
        value - the query parameter value
        Returns:
        the modified WSRequest.
      • addQueryParameter

        public WSRequest addQueryParameter​(String name,
                                           String value)
        Description copied from interface: WSRequest
        Sets a query parameter with the given name, this can be called repeatedly. Duplicate query parameters are allowed.
        Specified by:
        addQueryParameter in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        addQueryParameter in interface WSRequest
        Parameters:
        name - the query parameter name
        value - the query parameter value
        Returns:
        the modified WSRequest.
      • setQueryString

        public WSRequest setQueryString​(Map<String,​List<String>> params)
        Description copied from interface: WSRequest
        Sets the query string to query.
        Specified by:
        setQueryString in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setQueryString in interface WSRequest
        Parameters:
        params - the query string parameters
        Returns:
        the modified WSRequest.
      • setUrl

        public play.libs.ws.StandaloneWSRequest setUrl​(String url)
        Specified by:
        setUrl in interface play.libs.ws.StandaloneWSRequest
      • addCookie

        public WSRequest addCookie​(play.libs.ws.WSCookie cookie)
        Description copied from interface: WSRequest
        Adds a cookie to the request
        Specified by:
        addCookie in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        addCookie in interface WSRequest
        Parameters:
        cookie - the cookie to add.
        Returns:
        the modified request
      • addCookie

        public WSRequest addCookie​(Http.Cookie cookie)
        Description copied from interface: WSRequest
        Adds a cookie to the request
        Specified by:
        addCookie in interface WSRequest
        Parameters:
        cookie - the cookie to add.
        Returns:
        the modified request
      • addCookies

        public WSRequest addCookies​(play.libs.ws.WSCookie... cookies)
        Description copied from interface: WSRequest
        Sets several cookies on the request.
        Specified by:
        addCookies in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        addCookies in interface WSRequest
        Parameters:
        cookies - the cookies.
        Returns:
        the modified request
      • setCookies

        public WSRequest setCookies​(List<play.libs.ws.WSCookie> cookies)
        Description copied from interface: WSRequest
        Sets all the cookies on the request.
        Specified by:
        setCookies in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setCookies in interface WSRequest
        Parameters:
        cookies - all the cookies.
        Returns:
        the modified request
      • setAuth

        public WSRequest setAuth​(String userInfo)
        Description copied from interface: WSRequest
        Sets the authentication header for the current request using BASIC authentication.
        Specified by:
        setAuth in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setAuth in interface WSRequest
        Parameters:
        userInfo - a string formed as "username:password".
        Returns:
        the modified WSRequest.
      • setAuth

        public WSRequest setAuth​(String username,
                                 String password)
        Description copied from interface: WSRequest
        Sets the authentication header for the current request using BASIC authentication.
        Specified by:
        setAuth in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setAuth in interface WSRequest
        Parameters:
        username - the basic auth username
        password - the basic auth password
        Returns:
        the modified WSRequest.
      • setAuth

        public WSRequest setAuth​(String username,
                                 String password,
                                 play.libs.ws.WSAuthScheme scheme)
        Description copied from interface: WSRequest
        Sets the authentication header for the current request.
        Specified by:
        setAuth in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setAuth in interface WSRequest
        Parameters:
        username - the username
        password - the password
        scheme - authentication scheme
        Returns:
        the modified WSRequest.
      • setAuth

        public play.libs.ws.StandaloneWSRequest setAuth​(play.libs.ws.WSAuthInfo authInfo)
        Specified by:
        setAuth in interface play.libs.ws.StandaloneWSRequest
      • sign

        public WSRequest sign​(play.libs.ws.WSSignatureCalculator calculator)
        Description copied from interface: WSRequest
        Sets an (OAuth) signature calculator.
        Specified by:
        sign in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        sign in interface WSRequest
        Parameters:
        calculator - the signature calculator
        Returns:
        the modified WSRequest
      • setFollowRedirects

        public WSRequest setFollowRedirects​(boolean followRedirects)
        Description copied from interface: WSRequest
        Sets whether redirects (301, 302) should be followed automatically.
        Specified by:
        setFollowRedirects in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setFollowRedirects in interface WSRequest
        Parameters:
        followRedirects - true if the request should follow redirects
        Returns:
        the modified WSRequest
      • setDisableUrlEncoding

        public WSRequest setDisableUrlEncoding​(boolean disableUrlEncoding)
        Specified by:
        setDisableUrlEncoding in interface play.libs.ws.StandaloneWSRequest
      • setVirtualHost

        public WSRequest setVirtualHost​(String virtualHost)
        Description copied from interface: WSRequest
        Sets the virtual host as a "hostname:port" string.
        Specified by:
        setVirtualHost in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setVirtualHost in interface WSRequest
        Parameters:
        virtualHost - the virtual host
        Returns:
        the modified WSRequest
      • setRequestTimeout

        public WSRequest setRequestTimeout​(Duration timeout)
        Description copied from interface: WSRequest
        Sets the request timeout in milliseconds.
        Specified by:
        setRequestTimeout in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setRequestTimeout in interface WSRequest
        Parameters:
        timeout - the request timeout in milliseconds. A value of -1 indicates an infinite request timeout.
        Returns:
        the modified WSRequest.
      • setRequestFilter

        public WSRequest setRequestFilter​(play.libs.ws.WSRequestFilter filter)
        Description copied from interface: WSRequest
        Adds a request filter.
        Specified by:
        setRequestFilter in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setRequestFilter in interface WSRequest
        Parameters:
        filter - a transforming filter.
        Returns:
        the modified request.
      • setContentType

        public WSRequest setContentType​(String contentType)
        Description copied from interface: WSRequest
        Set the content type. If the request body is a String, and no charset parameter is included, then it will default to UTF-8.
        Specified by:
        setContentType in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        setContentType in interface WSRequest
        Parameters:
        contentType - The content type
        Returns:
        the modified WSRequest
      • getAuth

        public Optional<play.libs.ws.WSAuthInfo> getAuth()
        Specified by:
        getAuth in interface play.libs.ws.StandaloneWSRequest
      • getBody

        public Optional<play.libs.ws.BodyWritable> getBody()
        Specified by:
        getBody in interface play.libs.ws.StandaloneWSRequest
      • getCalculator

        public Optional<play.libs.ws.WSSignatureCalculator> getCalculator()
        Specified by:
        getCalculator in interface play.libs.ws.StandaloneWSRequest
      • getContentType

        public Optional<String> getContentType()
        Specified by:
        getContentType in interface play.libs.ws.StandaloneWSRequest
      • getFollowRedirects

        public Optional<Boolean> getFollowRedirects()
        Specified by:
        getFollowRedirects in interface play.libs.ws.StandaloneWSRequest
      • getDisableUrlEncoding

        public Optional<Boolean> getDisableUrlEncoding()
        Specified by:
        getDisableUrlEncoding in interface play.libs.ws.StandaloneWSRequest
      • getUrl

        public String getUrl()
        Specified by:
        getUrl in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        getUrl in interface WSRequest
        Returns:
        the URL of the request. This has not passed through an internal request builder and so will not be signed.
      • getHeaders

        public Map<String,​List<String>> getHeaders()
        Specified by:
        getHeaders in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        getHeaders in interface WSRequest
        Returns:
        the headers (a copy to prevent side-effects). This has not passed through an internal request builder and so will not be signed.
      • getHeaderValues

        public List<String> getHeaderValues​(String name)
        Specified by:
        getHeaderValues in interface play.libs.ws.StandaloneWSRequest
      • getHeader

        public Optional<String> getHeader​(String name)
        Specified by:
        getHeader in interface play.libs.ws.StandaloneWSRequest
      • getRequestTimeout

        public Optional<Duration> getRequestTimeout()
        Specified by:
        getRequestTimeout in interface play.libs.ws.StandaloneWSRequest
      • getQueryParameters

        public Map<String,​List<String>> getQueryParameters()
        Specified by:
        getQueryParameters in interface play.libs.ws.StandaloneWSRequest
        Specified by:
        getQueryParameters in interface WSRequest
        Returns:
        the query parameters (a copy to prevent side-effects). This has not passed through an internal request builder and so will not be signed.