Package play.libs.ws

Class WSRequest

java.lang.Object
play.libs.ws.WSRequest
Direct Known Subclasses:
DummyWSRequest

public abstract class WSRequest extends Object
  • Field Details

    • virtualHost

      public String virtualHost
      The virtual host this request will use
    • encoding

      protected final Charset encoding
    • username

      public String username
    • password

      public String password
    • scheme

      public Scheme scheme
    • body

      public Object body
    • fileParams

      public FileParam[] fileParams
    • headers

      public final Map<String,String> headers
    • parameters

      public final Map<String,Object> parameters
    • mimeType

      public String mimeType
    • followRedirects

      public boolean followRedirects
      Sets whether redirects (301, 302) should be followed automatically
    • timeout

      public int timeout
      Timeout: value in seconds
  • Constructor Details

  • Method Details

    • withVirtualHost

      public WSRequest withVirtualHost(String virtualHost)
      Sets the virtual host to use in this request
      Parameters:
      virtualHost - The given virtual host
      Returns:
      the WSRequest
    • mimeType

      public WSRequest mimeType(String mimeType)
      Add a MimeType to the web service request.
      Parameters:
      mimeType - the given mimeType
      Returns:
      the WSRequest for chaining.
    • authenticate

      public WSRequest authenticate(String username, String password, Scheme scheme)
      Define client authentication for a server host provided credentials will be used during the request
      Parameters:
      username - Login
      password - Password
      scheme - The given Scheme
      Returns:
      the WSRequest for chaining.
    • authenticate

      public WSRequest authenticate(String username, String password)
      define client authentication for a server host provided credentials will be used during the request the basic scheme will be used
      Parameters:
      username - Login
      password - Password
      Returns:
      the WSRequest for chaining.
    • followRedirects

      public WSRequest followRedirects(boolean value)
      Indicate if the WS should continue when hitting a 301 or 302
      Parameters:
      value - Indicate if follow or not follow redirects
      Returns:
      the WSRequest for chaining.
    • timeout

      public WSRequest timeout(String timeout)
      Set the value of the request timeout, i.e. the number of seconds before cutting the connection - default to 60 seconds
      Parameters:
      timeout - the timeout value, e.g. "30s", "1min"
      Returns:
      the WSRequest for chaining
    • files

      public WSRequest files(File... files)
      Add files to request. This will only work with POST or PUT.
      Parameters:
      files - list of files
      Returns:
      the WSRequest for chaining.
    • files

      public WSRequest files(FileParam... fileParams)
      Add fileParams aka File and Name parameter to the request. This will only work with POST or PUT.
      Parameters:
      fileParams - The fileParams list
      Returns:
      the WSRequest for chaining.
    • body

      public WSRequest body(Object body)
      Add the given body to the request.
      Parameters:
      body - The request body
      Returns:
      the WSRequest for chaining.
    • setHeader

      public WSRequest setHeader(String name, String value)
      Add a header to the request
      Parameters:
      name - header name
      value - header value
      Returns:
      the WSRequest for chaining.
    • setParameter

      public WSRequest setParameter(String name, String value)
      Add a parameter to the request
      Parameters:
      name - parameter name
      value - parameter value
      Returns:
      the WSRequest for chaining.
    • setParameter

      public WSRequest setParameter(String name, Object value)
    • headers

      public WSRequest headers(Map<String,String> headers)
      Use the provided headers when executing request.
      Parameters:
      headers - The request headers
      Returns:
      the WSRequest for chaining.
    • params

      public WSRequest params(Map<String,String> parameters)
      Add parameters to request. If POST or PUT, parameters are passed in body using x-www-form-urlencoded if alone, or form-data if there is files too. For any other method, those params are appended to the queryString.
      Parameters:
      parameters - The request parameters
      Returns:
      the WSRequest for chaining.
    • get

      public abstract HttpResponse get()
      Execute a GET request synchronously.
      Returns:
      The HTTP response
    • getAsync

      public Promise<HttpResponse> getAsync()
      Execute a GET request asynchronously.
      Returns:
      The HTTP response
    • patch

      public abstract HttpResponse patch()
      Execute a PATCH request.
      Returns:
      The HTTP response
    • patchAsync

      public Promise<HttpResponse> patchAsync()
      Execute a PATCH request asynchronously.
      Returns:
      The HTTP response
    • post

      public abstract HttpResponse post()
      Execute a POST request.
      Returns:
      The HTTP response
    • postAsync

      public Promise<HttpResponse> postAsync()
      Execute a POST request asynchronously.
      Returns:
      The HTTP response
    • put

      public abstract HttpResponse put()
      Execute a PUT request.
      Returns:
      The HTTP response
    • putAsync

      public Promise<HttpResponse> putAsync()
      Execute a PUT request asynchronously.
      Returns:
      The HTTP response
    • delete

      public abstract HttpResponse delete()
      Execute a DELETE request.
      Returns:
      The HTTP response
    • deleteAsync

      public Promise<HttpResponse> deleteAsync()
      Execute a DELETE request asynchronously.
      Returns:
      The HTTP response
    • options

      public abstract HttpResponse options()
      Execute a OPTIONS request.
      Returns:
      The HTTP response
    • optionsAsync

      public Promise<HttpResponse> optionsAsync()
      Execute a OPTIONS request asynchronously.
      Returns:
      The HTTP response
    • head

      public abstract HttpResponse head()
      Execute a HEAD request.
      Returns:
      The HTTP response
    • headAsync

      public Promise<HttpResponse> headAsync()
      Execute a HEAD request asynchronously.
      Returns:
      The HTTP response
    • trace

      public abstract HttpResponse trace()
      Execute a TRACE request.
      Returns:
      The HTTP response
    • traceAsync

      public Promise<HttpResponse> traceAsync()
      Execute a TRACE request asynchronously.
      Returns:
      The HTTP response
    • basicAuthHeader

      protected String basicAuthHeader()
    • encode

      protected String encode(String part)