来自 subscribeToStreamingNotifications 的 Item.bind() 拒绝访问

AccessDenied with Item.bind() from subscribeToStreamingNotifications

我们通过以下方法使用 MS Exchange 2016 订阅流式通知:

 service.subscribeToStreamingNotificationsOnAllFolders(EventType.Copied,EventType.Created, EventType.Deleted, EventType.Modified, EventType.Moved, EventType.NewMail);

                switch (itemEvent.getEventType()) {
                    case Deleted:
                        delete(mailbox, itemEvent.getItemId());
                        break;
                    case Moved:
                        try {
                            delete(mailbox, itemIdNoChangeKey(itemEvent.getOldItemId()));
                        } finally {
                            create(mailbox, Item.bind(service, itemIdNoChangeKey(itemEvent.getItemId())));
                        }
                        break;
                    case Modified:
                        update(mailbox, Item.bind(service, itemIdNoChangeKey(itemEvent.getItemId()), itemProp()));
                        break;
                    case Copied:
                    case Created:
                        create(mailbox, Item.bind(service, itemIdNoChangeKey(itemEvent.getItemId()), itemProp()));
                        break;
                }

有时上面的调用会成功,但通常情况下,Items.bind() 会失败,原因是:

"Access is denied. Check credentials and try again., The process failed to get the correct properties.,errorCode='ErrorAccessDenied'"

"The specified object was not found in the store., The process failed to get the correct properties.,errorCode='ErrorItemNotFound'"

尽管

谁能告诉我们为什么我们会收到 ErrorAccessDenied 和 ErrorItemNotFound 错误?是否与 Exchange 系统相关的消息或文件夹的处理有关?我们如何处理这些项目,或者如果我们不能,如何跳过它们而不会对 Exchange 服务器造成不必要的负载?

就我而言,我的代码模拟了错误的邮箱。事实证明,我需要维护一张地图如下:

 private Map<StreamingSubscription, String> reverseSubscriptions = Collections.synchronizedMap(new HashMap<>());

然后在 notificationEventDelegate(..) 方法中...

致电

String mailbox = reverseSubscriptions.get(args.getSubscription());

处理项目事件时...

 private void processItemEvent(ExchangeService service, String mailbox, ItemEvent itemEvent) throws Exception {
        synchronized(service) {
            service.setImpersonatedUserId(impersonateAccount(mailbox));
            service.getHttpHeaders().put("X-AnchorMailbox", mailbox);
            service.getHttpHeaders().put("X-PreferServerAffinity", "true");
                try {
                   ...
                } catch (Exception ie) {
                   ...
                }
            }
      }

}