Java Reference
In-Depth Information
System.out.println("----------- Customer test -----------");
Customer customer = ObjectFactory.createCustomer(customerIds[1]);
System.out.println(customer);
System.out.println("----------- Product test -----------");
Product product = ObjectFactory.createProduct(0);
System.out.println(product);
System.out.println("----------- Invoice test -----------");
Invoice invoice = ObjectFactory.createInvoice(0);
System.out.println(invoice);
System.out.println("----------- Invoice items test -----------");
System.out.println(invoice.getItems());
}
}
If you run this class, you should get something like the following:
----------- Collection test -----------
First three customer ids: 0, 1, 2
----------- Customer test -----------
Customer #1: King, Susanne - 366 - 20th Ave., Olten
----------- Product test -----------
Product #0: Iron Iron: priced at 5.4
----------- Invoice test -----------
Invoice #0: total sum 2607.6
Customer #0: Steel, Laura - 429 Seventh Av., Dallas
----------- Invoice items test -----------
[Item: quantity: 12, cost: 12.6
Invoice #0: total sum 2607.6
Customer #0: Steel, Laura -- 429 Seventh Av., Dallas
Product #7: Telephone Shoe: priced at 8.4, Item: quantity: 19, cost: 18.6
Invoice #0: total sum 2607.6
Customer #0: Steel, Laura -- 429 Seventh Av., Dallas
Product #14: Telephone Iron: priced at 12.4, Item: quantity: 3, cost: 26.7
That's all there is to the basics of accessing RESTful web services. Note that the essential code is
found in the RestServiceClient class, where the HttpUrlConnection class is used to establish the
connection. All the other classes deal with parsing the responses received from the server and estab-
lishing an object representation for them.
Note If you've already worked through the previous chapter on data-
bases, you might recognize that what is built here is quite similar to Object
Relational Mapping (ORM), where the relational structure of a database is
mapped to objects in Java, abstracting the aspect of having to deal with SQL
manually by or and just working with plain objects and their methods. What
you're doing here is similar: abstracting communication with the REST service
in a separate class.
Search WWH ::




Custom Search