[E2007] [EWSJA] [JAVA] - 添加带附件的任务时的ServiceValidationException。 [英] [E2007] [EWSJA] [JAVA] - ServiceValidationException while adding Task with attachment.

查看:77
本文介绍了[E2007] [EWSJA] [JAVA] - 添加带附件的任务时的ServiceValidationException。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,


Exchange版本:2007_SP1

API名称:EWS JAVA

API版本:1.1

IDE :Eclipse


目标功能:创建带有附件获取ServiceValidationException的任务时。


以下是步骤


1。创建了一个Task对象。


2。添加了主题,正文和附件详细信息。


3。要添加附件,代码如下,


FileAttachment的附着= NULL;

名称= IBExchangeUtils.getComplexNodeElementValue(cachedXPath,elementNode," FileAttachment的" ;, J + 1,"姓名");

的ContentType = IBExchangeUtils.getComplexNodeElementValue(cachedXPath,elementNode," FileAttachment的" ;, J + 1," ContentType的");

内容识别= IBExchangeUtils.getComplexNodeElementValue(cachedXPath,elementNode," FileAttachment的" ;, J + 1,"内容识别");

ContentLocation = IBExchangeUtils.getComplexNodeElementValue(cachedXPath,elementNode," FileAttachment的" ;,Ĵ + 1,       " ContentLocation");


if(Name!= null)

  ;  {

    attachment = taskObj.getAttachments()。addFileAttachment(Name);

    }
if(ContentId!= null)

      attachment.setContentId(ContentId);
$
if(ContentType!= null)

      attachment.setContentType(ContentType);
$
else

       attachment.setContentType(" text / HTML");


if(ContentLocation!= null)

                            {

                               


                                FileAttachment file = taskObj.getAttachments()。addFileAttachment(ContentLocation);

                                file.setName(Name);

                                file.setContentType(ContentType);

                                file.setContentId(ContentId);

                                file.setContentLocation(ContentLocation);

                            }
                           将附件添加到任务对象后我们调用 service.createItems方法。$



$

目前在ExchnageService.java这点上,我们所得到的例外


如果(EwsUtilities.trueForAll(项目,新IPredicate<!项目>(){&NBSP;&NBSP;           


          @Override

          public boolean predicate(Item obj)throws ServiceLocalException {

   &NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;返回obj.hasUnprocessedAttachmentChanges(!);

&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;&NBSP;   }

      })){

        ;&NBSP;&NBSP;&NBSP;&NBSP;抛出新的ServiceValidationException(Strings.CreateItemsDoesNotAllowAttachments);

        } b $ b


注意:此异常在请求发送之前发生,因此我们没有得到任何响应,以便显示。


请帮助我们。


提前致谢。


问候,


Mandar




 

解决方案

你好Mandar,


我想首先感谢您阅读论坛指南。它使您更容易回答您的问题。


我没有使用 EWS Java API  所以我无法帮助您使用代码示例,但由于EWS Java API类似于EWS托管API,因此问题是
ExchangeService.CreateItems方法不支持具有未保存附件的项目。 CreateItems方法用于在单个调用中批量创建项目。如果您使用网络监视器,您将看到CreateItems
方法导致对EWS的单次调用。未保存的附件本质上是附加到客户端上的项目但尚未记录的附件在服务器上。创建项目并添加附件需要两次EWS调用。


为了进一步说明,底层EWS API由EWS Java API抽象。 EWS API要求首先创建新项目(单个  CreateItem操作调用),然后使用CreateAttachment操作添加/保存附件。 


基本上,您需要使用Task.Save方法替换ExchangeService.CreateItems方法。 这将导致单个CreateItem调用和随后的CreateAttachment调用。


关于问候,


Hello,

Exchange Version : 2007_SP1
API Name : EWS JAVA
API Version : 1.1
IDE : Eclipse

Targeted features : While creating a task with an attachment getting ServiceValidationException.

Following are the steps

1. Created a Task object.

2. Added Subject,body and attachment details to it.

3. To add an attachment,the code is as below,

FileAttachment attachment=null;
Name = IBExchangeUtils.getComplexNodeElementValue(cachedXPath, elementNode, "FileAttachment", j+1, "Name");
ContentType = IBExchangeUtils.getComplexNodeElementValue(cachedXPath, elementNode, "FileAttachment", j+1, "ContentType");
ContentId = IBExchangeUtils.getComplexNodeElementValue(cachedXPath, elementNode, "FileAttachment", j+1, "ContentId");
ContentLocation = IBExchangeUtils.getComplexNodeElementValue(cachedXPath, elementNode, "FileAttachment", j+1,        "ContentLocation");

if(Name!=null)
   {
    attachment = taskObj.getAttachments().addFileAttachment(Name);
    }
if(ContentId!= null)
      attachment.setContentId(ContentId);
if(ContentType!=null)
      attachment.setContentType(ContentType);
else
       attachment.setContentType("text/HTML");

if(ContentLocation != null)
                            {
                               
                                FileAttachment file = taskObj.getAttachments().addFileAttachment(ContentLocation);
                                file.setName(Name);
                                file.setContentType(ContentType);
                                file.setContentId(ContentId);
                                file.setContentLocation(ContentLocation);
                            }
                           
after adding the attachment to task object we are calling service.createItems method.

At this point in ExchnageService.java we are getting the exception

if (!EwsUtilities.trueForAll(items,new IPredicate<Item>() {               
            @Override
            public boolean predicate(Item obj) throws ServiceLocalException {
                return !obj.hasUnprocessedAttachmentChanges();
            }
        })) {
            throw new ServiceValidationException(Strings.CreateItemsDoesNotAllowAttachments);
        }

Note : This exception is coming before request is sent so we are not getting any response as such to show.

Please help us on the same.

Thanks in advance.

regards,

Mandar


 

解决方案

Hello Mandar,

I want to start by thanking you for reading the forum guide. It makes it much easier to answer your question.

I haven't used the EWS Java API so I can't help you with a code example but since the EWS Java API is similar to the EWS Managed API the issue is that the ExchangeService.CreateItems method does not support items with unsaved attachments. The CreateItems method is used to bulk create items in a single call. If you use a network monitor, you will see that the CreateItems method results in a single call to EWS. An unsaved attachment is essentially an attachment that has been attached to an item on the client but has not been recorded on the server. Creating an item and adding an attachment requires two EWS calls.

To explain further, the underlying EWS API is abstracted by the EWS Java API. The EWS API requires that a new item first be created (a single CreateItem operation call) and then the attachment can be added/saved by using the CreateAttachment operation. 

Essentially you need to replace the ExchangeService.CreateItems method with a Task.Save method . This will result in a single CreateItem call and a subsequent CreateAttachment call.

With regards,


这篇关于[E2007] [EWSJA] [JAVA] - 添加带附件的任务时的ServiceValidationException。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆