Sun GlassFish Mobility Platform 1.1 Developer's Guide for Client Applications

The WebResource Class

Table 5–4 lists the methods in the WebResource class, which implements a web resource on which the HTTP methods GET, PUT, POST, DELETE and HEAD can be called. To create an instance of this class, call the Client.resource(String) method. This class implements the UniformInterface interface. Only the lastGetCached method is specific to this class.

Table 5–4 Class com.sun.jerseyme.api.client.WebResource

Method 

Description 

public UniformInterface accept(java.lang.String type)

Adds an accept type to the list prepared for the next HTTP GET request. 

UniformInterface acceptLanguage(java.lang.String type)

Sets a value for the HTTP header Accept-Language. 

UniformInterface cookie(java.lang.String type)

Sets a value for the HTTP header Cookie. 

void delete()

Deletes an empty resource without returning any content. Uses X-HTTP-Method-Override to override POST operation. 

java.lang.Object delete(java.lang.Class c)

Deletes a resource without returning any content. The argument must be an instance of String, InputStream, or byte[]. If the argument is of type String, the platform's default character set is used for encoding. Uses X-HTTP-Method-Override to override POST operation.

java.lang.Object delete(java.lang.Class c, java.lang.Object o)

Deletes a resource. The first argument specifies the class of the instance returned and must be String, InputStream, or byte[]. The second argument must be an instance of String, InputStream, or byte[]. If the result or the argument is of type String, the platform's default character set is used for decoding. Uses X-HTTP-Method-Override to override POST operation.

void delete(java.lang.Object o)

Posts a resource without returning any content. The argument must be an instance of String, InputStream, or byte[]. If the argument is of type String, the platform's default character set is used for encoding.

java.lang.Object get(java.lang.Class c)

Gets a resource by first looking it up in the local cache. If the resource is available locally and it isn't stale, it is returned. If it is stale, it will be re-fetched. If it can't be re-fetched, its stale copy is returned. The argument specifies the class of the instance returned; it must be String, InputStream, or byte[].

java.lang.Object get(java.lang.Class c, boolean ignoreCache)

Same as get(Class) except that you can force the local cache to be ignored by setting the second parameter to true. The first argument specifies the class of the instance returned; it must be String, InputStream, or byte[]. The second argument is a flag that indicates whether or not the cache should be inspected.

java.util.Hashtable head()

Calls the HEAD operation on the resource, returning a hash table of headers. 

public boolean lastGetCached()

Returns a boolean value that indicates whether the last HTTP GET operation was resolved using the local cache. 

void post()

Posts an empty resource without returning any content. 

java.lang.Object post(java.lang.Class c)

Posts an empty resource. If the result is of type String, the platform's default character set is used for decoding. The argument specifies the class of the instance returned; it must be String, InputStream, or byte[].

java.lang.Object post(java.lang.Class c, java.lang.Object o)

Posts a resource. If the result or the parameter is of type String, the platform's default character set is used for decoding. The first argument specifies the class of the instance returned; it must be String, InputStream, or byte[]. The second argument must be an instance of String, InputStream, or byte[].

void post(java.lang.Object o)

Posts a resource without returning any content. If the parameter is of type String, the platform's default character set is used for encoding. The argument must be an instance of String, InputStream, or byte[].

void put()

Puts an empty resource without returning any content. Uses X-HTTP-Method-Override to override a POST operation. 

java.lang.Object put(java.lang.Class c)

Puts an empty resource. If the result is of type String, the platform's default character set is used for decoding. Uses X-HTTP-Method-Override to override a POST operation. The argument specifies the class of the instance returned; it must be String, InputStream, or byte[].

java.lang.Object put(java.lang.Class c, java.lang.Object o)

Puts a resource. If the result or the argument is of type String, the platform's default character set is used for decoding. Uses X-HTTP-Method-Override to override a POST operation. The first argument specifies the class of the instance returned; it must be String, InputStream, or byte[]. The second argument must be an instance of String, InputStream, or byte[].

void put(java.lang.Object o)

Puts a resource without returning any content. If the argument is of type String, the platform's default character set is used for encoding. Uses X-HTTP-Method-Override to override a POST operation. The argument must be an instance of String, InputStream, or byte[].

UniformInterface type(java.lang.String type)

Sets the value for HTTP header Content-Type.