public class WebResource extends Filterable implements RequestBuilder<WebResource.Builder>, UniformInterface
A WebResource instance is obtained from the Client
.
The Web resource implements the UniformInterface
to invoke the HTTP
method on the Web resource. A client request may be built before invocation
on the uniform interface.
Methods to create a request and return a response are thread-safe. Methods that modify filters are not guaranteed to be thread-safe.
com.sun.jersey.api.client
Modifier and Type | Class and Description |
---|---|
class |
WebResource.Builder
The builder for building a
ClientRequest instance and
handling the request using the UniformInterface . |
Modifier and Type | Method and Description |
---|---|
WebResource.Builder |
accept(MediaType... types)
Add acceptable media types.
|
WebResource.Builder |
accept(java.lang.String... types)
Add acceptable media types.
|
WebResource.Builder |
acceptLanguage(java.util.Locale... locales)
Add acceptable languages
|
WebResource.Builder |
acceptLanguage(java.lang.String... locales)
Add acceptable languages
|
WebResource.Builder |
cookie(Cookie cookie)
Add a cookie to be set.
|
void |
delete()
Invoke the DELETE method with no request entity or response.
|
<T> T |
delete(java.lang.Class<T> c)
Invoke the DELETE method with no request entity that returns a response.
|
<T> T |
delete(java.lang.Class<T> c,
java.lang.Object requestEntity)
Invoke the DELETE method with a request entity that returns a response.
|
<T> T |
delete(GenericType<T> gt)
Invoke the DELETE method with a request entity that returns a response.
|
<T> T |
delete(GenericType<T> gt,
java.lang.Object requestEntity)
Invoke the DELETE method with a request entity that returns a response.
|
void |
delete(java.lang.Object requestEntity)
Invoke the DELETE method with a request entity but no response.
|
WebResource.Builder |
entity(java.lang.Object entity)
Set the request entity.
|
WebResource.Builder |
entity(java.lang.Object entity,
MediaType type)
Set the request entity with its media type.
|
WebResource.Builder |
entity(java.lang.Object entity,
java.lang.String type)
Set the request entity with its media type.
|
boolean |
equals(java.lang.Object obj)
Compares this resource to the specified object.
|
<T> T |
get(java.lang.Class<T> c)
Invoke the GET method.
|
<T> T |
get(GenericType<T> gt)
Invoke the GET method.
|
UriBuilder |
getBuilder()
Deprecated.
|
java.util.Map<java.lang.String,java.lang.Object> |
getProperties()
Gets WebResource related properties.
|
WebResource.Builder |
getRequestBuilder()
Get the ClientRequest builder.
|
java.net.URI |
getURI()
Get the URI to the resource.
|
UriBuilder |
getUriBuilder()
Get the URI builder to the resource.
|
int |
hashCode()
Returns a hash code for this
WebResource . |
ClientResponse |
head()
Invoke the HEAD method.
|
WebResource.Builder |
header(java.lang.String name,
java.lang.Object value)
Add an HTTP header and value.
|
void |
method(java.lang.String method)
Invoke a HTTP method with no request entity or response.
|
<T> T |
method(java.lang.String method,
java.lang.Class<T> c)
Invoke a HTTP method with no request entity that returns a response.
|
<T> T |
method(java.lang.String method,
java.lang.Class<T> c,
java.lang.Object requestEntity)
Invoke a HTTP method with a request entity that returns a response.
|
<T> T |
method(java.lang.String method,
GenericType<T> gt)
Invoke a HTTP method with no request entity that returns a response.
|
<T> T |
method(java.lang.String method,
GenericType<T> gt,
java.lang.Object requestEntity)
Invoke a HTTP method with a request entity that returns a response.
|
void |
method(java.lang.String method,
java.lang.Object requestEntity)
Invoke a HTTP method with a request entity but no response.
|
<T> T |
options(java.lang.Class<T> c)
Invoke the OPTIONS method.
|
<T> T |
options(GenericType<T> gt)
Invoke the OPTIONS method.
|
WebResource |
path(java.lang.String path)
Create a new WebResource from this web resource with an additional path
added to the URI of this web resource.
|
void |
post()
Invoke the POST method with no request entity or response.
|
<T> T |
post(java.lang.Class<T> c)
Invoke the POST method with no request entity that returns a response.
|
<T> T |
post(java.lang.Class<T> c,
java.lang.Object requestEntity)
Invoke the POST method with a request entity that returns a response.
|
<T> T |
post(GenericType<T> gt)
Invoke the POST method with a request entity that returns a response.
|
<T> T |
post(GenericType<T> gt,
java.lang.Object requestEntity)
Invoke the POST method with a request entity that returns a response.
|
void |
post(java.lang.Object requestEntity)
Invoke the POST method with a request entity but no response.
|
void |
put()
Invoke the PUT method with no request entity or response.
|
<T> T |
put(java.lang.Class<T> c)
Invoke the PUT method with no request entity that returns a response.
|
<T> T |
put(java.lang.Class<T> c,
java.lang.Object requestEntity)
Invoke the PUT method with a request entity that returns a response.
|
<T> T |
put(GenericType<T> gt)
Invoke the PUT method with a request entity that returns a response.
|
<T> T |
put(GenericType<T> gt,
java.lang.Object requestEntity)
Invoke the PUT method with a request entity that returns a response.
|
void |
put(java.lang.Object requestEntity)
Invoke the PUT method with a request entity but no response.
|
WebResource |
queryParam(java.lang.String key,
java.lang.String value)
Create a new WebResource from this web resource with an additional
query parameter added to the URI of this web resource.
|
WebResource |
queryParams(MultivaluedMap<java.lang.String,java.lang.String> params)
Create a new WebResource from this web resource with additional
query parameters added to the URI of this web resource.
|
void |
setProperty(java.lang.String property,
java.lang.Object value)
Sets WebResource related property.
|
java.lang.String |
toString() |
WebResource.Builder |
type(MediaType type)
Set the media type.
|
WebResource.Builder |
type(java.lang.String type)
Set the media type.
|
WebResource |
uri(java.net.URI uri)
Create a new WebResource from this web resource.
|
addFilter, getHeadHandler, isFilterPresent, isFilterPreset, removeAllFilters, removeFilter
public java.net.URI getURI()
@Deprecated public UriBuilder getBuilder()
public UriBuilder getUriBuilder()
public WebResource.Builder getRequestBuilder()
public java.lang.String toString()
toString
in class java.lang.Object
public int hashCode()
WebResource
.
The hash code is the hash code of URI of this
WebResource
.
hashCode
in class java.lang.Object
WebResource
.public boolean equals(java.lang.Object obj)
The result is true if and only if the argument is not null and is a
WebResource
object whose URI is equal to the URI of this
WebResource
.
equals
in class java.lang.Object
obj
- the object to compare this WebResource
against.WebResource
are equal; false otherwise.public ClientResponse head() throws ClientHandlerException
UniformInterface
head
in interface UniformInterface
ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T options(java.lang.Class<T> c) throws UniformInterfaceException, ClientHandlerException
UniformInterface
options
in interface UniformInterface
T
- the type of the response.c
- the type of the returned response.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T options(GenericType<T> gt) throws UniformInterfaceException, ClientHandlerException
UniformInterface
options
in interface UniformInterface
T
- the type of the response.gt
- the generic type of the returned response.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T get(java.lang.Class<T> c) throws UniformInterfaceException, ClientHandlerException
UniformInterface
get
in interface UniformInterface
T
- the type of the response.c
- the type of the returned response.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T get(GenericType<T> gt) throws UniformInterfaceException, ClientHandlerException
UniformInterface
get
in interface UniformInterface
T
- the type of the response.gt
- the generic type of the returned response.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public void put() throws UniformInterfaceException, ClientHandlerException
UniformInterface
If the status code is less than 300 and a representation is present then that representation is ignored.
put
in interface UniformInterface
UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300.ClientHandlerException
- if the client handler fails to process
the request or response.public void put(java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
If the status code is less than 300 and a representation is present then that representation is ignored.
put
in interface UniformInterface
requestEntity
- the request entity.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T put(java.lang.Class<T> c) throws UniformInterfaceException, ClientHandlerException
UniformInterface
put
in interface UniformInterface
T
- the type of the response.c
- the type of the returned response.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T put(GenericType<T> gt) throws UniformInterfaceException, ClientHandlerException
UniformInterface
put
in interface UniformInterface
T
- the type of the response.gt
- the generic type of the returned response.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T put(java.lang.Class<T> c, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
put
in interface UniformInterface
T
- the type of the response.c
- the type of the returned response.requestEntity
- the request entity.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T put(GenericType<T> gt, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
put
in interface UniformInterface
T
- the type of the response.gt
- the generic type of the returned response.requestEntity
- the request entity.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public void post() throws UniformInterfaceException, ClientHandlerException
UniformInterface
If the status code is less than 300 and a representation is present then that representation is ignored.
post
in interface UniformInterface
UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300.ClientHandlerException
- if the client handler fails to process
the request or response.public void post(java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
If the status code is less than 300 and a representation is present then that representation is ignored.
post
in interface UniformInterface
requestEntity
- the request entity.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T post(java.lang.Class<T> c) throws UniformInterfaceException, ClientHandlerException
UniformInterface
post
in interface UniformInterface
T
- the type of the response.c
- the type of the returned response.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T post(GenericType<T> gt) throws UniformInterfaceException, ClientHandlerException
UniformInterface
post
in interface UniformInterface
T
- the type of the response.gt
- the generic type of the returned response.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T post(java.lang.Class<T> c, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
post
in interface UniformInterface
T
- the type of the response.c
- the type of the returned response.requestEntity
- the request entity.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T post(GenericType<T> gt, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
post
in interface UniformInterface
T
- the type of the response.gt
- the generic type of the returned response.requestEntity
- the request entity.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public void delete() throws UniformInterfaceException, ClientHandlerException
UniformInterface
If the status code is less than 300 and a representation is present then that representation is ignored.
delete
in interface UniformInterface
UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300.ClientHandlerException
- if the client handler fails to process
the request or response.public void delete(java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
If the status code is less than 300 and a representation is present then that representation is ignored.
delete
in interface UniformInterface
requestEntity
- the request entity.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T delete(java.lang.Class<T> c) throws UniformInterfaceException, ClientHandlerException
UniformInterface
delete
in interface UniformInterface
T
- the type of the response.c
- the type of the returned response.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T delete(GenericType<T> gt) throws UniformInterfaceException, ClientHandlerException
UniformInterface
delete
in interface UniformInterface
T
- the type of the response.gt
- the generic type of the returned response.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T delete(java.lang.Class<T> c, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
delete
in interface UniformInterface
T
- the type of the response.c
- the type of the returned response.requestEntity
- the request entity.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T delete(GenericType<T> gt, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
delete
in interface UniformInterface
T
- the type of the response.gt
- the generic type of the returned response.requestEntity
- the request entity.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public void method(java.lang.String method) throws UniformInterfaceException, ClientHandlerException
UniformInterface
If the status code is less than 300 and a representation is present then that representation is ignored.
method
in interface UniformInterface
method
- the HTTP method.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300.ClientHandlerException
- if the client handler fails to process
the request or response.public void method(java.lang.String method, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
If the status code is less than 300 and a representation is present then that representation is ignored.
method
in interface UniformInterface
method
- the HTTP method.requestEntity
- the request entity.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T method(java.lang.String method, java.lang.Class<T> c) throws UniformInterfaceException, ClientHandlerException
UniformInterface
method
in interface UniformInterface
T
- the type of the response.method
- the HTTP method.c
- the type of the returned response.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T method(java.lang.String method, GenericType<T> gt) throws UniformInterfaceException, ClientHandlerException
UniformInterface
method
in interface UniformInterface
T
- the type of the response.method
- the HTTP method.gt
- the generic type of the returned response.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T method(java.lang.String method, java.lang.Class<T> c, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
method
in interface UniformInterface
T
- the type of the response.method
- the HTTP method.c
- the type of the returned response.requestEntity
- the request entity.c
.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and c
is not the type
ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public <T> T method(java.lang.String method, GenericType<T> gt, java.lang.Object requestEntity) throws UniformInterfaceException, ClientHandlerException
UniformInterface
method
in interface UniformInterface
T
- the type of the response.method
- the HTTP method.gt
- the generic type of the returned response.requestEntity
- the request entity.UniformInterfaceException
- if the status of the HTTP response is
greater than or equal to 300 and gt
does not
represent the type ClientResponse
.ClientHandlerException
- if the client handler fails to process
the request or response.public WebResource.Builder entity(java.lang.Object entity)
RequestBuilder
Any Java type instance for a request entity, that is supported by the client
configuration of the client, can be passed. If generic information is
required then an instance of GenericEntity
may
be used.
entity
in interface RequestBuilder<WebResource.Builder>
entity
- the request entitypublic WebResource.Builder entity(java.lang.Object entity, MediaType type)
RequestBuilder
Any Java type instance for a request entity, that is supported by the client
configuration of the client, can be passed. If generic information is
required then an instance of GenericEntity
may
be used.
entity
in interface RequestBuilder<WebResource.Builder>
entity
- the request entitytype
- the media typepublic WebResource.Builder entity(java.lang.Object entity, java.lang.String type)
RequestBuilder
Any Java type instance for a request entity, that is supported by the client
configuration of the client, can be passed. If generic information is
required then an instance of GenericEntity
may
be used.
entity
in interface RequestBuilder<WebResource.Builder>
entity
- the request entitytype
- the media typepublic WebResource.Builder type(MediaType type)
RequestBuilder
type
in interface RequestBuilder<WebResource.Builder>
type
- the media typepublic WebResource.Builder type(java.lang.String type)
RequestBuilder
type
in interface RequestBuilder<WebResource.Builder>
type
- the media typepublic WebResource.Builder accept(MediaType... types)
RequestBuilder
accept
in interface RequestBuilder<WebResource.Builder>
types
- an array of the acceptable media typespublic WebResource.Builder accept(java.lang.String... types)
RequestBuilder
accept
in interface RequestBuilder<WebResource.Builder>
types
- an array of the acceptable media typespublic WebResource.Builder acceptLanguage(java.util.Locale... locales)
RequestBuilder
acceptLanguage
in interface RequestBuilder<WebResource.Builder>
locales
- an array of the acceptable languagespublic WebResource.Builder acceptLanguage(java.lang.String... locales)
RequestBuilder
acceptLanguage
in interface RequestBuilder<WebResource.Builder>
locales
- an array of the acceptable languagespublic WebResource.Builder cookie(Cookie cookie)
RequestBuilder
cookie
in interface RequestBuilder<WebResource.Builder>
cookie
- to be set.public WebResource.Builder header(java.lang.String name, java.lang.Object value)
RequestBuilder
header
in interface RequestBuilder<WebResource.Builder>
name
- the HTTP header name.value
- the HTTP header value.public WebResource path(java.lang.String path)
Any filters on this web resource are inherited. Removal of filters may cause undefined behaviour.
path
- the additional path.public WebResource uri(java.net.URI uri)
If the URI contains a path component and the path starts with a '/' then the path of this web resource URI is replaced. Otherwise the path is appended.
If the URI contains query parameters then those query parameters will replace the query parameters (if any) of this web resource.
Any filters on this web resource are inherited. Removal of filters may cause undefined behaviour.
uri
- the URI.public WebResource queryParam(java.lang.String key, java.lang.String value)
key
- the query parameter namevalue
- the query parameter valuepublic WebResource queryParams(MultivaluedMap<java.lang.String,java.lang.String> params)
params
- the query parameters.public void setProperty(java.lang.String property, java.lang.Object value)
property
- property identifier.value
- value of given property.public java.util.Map<java.lang.String,java.lang.Object> getProperties()
Properties are inherited, so setting properties on "parent" WebResource instance, creating child (for example via WebResource.path("subpath")) will set parents properties on it. However changing child properties won't cause change in parent's properties.
Methods entrySet(), keySet() and values() are returning read-only results (via Collection.unmodifiableMap).
Copyright © 2016 Oracle Corporation. All Rights Reserved.