code: public List<Message> getMessages(final List<String> nodes) throws NoResponseException, XMPPErrorException, NotConnectedException, InterruptedException {
          List<Message> messages = new ArrayList<>(nodes.size());
          OfflineMessageRequest request = new OfflineMessageRequest();
          for (String node : nodes) {
              OfflineMessageRequest.Item item = new OfflineMessageRequest.Item(node);
              item.setAction("view");
              request.addItem(item);
          }
          // Filter offline messages that were requested by this request
          StanzaFilter messageFilter = new AndFilter(PACKET_FILTER, new StanzaFilter() {
              @Override
              public boolean accept(Stanza packet) {
                  OfflineMessageInfo info = packet.getExtension("offline",
                          namespace);
                  return nodes.contains(info.getNode());
              }
          });
          int pendingNodes = nodes.size();
          try (StanzaCollector messageCollector = connection.createStanzaCollector(messageFilter)) {
              connection.createStanzaCollectorAndSend(request).nextResultOrThrow();
              // Collect the received offline messages
              Message message;
              do {
                  message = messageCollector.nextResult();
                  if (message != null) {
                      messages.add(message);
                      pendingNodes--;
                  } else if (message == null && pendingNodes > 0) {
                      LOGGER.log(Level.WARNING,
                                      "Did not receive all expected offline messages. " + pendingNodes + " are missing.");
                  }
              } while (message != null && pendingNodes > 0);
          }
          return messages;
      }
docs: Returns a List of the offline <tt>Messages</tt> whose stamp matches the specified
  request. The request will include the list of stamps that uniquely identifies
  the offline messages to retrieve. The returned offline messages will not be deleted
  from the server. Use {@link #deleteMessages(java.util.List)} to delete the messages.
  
  @param nodes the list of stamps that uniquely identifies offline message.
  @return a List with the offline <tt>Messages</tt> that were received as part of
  this request.
  @throws XMPPErrorException If the user is not allowed to make this request or the server does
  not support offline message retrieval.
  @throws NoResponseException if there was no response from the server.
  @throws NotConnectedException
  @throws InterruptedException