Version 2

    Custom client-side Responses

     

    Sometimes you are interested not only in the response body of a client request, but also either the response code and/or response headers.  The Client-Proxy framework has two ways to get at this information

     

    Response codes

     

    You may return a javax.ws.rs.core.Response.Status enumeration from your method calls:

     

    
    @Path("/")
    public interface MyProxy {
    
       @POST
       Response.Status updateSite(MyPojo pojo);
    }
    

     

    Interally, after invoking on the server, the client proxy internals will convert the HTTP response code into a Response.Status enum.

     

    ClientResponse object

     

    If you are interested in everything, you can get it with the org.resteasy.spi.ClientResponse interface:

     

    
    /**
     * Response interface for the RESTEasy client framework.  Use this in your client proxy interface method return type
     * declarations if you want access to the response entity as well as status and header information.
     *
     * @author <a href="mailto:bill@burkecentral.com">Bill Burke</a>
     * @version $Revision: 1 $
     */
    public interface ClientResponse<T>
    {
       T getEntity();
    
       MultivaluedMap<String, String> getHeaders();
    
       int getStatus();
    }
    
    
    

     

    You must use it as a generic with the entity body type you are interested in receiving back from the response unmarshalling layer.  Here's an example

     

    @Path("/")
    public interface LibraryService {
    
      @GET
      @ProduceMime("application/xml")
      ClientResponse<LibraryPojo> getAllBooks();
    }
    

     

    We need to include the LibraryPojo in ClientResponse's generic declaration so that the client proxy framework knows how to unmarshal the HTTP response body.  We could not reuse the javax.ws.rs.core.Response class because it is not a Java generic and we would have had no way to get this type information.