Java Reference
In-Depth Information
If there are more possible customer instances left to be viewed, a next link relationship is
calculated using the UriBuilder template defined earlier. A similar calculation is done to
see if a previous link relationship needs to be added to the document.
Customers customers = new
new Customers ();
customers . setCustomers ( list );
customers . setLinks ( links );
return customers ;
Finally, a Customers instance is created and initialized with the Customer list and link rela-
tionships and returned to the client.
The Client Code
The client initially gets the XML document from the /customers URL. It then loops using
the next link relationship as the URL to print out all the customers in the database:
public class
class CustomerResourceTest
public void
void testQueryCustomers () throws
throws Exception
URI uri = new
new URI ( "http://localhost:8080/services/customers" );
while ( uri != null
null )
WebTarget target = client . target ( uri );
String output = target . request (). get ( String . class );
System . out . println ( "** XML from " + uri . toString ());
System . out . println ( output );
Customers customers = target . request (). get ( Customers . class );
uri = customers . getNext ();
An interesting thing to note about this is that the server is guiding the client to make state
transitions as it browses the customer database. Once the initial URL is invoked, further
queries are solely driven by Atom links.
Build and Run the Example Program
Perform the following steps:
Search WWH ::

Custom Search