com.sun.jersey.api.client
Class WebResource

java.lang.Object
  extended by com.sun.jersey.api.client.filter.Filterable
      extended by com.sun.jersey.api.client.WebResource
All Implemented Interfaces:
RequestBuilder<WebResource.Builder>, UniformInterface

public final class WebResource
extends Filterable
implements RequestBuilder<WebResource.Builder>, UniformInterface

An encapsulation of a Web resource capable of building requests to send to the Web resource and processing responses returned from the Web resource.

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.

Author:
Paul.Sandoz@Sun.Com

Nested Class Summary
 class WebResource.Builder
          The builder for building a ClientRequest instance and handling the request using the UniformInterface.
 
Method Summary
 WebResource.Builder accept(javax.ws.rs.core.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(javax.ws.rs.core.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, javax.ws.rs.core.MediaType type)
          Set the request entity it's media type.
 WebResource.Builder entity(java.lang.Object entity, java.lang.String type)
          Set the request entity it's media type.
<T> T
get(java.lang.Class<T> c)
          Invoke the GET method.
<T> T
get(GenericType<T> gt)
          Invoke the GET method.
 javax.ws.rs.core.UriBuilder getBuilder()
          Get the URI builder to the resource.
 java.net.URI getURI()
          Get the URI to the resource.
 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.Builder type(javax.ws.rs.core.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.
 
Methods inherited from class com.sun.jersey.api.client.filter.Filterable
addFilter, getHeadHandler, removeAllFilters, removeFilter
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

getURI

public java.net.URI getURI()
Get the URI to the resource.

Returns:
the URI.

getBuilder

public javax.ws.rs.core.UriBuilder getBuilder()
Get the URI builder to the resource.

Returns:
the URI builder.

head

public ClientResponse head()
Description copied from interface: UniformInterface
Invoke the HEAD method.

Specified by:
head in interface UniformInterface
Returns:
the HTTP response.

options

public <T> T options(java.lang.Class<T> c)
Description copied from interface: UniformInterface
Invoke the OPTIONS method.

Specified by:
options in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
c - the type of the returned response.
Returns:
an instance of type c.

options

public <T> T options(GenericType<T> gt)
Description copied from interface: UniformInterface
Invoke the OPTIONS method.

Specified by:
options in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
gt - the generic type of the returned response.
Returns:
an instance of type represented by the generic type.

get

public <T> T get(java.lang.Class<T> c)
Description copied from interface: UniformInterface
Invoke the GET method.

Specified by:
get in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
c - the type of the returned response.
Returns:
an instance of type c.

get

public <T> T get(GenericType<T> gt)
Description copied from interface: UniformInterface
Invoke the GET method.

Specified by:
get in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
gt - the generic type of the returned response.
Returns:
an instance of type represented by the generic type.

put

public void put()
Description copied from interface: UniformInterface
Invoke the PUT method with no request entity or response.

If the status code is less than 300 and a representation is present then that representation is ignored.

Specified by:
put in interface UniformInterface

put

public void put(java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the PUT method with a request entity but no response.

If the status code is less than 300 and a representation is present then that representation is ignored.

Specified by:
put in interface UniformInterface
Parameters:
requestEntity - the request entity.

put

public <T> T put(java.lang.Class<T> c)
Description copied from interface: UniformInterface
Invoke the PUT method with no request entity that returns a response.

Specified by:
put in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
c - the type of the returned response.
Returns:
an instance of type c.

put

public <T> T put(GenericType<T> gt)
Description copied from interface: UniformInterface
Invoke the PUT method with a request entity that returns a response.

Specified by:
put in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
gt - the generic type of the returned response.
Returns:
an instance of type represented by the generic type.

put

public <T> T put(java.lang.Class<T> c,
                 java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the PUT method with a request entity that returns a response.

Specified by:
put in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
c - the type of the returned response.
requestEntity - the request entity.
Returns:
an instance of type c.

put

public <T> T put(GenericType<T> gt,
                 java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the PUT method with a request entity that returns a response.

Specified by:
put in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
gt - the generic type of the returned response.
requestEntity - the request entity.
Returns:
an instance of type represented by the generic type.

post

public void post()
Description copied from interface: UniformInterface
Invoke the POST method with no request entity or response.

If the status code is less than 300 and a representation is present then that representation is ignored.

Specified by:
post in interface UniformInterface

post

public void post(java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the POST method with a request entity but no response.

If the status code is less than 300 and a representation is present then that representation is ignored.

Specified by:
post in interface UniformInterface
Parameters:
requestEntity - the request entity.

post

public <T> T post(java.lang.Class<T> c)
Description copied from interface: UniformInterface
Invoke the POST method with no request entity that returns a response.

Specified by:
post in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
c - the type of the returned response.
Returns:
an instance of type c.

post

public <T> T post(GenericType<T> gt)
Description copied from interface: UniformInterface
Invoke the POST method with a request entity that returns a response.

Specified by:
post in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
gt - the generic type of the returned response.
Returns:
an instance of type represented by the generic type.

post

public <T> T post(java.lang.Class<T> c,
                  java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the POST method with a request entity that returns a response.

Specified by:
post in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
c - the type of the returned response.
requestEntity - the request entity.
Returns:
an instance of type c.

post

public <T> T post(GenericType<T> gt,
                  java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the POST method with a request entity that returns a response.

Specified by:
post in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
gt - the generic type of the returned response.
requestEntity - the request entity.
Returns:
an instance of type represented by the generic type.

delete

public void delete()
Description copied from interface: UniformInterface
Invoke the DELETE method with no request entity or response.

If the status code is less than 300 and a representation is present then that representation is ignored.

Specified by:
delete in interface UniformInterface

delete

public void delete(java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the DELETE method with a request entity but no response.

If the status code is less than 300 and a representation is present then that representation is ignored.

Specified by:
delete in interface UniformInterface
Parameters:
requestEntity - the request entity.

delete

public <T> T delete(java.lang.Class<T> c)
Description copied from interface: UniformInterface
Invoke the DELETE method with no request entity that returns a response.

Specified by:
delete in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
c - the type of the returned response.
Returns:
an instance of type c.

delete

public <T> T delete(GenericType<T> gt)
Description copied from interface: UniformInterface
Invoke the DELETE method with a request entity that returns a response.

Specified by:
delete in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
gt - the generic type of the returned response.
Returns:
an instance of type represented by the generic type.

delete

public <T> T delete(java.lang.Class<T> c,
                    java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the DELETE method with a request entity that returns a response.

Specified by:
delete in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
c - the type of the returned response.
requestEntity - the request entity.
Returns:
an instance of type c.

delete

public <T> T delete(GenericType<T> gt,
                    java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke the DELETE method with a request entity that returns a response.

Specified by:
delete in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
gt - the generic type of the returned response.
requestEntity - the request entity.
Returns:
an instance of type represented by the generic type.

method

public void method(java.lang.String method)
Description copied from interface: UniformInterface
Invoke a HTTP method with no request entity or response.

If the status code is less than 300 and a representation is present then that representation is ignored.

Specified by:
method in interface UniformInterface
Parameters:
method - the HTTP method.

method

public void method(java.lang.String method,
                   java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke a HTTP method with a request entity but no response.

If the status code is less than 300 and a representation is present then that representation is ignored.

Specified by:
method in interface UniformInterface
Parameters:
method - the HTTP method.
requestEntity - the request entity.

method

public <T> T method(java.lang.String method,
                    java.lang.Class<T> c)
Description copied from interface: UniformInterface
Invoke a HTTP method with no request entity that returns a response.

Specified by:
method in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
method - the HTTP method.
c - the type of the returned response.
Returns:
an instance of type c.

method

public <T> T method(java.lang.String method,
                    GenericType<T> gt)
Description copied from interface: UniformInterface
Invoke a HTTP method with no request entity that returns a response.

Specified by:
method in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
method - the HTTP method.
gt - the generic type of the returned response.
Returns:
an instance of type represented by the generic type.

method

public <T> T method(java.lang.String method,
                    java.lang.Class<T> c,
                    java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke a HTTP method with a request entity that returns a response.

Specified by:
method in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
method - the HTTP method.
c - the type of the returned response.
requestEntity - the request entity.
Returns:
an instance of type c.

method

public <T> T method(java.lang.String method,
                    GenericType<T> gt,
                    java.lang.Object requestEntity)
Description copied from interface: UniformInterface
Invoke a HTTP method with a request entity that returns a response.

Specified by:
method in interface UniformInterface
Type Parameters:
T - the type of the response.
Parameters:
method - the HTTP method.
gt - the generic type of the returned response.
requestEntity - the request entity.
Returns:
an instance of type represented by the generic type.

entity

public WebResource.Builder entity(java.lang.Object entity)
Description copied from interface: RequestBuilder
Set the request entity.

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.

Specified by:
entity in interface RequestBuilder<WebResource.Builder>
Parameters:
entity - the request entity
Returns:
the builder.

entity

public WebResource.Builder entity(java.lang.Object entity,
                                  javax.ws.rs.core.MediaType type)
Description copied from interface: RequestBuilder
Set the request entity it's media type.

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.

Specified by:
entity in interface RequestBuilder<WebResource.Builder>
Parameters:
entity - the request entity
type - the media type
Returns:
the builder.

entity

public WebResource.Builder entity(java.lang.Object entity,
                                  java.lang.String type)
Description copied from interface: RequestBuilder
Set the request entity it's media type.

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.

Specified by:
entity in interface RequestBuilder<WebResource.Builder>
Parameters:
entity - the request entity
type - the media type
Returns:
the builder.

type

public WebResource.Builder type(javax.ws.rs.core.MediaType type)
Description copied from interface: RequestBuilder
Set the media type.

Specified by:
type in interface RequestBuilder<WebResource.Builder>
Parameters:
type - the media type
Returns:
the builder.

type

public WebResource.Builder type(java.lang.String type)
Description copied from interface: RequestBuilder
Set the media type.

Specified by:
type in interface RequestBuilder<WebResource.Builder>
Parameters:
type - the media type
Returns:
the builder.

accept

public WebResource.Builder accept(javax.ws.rs.core.MediaType... types)
Description copied from interface: RequestBuilder
Add acceptable media types.

Specified by:
accept in interface RequestBuilder<WebResource.Builder>
Parameters:
types - an array of the acceptable media types
Returns:
the builder.

accept

public WebResource.Builder accept(java.lang.String... types)
Description copied from interface: RequestBuilder
Add acceptable media types.

Specified by:
accept in interface RequestBuilder<WebResource.Builder>
Parameters:
types - an array of the acceptable media types
Returns:
the builder.

acceptLanguage

public WebResource.Builder acceptLanguage(java.util.Locale... locales)
Description copied from interface: RequestBuilder
Add acceptable languages

Specified by:
acceptLanguage in interface RequestBuilder<WebResource.Builder>
Parameters:
locales - an array of the acceptable languages
Returns:
the builder.

acceptLanguage

public WebResource.Builder acceptLanguage(java.lang.String... locales)
Description copied from interface: RequestBuilder
Add acceptable languages

Specified by:
acceptLanguage in interface RequestBuilder<WebResource.Builder>
Parameters:
locales - an array of the acceptable languages
Returns:
the builder.

cookie

public WebResource.Builder cookie(javax.ws.rs.core.Cookie cookie)
Description copied from interface: RequestBuilder
Add a cookie to be set.

Specified by:
cookie in interface RequestBuilder<WebResource.Builder>
Parameters:
cookie - to be set.
Returns:
the builder

header

public WebResource.Builder header(java.lang.String name,
                                  java.lang.Object value)
Description copied from interface: RequestBuilder
Add an HTTP header and value.

Specified by:
header in interface RequestBuilder<WebResource.Builder>
Parameters:
name - the HTTP header name.
value - the HTTP header value.
Returns:
the builder.

path

public 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.

Any filters on this web resource are inherited. Removal of filters may cause undefined behaviour.

Parameters:
path - the additional path.
Returns:
the new web resource.

uri

public WebResource uri(java.net.URI uri)
Create a new WebResource from this web resource.

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.

Parameters:
uri - the URI.
Returns:
the new web resource.


Copyright © 2008 Sun Microsystems, Inc. All Rights Reserved.