These are chat archives for OfficeDev/ews-java-api

6th
Oct 2017
Jose Carlos
@josecyn
Oct 06 2017 09:01

@retor I did that a while ago, but maybe it helps you.

Subscribe to pull events:

        List  folder = new ArrayList();
        folder.add(new FolderId().getFolderIdFromWellKnownFolderName(WellKnownFolderName.Calendar));

        PullSubscription subscription = ExchangeClient.getExchangeService().subscribeToPullNotifications(folder,5, /* timeOut: the subscription will end if the server is not polled within 5 minutes. */
                null, /* watermark: null to start a new subscription. */
                EventType.Created,
                EventType.Modified,
                EventType.Deleted);

        LOG.info("Subscription successful Id: ! "+subscription.getId() + " - Watermark: ! "+subscription.getWaterMark());
        LOG.info("Starting thread...");
        new Thread(new RetrieveEvents(subscription)).start();

RetrieveEvents thread:

    @Override
    public void run() {
        LOG.info("Thread started!");
        try {
            LOG.info("Sleeping...");
            sleep (60000);
            LOG.info("Awake! Let's check the events!");
            // Wait a couple minutes, then poll the server for new events.
            GetEventsResults events = subscription.getEvents();

            if (events != null && events.getItemEvents() != null && events.getAllEvents().size() > 0) {
                // Loop through all item-related events.
                for (ItemEvent itemEvent : events.getItemEvents()) {
                    LOG.info("itemEvent id: " + itemEvent.getItemId());
                }
            }
            else {
                LOG.info("No result! :(");
            }
        }
        catch (Exception e) {
            LOG.error("Exception", e);
        }
    }
retor
@retor
Oct 06 2017 11:45
@josecyn thanks. Tomorrow I understand how to do it. And I do it on RxJava.
Here subscription is an object on server, what store updates and I can retrieve any updates from them.
Thanks
Sorry for my English. Yesterday not tomorrow)))))