7273747576777879808182
return singleton.getMessages(); } @POST public Response addMessage(String msg) throws URISyntaxException { Message m = singleton.addMessage(msg); URI msgURI = ui.getRequestUriBuilder().path(Integer.toString(m.getUniqueId())).build(); return Response.created(msgURI).build(); }
8283848586878889909192
} @Path("{msgNum}") @GET public Message getMessage(@PathParam("msgNum") int msgNum) { Message m = singleton.getMessage(msgNum); if(m == null) { // This exception will be passed through to the JAX-RS runtime // No other runtime exception will behave this way unless the // exception is annotated with javax.ejb.ApplicationException
8586878889909192939495
public synchronized Message addMessage(String msg) { return addMessage(msg, new Date()); } private synchronized Message addMessage(String msg, Date date) { Message m = new Message(date, msg, getNewId()); list.addFirst(m); return m; }
949596979899100101102103104
return m; } public Message getMessage(int uniqueId) { int index = 0; Message m; while(index < list.size()) { if((m = list.get(index)).getUniqueId() == uniqueId) return m; index++;