Пример #1
0
 @GET
 @Produces(MediaType.APPLICATION_JSON)
 public Response addBook(@QueryParam("bookIsbn") String bookIsbn) {
   System.out.println("Add book called " + bookIsbn);
   Book book = null;
   try {
     Volumes volumes = BooksFinder.queryGoogleBooksByIsbn(bookIsbn);
     List<Volume> items = volumes.getItems();
     if (items.size() > 0) {
       Volume volume = items.get(0);
       Volume.VolumeInfo volumeInfo = volume.getVolumeInfo();
       String infoLink = volumeInfo.getInfoLink();
       System.out.println("infoLink " + infoLink);
       Volume.VolumeInfo.ImageLinks imageLinks = volumeInfo.getImageLinks();
       System.out.println("volumelinks " + imageLinks);
       book =
           new Book(
               volumeInfo.getTitle(),
               bookIsbn,
               volumeInfo.getAuthors().toString(),
               volumeInfo.getPublishedDate());
       bookService.createBook(book.getTitle(), book.getIsbn(), book.getAuthor(), book.getYear());
     }
   } catch (Exception e) {
     e.printStackTrace();
     return Response.status(Response.Status.BAD_REQUEST).build();
   }
   return Response.ok(book).build();
 }
  public RechercheLivreGoogle(String demande) {

    JsonFactory jsonFactory = JacksonFactory.getDefaultInstance();

    try {

      if (demande.length() == 13 || demande.length() == 10) {
        demande = "isbn:" + demande;
      }

      // Création de la demande
      final Books books =
          new Books.Builder(GoogleNetHttpTransport.newTrustedTransport(), jsonFactory, null)
              .setApplicationName(NOM_APPLICATION)
              .setGoogleClientRequestInitializer(new BooksRequestInitializer(API_KEY))
              .build();
      System.out.println("Demande: [" + demande + "]");
      List listVolumes = books.volumes().list(demande);

      // Envoie de la demande
      Volumes volumes = listVolumes.execute();

      lesVolumes = volumes.getItems();

    } catch (Exception e) {
    }
  }