Package play.libs.ws
Class WSRequest
- java.lang.Object
-
- play.libs.ws.WSRequest
-
- Direct Known Subclasses:
DummyWSRequest
public abstract class WSRequest extends java.lang.Object
-
-
Field Summary
Fields Modifier and Type Field Description java.lang.Objectbodyprotected java.nio.charset.CharsetencodingFileParam[]fileParamsbooleanfollowRedirectsSets whether redirects (301, 302) should be followed automaticallyjava.util.Map<java.lang.String,java.lang.String>headersjava.lang.StringmimeTypejava.util.Map<java.lang.String,java.lang.Object>parametersjava.lang.StringpasswordSchemeschemeinttimeoutTimeout: value in secondsjava.lang.Stringusernamejava.lang.StringvirtualHostThe virtual host this request will use
-
Constructor Summary
Constructors Modifier Constructor Description protectedWSRequest(java.lang.String url, java.nio.charset.Charset encoding)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description WSRequestauthenticate(java.lang.String username, java.lang.String password)define client authentication for a server host provided credentials will be used during the request the basic scheme will be usedWSRequestauthenticate(java.lang.String username, java.lang.String password, Scheme scheme)Define client authentication for a server host provided credentials will be used during the requestprotected java.lang.StringbasicAuthHeader()WSRequestbody(java.lang.Object body)Add the given body to the request.abstract HttpResponsedelete()Execute a DELETE request.Promise<HttpResponse>deleteAsync()Execute a DELETE request asynchronously.protected java.lang.Stringencode(java.lang.String part)WSRequestfiles(java.io.File... files)Add files to request.WSRequestfiles(FileParam... fileParams)Add fileParams aka File and Name parameter to the request.WSRequestfollowRedirects(boolean value)Indicate if the WS should continue when hitting a 301 or 302abstract HttpResponseget()Execute a GET request synchronously.Promise<HttpResponse>getAsync()Execute a GET request asynchronously.abstract HttpResponsehead()Execute a HEAD request.Promise<HttpResponse>headAsync()Execute a HEAD request asynchronously.WSRequestheaders(java.util.Map<java.lang.String,java.lang.String> headers)Use the provided headers when executing request.WSRequestmimeType(java.lang.String mimeType)Add a MimeType to the web service request.abstract HttpResponseoptions()Execute a OPTIONS request.Promise<HttpResponse>optionsAsync()Execute a OPTIONS request asynchronously.WSRequestparams(java.util.Map<java.lang.String,java.lang.String> parameters)Add parameters to request.abstract HttpResponsepatch()Execute a PATCH request.Promise<HttpResponse>patchAsync()Execute a PATCH request asynchronously.abstract HttpResponsepost()Execute a POST request.Promise<HttpResponse>postAsync()Execute a POST request asynchronously.abstract HttpResponseput()Execute a PUT request.Promise<HttpResponse>putAsync()Execute a PUT request asynchronously.WSRequestsetHeader(java.lang.String name, java.lang.String value)Add a header to the requestWSRequestsetParameter(java.lang.String name, java.lang.Object value)WSRequestsetParameter(java.lang.String name, java.lang.String value)Add a parameter to the requestWSRequesttimeout(java.lang.String timeout)Set the value of the request timeout, i.e.abstract HttpResponsetrace()Execute a TRACE request.Promise<HttpResponse>traceAsync()Execute a TRACE request asynchronously.WSRequestwithVirtualHost(java.lang.String virtualHost)Sets the virtual host to use in this request
-
-
-
Field Detail
-
virtualHost
public java.lang.String virtualHost
The virtual host this request will use
-
encoding
protected final java.nio.charset.Charset encoding
-
username
public java.lang.String username
-
password
public java.lang.String password
-
scheme
public Scheme scheme
-
body
public java.lang.Object body
-
fileParams
public FileParam[] fileParams
-
headers
public final java.util.Map<java.lang.String,java.lang.String> headers
-
parameters
public final java.util.Map<java.lang.String,java.lang.Object> parameters
-
mimeType
public java.lang.String mimeType
-
followRedirects
public boolean followRedirects
Sets whether redirects (301, 302) should be followed automatically
-
timeout
public int timeout
Timeout: value in seconds
-
-
Method Detail
-
withVirtualHost
public WSRequest withVirtualHost(java.lang.String virtualHost)
Sets the virtual host to use in this request- Parameters:
virtualHost- The given virtual host- Returns:
- the WSRequest
-
mimeType
public WSRequest mimeType(java.lang.String mimeType)
Add a MimeType to the web service request.- Parameters:
mimeType- the given mimeType- Returns:
- the WSRequest for chaining.
-
authenticate
public WSRequest authenticate(java.lang.String username, java.lang.String password, Scheme scheme)
Define client authentication for a server host provided credentials will be used during the request- Parameters:
username- Loginpassword- Passwordscheme- The given Scheme- Returns:
- the WSRequest for chaining.
-
authenticate
public WSRequest authenticate(java.lang.String username, java.lang.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- Loginpassword- 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(java.lang.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(java.io.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(java.lang.Object body)
Add the given body to the request.- Parameters:
body- The request body- Returns:
- the WSRequest for chaining.
-
setHeader
public WSRequest setHeader(java.lang.String name, java.lang.String value)
Add a header to the request- Parameters:
name- header namevalue- header value- Returns:
- the WSRequest for chaining.
-
setParameter
public WSRequest setParameter(java.lang.String name, java.lang.String value)
Add a parameter to the request- Parameters:
name- parameter namevalue- parameter value- Returns:
- the WSRequest for chaining.
-
setParameter
public WSRequest setParameter(java.lang.String name, java.lang.Object value)
-
headers
public WSRequest headers(java.util.Map<java.lang.String,java.lang.String> headers)
Use the provided headers when executing request.- Parameters:
headers- The request headers- Returns:
- the WSRequest for chaining.
-
params
public WSRequest params(java.util.Map<java.lang.String,java.lang.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 java.lang.String basicAuthHeader()
-
encode
protected java.lang.String encode(java.lang.String part)
-
-