Apache Wink : 6.1 Getting Started with Apache Wink Client
This page last changed on Oct 13, 2009 by michael.
The following section details the getting started examples that demonstrate how to write a simple client that consume RESTful Web Services with the Apache Wink Client.
The following example demonstrates how to issue an Http GET request.
The RestClient is the entry point for building a RESTful Web Service client. In order to start working with the Wink Client, a new instance of RestClient needs to be created, as the example shows in line 1 of the example. A new Resource is then created with the given URI, by calling the RestClient#resource() method as appears in line 2.
Finally, the Resource#get() method is invoked in order to issue an Http GET request as appears in line 3.
The following example demonstrates how to issue an Http POST request.
The POST Request example demonstrates how to issue a simple Http POST request that sends and receives resources as strings.
First, a new instance of a Resource is created through the RestClient. The Http POST request is then issued by specifying the request and response media types and the response entity type (String.class).
The following example demonstrates how to issue an Http POST request that sends and receives atom entries.
The Apache Wink Client provides an object model for Atom (atom feed and atom entry), and supplies out-of-the-box providers that enable sending and receiving atom feeds and entries.
The following example demonstrates how to use the ClientResponse object in order to de-serialize the response entity.
If the response entity type is not provided when invoking the Resource#get() method that appears in line 3, the response will be returned as the raw ClientResponse. In order to trigger the response deserialization mechanism, the ClientResponse#getEntity() method needs to be invoked as it appears in line 4 with the required response entity type.
|Document generated by Confluence on Nov 11, 2009 06:57|