* To see the demo, run RestLiFortuneServer, then start the client
*/
public static void main(String[] args) throws Exception
{
// Create an HttpClient and wrap it in an abstraction layer
final HttpClientFactory http = new HttpClientFactory(FilterChains.create(
new ClientCompressionFilter(EncodingType.IDENTITY, new EncodingType[]{ EncodingType.SNAPPY}, Collections.singletonList("*"))
));
final Client r2Client = new TransportClientAdapter(
http.getClient(Collections.<String, String>emptyMap()));
// Create a RestClient to talk to localhost:8080
RestClient restClient = new RestClient(r2Client, "http://localhost:8080/");
// Generate a random ID for a fortune cookie, in the range 0-5
long fortuneId = (long) (Math.random() * 5);
// Construct a request for the specified fortune
FortunesGetBuilder getBuilder = _fortuneBuilder.get();
Request<Fortune> getReq = getBuilder.id(fortuneId).build();
// Send the request and wait for a response
final ResponseFuture<Fortune> getFuture = restClient.sendRequest(getReq);
final Response<Fortune> resp = getFuture.getResponse();
// Print the response
System.out.println(resp.getEntity().getFortune());
// shutdown
restClient.shutdown(new FutureCallback<None>());
http.shutdown(new FutureCallback<None>());
}