Java Reference
In-Depth Information
/**
* Gets three different representations of the same
* resource (Duke): HTML, XML, and an image.
* Note that all three methods point to the exact same URL,
* and specify only a different "Accept" header; there's no
* query parameter, etc.
*
* This class is used with DifferentRepresentations.java which
* is the REST service.
*/
public class DifferentRepClient {
private static String RESOURCE_URL =
"http://localhost:8080/restexamples/resources/duke";
//client path to save image in current execution dir
private static String SAVE_TO =
System.getProperty("user.dir") + "/dukeClient.gif";
/**
* Use with HTTP client in Apache Commons to
* get alternative content from DifferentRepresentations
* REST service.
*/
public static void main(String... args) {
getXml();
System.out.println("Got XML. Now getting HTML...");
getHtml();
System.out.println("Now getting image...");
getImage();
//now that it's saved on client, show image:
new ImageViewer(SAVE_TO).show();
System.out.println("All done.");
}
private static void getXml() {
HttpClient client = new HttpClient();
GetMethod get = new GetMethod(RESOURCE_URL);
get.setRequestHeader("Accept", "text/xml");
try {
int httpStatus = client.executeMethod(get);
Search WWH ::




Custom Search