Java Reference
In-Depth Information
• Values of elements come in pairs having the structure of name:value and
are comma separated
• Arrays are enclosed with square brackets ( [ and ] )
That's all there is to it. (For the full JSON grammar description, see ht-
tp://www.json.org/ .)
The second method included in this class is buyTicket that will be used to invoke
the corresponding buyTicket class of our EJB. This method, on the other hand, is
bound to the following HTTP POST method:
@POST
@Path("/{id:\\d+}")
@Produces(MediaType.APPLICATION_JSON)
public Response buyTicket(@PathParam("id") int
id)
You might be thinking that this Path expression seems a bit weird, but all it does is
map a URI numeric parameter (included in the Path expression) to a method para-
meter. In short, the parameter that is included in the URL will be passed to the meth-
od in the ID variable.
The previous method also returns a JSON-formatted string that we will get decoded
on the client side using a simple Java library.
Now the REST service is complete and we can start deploying it in the usual way:
mvn install jboss-as:deploy
If you followed all the steps so far, the following GET method issued by your browser
should print out the list of available seats:
[{"id":0,"seatName":"Stalls","price":40,"booked":false},{"id":1,"seatName":"Stalls","price":40,"booked":false},{"id":2,"seatName":"Stalls","price":40,"booked":false},{"id":3,"seatName":"Stalls","price":40,"booked":false},{"id":4,"seatName":"Stalls","price":40,"booked":false},
. . . . . .
Search WWH ::




Custom Search