Java Reference
In-Depth Information
WARNING
Always remember to close() your Response objects. Response objects reference open socket
streams. If you do not close them, you are leaking system resources. While most JAX-RS imple-
mentations implement a finalize() method for Response , it is not a good idea to rely on the
garbage collector to clean up poorly written code. The default behavior of the RESTEasy JAX-RS
implementation actually only lets you have one open Response per Client instance. This forces
you to write responsible client code.
So far we haven't discussed PUT and POST requests that submit a representation to the serv-
er. These types of requests have similar method styles to GET but also specify an entity para-
meter:
< T > T put ( Entity <?> entity , Class < T > responseType );
< T > T put ( Entity <?> entity , GenericType < T > responseType );
< T > T post ( Entity <?> entity , Class < T > responseType );
< T > T post ( Entity <?> entity , GenericType < T > responseType );
Response post ( Entity <?> entity );
Response put ( Entity <?> entity );
The Entity class encapsulates the Java object we want to send with the POST or GET re-
quest:
package
package javax . ws . rs . client ;
public
public final
final class
class Entity
Entity < T > {
public
public Variant getVariant () {}
public
public MediaType getMediaType () {
public
public String getEncoding () {
public
public Locale getLanguage () {
public
public T getEntity () {
public
public Annotation [] getAnnotations () { }
...
}
The Entity class does not have a public constructor. You instead have to invoke one of the
static convenience methods to instantiate one:
package
package javax . ws . rs . client ;
import
import javax.ws.rs.core.Form
javax.ws.rs.core.Form ;
public
public final
final class
class Entity
Entity < T > {
Search WWH ::




Custom Search