猿问

使用 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() 会失败,并显示以下内容:

“访问被拒绝。检查凭据并重试。该过程无法获取正确的属性。,errorCode='ErrorAccessDenied'”

或者

“在商店中找不到指定的对象。,进程无法获取正确的属性。,errorCode='ErrorItemNotFound'”

尽管事实是这样

  • 凭据有效,可以成功用于调用 service.findFolders(WellKnownFolderName.MsgFolderRoot,folderView);

  • 我们正在使用 Exchange 模拟。已为所有邮箱分配模拟权限。

  • 设置锚邮箱:service.getHttpHeaders().put("X-AnchorMailbox",mailbox);

  • 设置 X-PreferServerAffinity:service.getHttpHeaders().put("X-PreferServerAffinity", "true");

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


MMMHUHU
浏览 117回答 1
1回答

临摹微笑

就我而言,我的代码模拟了错误的邮箱。事实证明,我需要维护一张地图,如下所示:&nbsp;private&nbsp;Map<StreamingSubscription,&nbsp;String>&nbsp;reverseSubscriptions&nbsp;=&nbsp;Collections.synchronizedMap(new&nbsp;HashMap<>());然后在 notificationEventDelegate(..) 方法中...称呼String&nbsp;mailbox&nbsp;=&nbsp;reverseSubscriptions.get(args.getSubscription());处理项目事件时...private void processItemEvent(ExchangeService service, String mailbox, ItemEvent itemEvent) throws Exception {&nbsp; &nbsp; &nbsp; &nbsp; synchronized(service) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.setImpersonatedUserId(impersonateAccount(mailbox));&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.getHttpHeaders().put("X-AnchorMailbox", mailbox);&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; service.getHttpHeaders().put("X-PreferServerAffinity", "true");&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; try {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } catch (Exception ie) {&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;...&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }&nbsp; &nbsp; &nbsp; }}
随时随地看视频慕课网APP

相关分类

Java
我要回答