Java Reference
In-Depth Information
19:52:45,906 INFO
[com.packtpub.wflydevelopment.chapter7.controller.LoggingRestFilter]
(default task-10) GET on /seat
19:52:45,909 INFO
[com.packtpub.wflydevelopment.chapter7.controller.LoggingRestFilter]
(default task-10) OK
20:29:04,275 INFO
[com.packtpub.wflydevelopment.chapter7.controller.LoggingRestFilter]
(default task-14) GET on /account
20:29:04,313 INFO
[com.packtpub.wflydevelopment.chapter7.controller.LoggingRestFilter]
(default task-14) OK
Consuming our REST service
Connecting to a RESTful web service takes no more work than directly connecting to the
service through an HTTP connection. For this reason, you can use plenty of APIs to ac-
cess your REST services, such as the JDK URLConnection class or Jakarta Commons
HttpClient API, since we have a standardized client available in JAX-RS.
If you want to retrieve the list of Seats from your REST service, your code should look
like this:
Client restclient = ClientBuilder.newClient();
WebTarget seatResource = restclient.target(APPLICATION_URL
+ "seat");
Collection<SeatDto> seats = seatResource.request().get(new
GenericType<Collection<SeatDto>>() {});
The previous code will simply perform a GET action to the REST service that is deployed
as part of the ticket-agency-ws web application. RESTEasy (using Jackson) will
transform the JSON objects.
The following standalone sample will get the data from the account and seat resources and
attempt to book all of the available seats:
public class RestServiceTestApplication {
private static final String APPLICATION_URL =
"http://localhost:8080/ticket-agency-ws/rest/";
Search WWH ::




Custom Search