Esempio n. 1
0
 private Book doGetBook(String id) throws BookNotFoundFault {
   Book book = books.get(Long.parseLong(id));
   if (book != null) {
     return book;
   } else {
     BookNotFoundDetails details = new BookNotFoundDetails();
     details.setId(Long.parseLong(id));
     throw new BookNotFoundFault(details);
   }
 }
  public Book getBook(Long id) throws BookNotFoundFault {

    if (books.get(id) == null) {
      BookNotFoundDetails details = new BookNotFoundDetails();
      details.setId(id);
      if (!isRest) {
        throw new BookNotFoundFault("Can't find the Book with id " + id, details);
      } else {
        Response r =
            Response.status(404)
                .header("BOOK-HEADER", "No Book with id " + id + " is available")
                .entity(details)
                .build();
        throw new WebApplicationException(r);
      }
    }

    return books.get(id);
  }