Java Reference
In-Depth Information
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
</web-app>
This simply means that if we were to deploy our former example, the HTTP GET method,
http://host/example/rest/users would trigger our getUser business meth-
od, while the same URL will place a request through the handlePOSTRequest meth-
od using a POST request.
Adding REST to our ticket example
With all the configurations in place, we can now add a simple REST web service to our
Ticket Web Service project, which will provide the same functionalities as our
SOAP web service.
So add a new class to your project and name it SeatsResource . The code for this is as
follows:
package com.packtpub.wflydevelopment.chapter7.boundary;
@Path("/seat")
@Produces(MediaType.APPLICATION_JSON)
@RequestScoped
public class SeatsResource {
@Inject
private TheatreBooker theatreBooker;
@Inject
private TheatreBox theatreBox;
@GET
public Collection<SeatDto> getSeatList() {
return theatreBox.getSeats()
.stream()
.map(SeatDto::fromSeat)
.collect(Collectors.toList());
Search WWH ::




Custom Search