Java Reference
In-Depth Information
figure 10-19  
As you can observe, your browser is making simple HTTP GET requests to specified, agreed‐upon
URLs and getting back structured information, in this case formatted as XML.
To access REST web services using Java, you'll need a way to work with the HTTP protocol
directly. Many good libraries exist to do so, but for now, take a look at Java's built‐in HTTP con-
nection class: java.net.HttpURLConnection . Create a new project in Eclipse— RESTWithJava
and use it throughout this section.
Instead of writing Java code like a script (as you've done before to show off SOAP services), make
sure the resources you request from the web service are immediately converted to objects, which is
the proper object‐oriented way to go. If you take a look at the web service, you'll see that it defines
four kinds of resources:
A customer: With an ID, first name, last name, street, and city
An invoice: With an ID, which is the customer ID the invoice relates to and a total sum
A product: With an ID, name, and price
An item line: Relates to an invoice, a product, quantity, and total cost
You can verify this by exploring the other URLs in your browser. You should create classes to rep-
resent each of these and place them in the com.thomasbayer.sqlrest package, starting with a
customer:
package com.thomasbayer.sqlrest;
public class Customer {
private int id;
private String firstName, lastName;
Search WWH ::




Custom Search