查询Exchange Web服务使用WildFly和Apache CXF

时间:2016-04-29 11:59:23

标签: java web-services cxf exchangewebservices

在查询Microsoft Exchange Server WebServices以获取某些文件夹中的项目时出现问题。按此顺序,我可以向方法expandDL和方法findFolders发出请求。这些工作正常。但是当我随后向所有找到的文件夹发出请求findItems时,我收到400 Bad Request而没有错误消息。

我认为这个问题与Querying Exchange Web Services fails with 400 Bad Request

有关

我使用的是WildFly 10和Java 1.8。 Apache CXF用作webservice调用的框架。 Exchange Server的版本为2013。

有两个观察结果使这个问题变得神秘,至少对我而言:

  1. 当我发出findItem请求时,它有大约11个FolderIdType秒。结果总是400 Bad Request。我可以从请求中删除一些文件夹,最终当findItem请求中只有四个文件夹时,一切正常。只要只有四个或更少,我删除哪个文件夹也没关系!看我的肥皂要求:

    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
        <soap:Header>
            <ns2:ExchangeImpersonation xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types">
                <ns2:ConnectingSID>
                    <ns2:PrimarySmtpAddress>tobeimpersonated@example.com</ns2:PrimarySmtpAddress>
                </ns2:ConnectingSID>
            </ns2:ExchangeImpersonation>
            <ns2:RequestServerVersion xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types" Version="Exchange2007_SP1"/>
        </soap:Header>
        <soap:Body>
            <FindItem xmlns="http://schemas.microsoft.com/exchange/services/2006/messages" xmlns:ns2="http://schemas.microsoft.com/exchange/services/2006/types" Traversal="Shallow">
                <ItemShape>
                    <ns2:BaseShape>IdOnly</ns2:BaseShape>
                    <ns2:IncludeMimeContent>false</ns2:IncludeMimeContent>
                    <ns2:BodyType>Best</ns2:BodyType>
                    <ns2:AdditionalProperties>
                        <ns2:FieldURI FieldURI="message:InternetMessageId"/>
                        <ns2:FieldURI FieldURI="item:Subject"/>
                        <ns2:ExtendedFieldURI PropertyTag="0x300B" PropertyType="Binary"/>
                        <ns2:ExtendedFieldURI PropertyTag="0x3704" PropertyType="String"/>
                    </ns2:AdditionalProperties>
                </ItemShape>
                <IndexedPageItemView BasePoint="Beginning" MaxEntriesReturned="20" Offset="0"/>
                <Restriction>
                    <ns2:And>
                        <ns2:Or>
                            <ns2:IsEqualTo>
                                <ns2:FieldURI FieldURI="item:ItemClass"/>
                                <ns2:FieldURIOrConstant>
                                    <ns2:Constant Value="IPM.Note"/>
                                </ns2:FieldURIOrConstant>
                            </ns2:IsEqualTo>
                            <ns2:IsEqualTo>
                                <ns2:FieldURI FieldURI="item:ItemClass"/>
                                <ns2:FieldURIOrConstant>
                                    <ns2:Constant Value="IPM.Note.SMIME.MultipartSigned"/>
                                </ns2:FieldURIOrConstant>
                            </ns2:IsEqualTo>
                            <ns2:IsEqualTo>
                                <ns2:FieldURI FieldURI="item:ItemClass"/>
                                <ns2:FieldURIOrConstant>
                                    <ns2:Constant Value="IPM.Note.SMIME"/>
                                </ns2:FieldURIOrConstant>
                            </ns2:IsEqualTo>
                        </ns2:Or>
                        <ns2:IsEqualTo>
                            <ns2:FieldURI FieldURI="item:IsDraft"/>
                            <ns2:FieldURIOrConstant>
                                <ns2:Constant Value="false"/>
                            </ns2:FieldURIOrConstant>
                        </ns2:IsEqualTo>
                        <ns2:Not>
                            <ns2:Exists>
                                <ns2:ExtendedFieldURI PropertyName="propertyName" PropertySetId="24040483-cda4-4521-bb4e-a83fac4d19a4" PropertyType="Integer"/>
                            </ns2:Exists>
                        </ns2:Not>
                        <ns2:Or>
                            <ns2:And>
                                <ns2:IsGreaterThan>
                                    <ns2:FieldURI FieldURI="item:DateTimeReceived"/>
                                    <ns2:FieldURIOrConstant>
                                        <ns2:Constant Value="2014-02-06T12:40:53Z"/>
                                    </ns2:FieldURIOrConstant>
                                </ns2:IsGreaterThan>
                                <ns2:IsLessThanOrEqualTo>
                                    <ns2:FieldURI FieldURI="item:DateTimeReceived"/>
                                    <ns2:FieldURIOrConstant>
                                        <ns2:Constant Value="2016-04-29T08:32:42Z"/>
                                    </ns2:FieldURIOrConstant>
                                </ns2:IsLessThanOrEqualTo>
                            </ns2:And>
                            <ns2:And>
                                <ns2:IsGreaterThan>
                                    <ns2:FieldURI FieldURI="item:DateTimeSent"/>
                                    <ns2:FieldURIOrConstant>
                                        <ns2:Constant Value="2014-02-06T12:40:53Z"/>
                                    </ns2:FieldURIOrConstant>
                                </ns2:IsGreaterThan>
                                <ns2:IsLessThanOrEqualTo>
                                    <ns2:FieldURI FieldURI="item:DateTimeSent"/>
                                    <ns2:FieldURIOrConstant>
                                        <ns2:Constant Value="2016-04-29T08:32:42Z"/>
                                    </ns2:FieldURIOrConstant>
                                </ns2:IsLessThanOrEqualTo>
                            </ns2:And>
                        </ns2:Or>
                    </ns2:And>
                </Restriction>
                <SortOrder>
                    <ns2:FieldOrder Order="Ascending">
                        <ns2:FieldURI FieldURI="item:DateTimeReceived"/>
                    </ns2:FieldOrder>
                </SortOrder>
                <ParentFolderIds>
                    <ns2:FolderId ChangeKey="AQAAABYAAAB8br3Xlm6jQ6ESWiFFNbMfAAEtfGtC" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEA0zVBfp4xUk+7Vyc3iZW0FAA05RFXoQAAAA=="/>
                    <ns2:FolderId ChangeKey="AQAAABYAAAB8br3Xlm6jQ6ESWiFFNbMfAAEtfH8N" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEA0zVBfp4xUk+7Vyc3iZW0FAA05RFXoAAAAA=="/>
                    <ns2:FolderId ChangeKey="AQAAABQAAAAJFy1A7LXdQ4Jg/JYq7dhuAAFIBg==" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEA0zVBfp4xUk+7Vyc3iZW0FAA05RDn6AAAAA=="/>
                    <ns2:FolderId ChangeKey="AgAAABYAAADTNUF+njFST7tXJzeJlbQUADTuxhMy" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEA0zVBfp4xUk+7Vyc3iZW0FAA05RDnvgAAAA=="/>
                    <ns2:FolderId ChangeKey="AwAAABYAAAB8br3Xlm6jQ6ESWiFFNbMfAAEtfLe1" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEAfG6915Zuo0OhElohRTWzHwAAAgmBAAAA"/>
                    <ns2:FolderId ChangeKey="AQAAABYAAAB8br3Xlm6jQ6ESWiFFNbMfAAEtfLIm" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEA0zVBfp4xUk+7Vyc3iZW0FAA05RFXngAAAA=="/>
                    <ns2:FolderId ChangeKey="AQAAABYAAAB8br3Xlm6jQ6ESWiFFNbMfAAEtfH79" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEAfG6915Zuo0OhElohRTWzHwABJMQcGAAAAA=="/>
                    <ns2:FolderId ChangeKey="AQAAABQAAAAJFy1A7LXdQ4Jg/JYq7dhuAAFIBA==" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEA0zVBfp4xUk+7Vyc3iZW0FAA07GTIvwAAAA=="/>
                    <ns2:FolderId ChangeKey="AwAAABYAAAB8br3Xlm6jQ6ESWiFFNbMfAACg9DeI" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEACthrv1y0RUyxtNEACu0ptAA066kAAwAAAA=="/>
                    <ns2:FolderId ChangeKey="AQAAABYAAAB8br3Xlm6jQ6ESWiFFNbMfAAEdND9a" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEA0zVBfp4xUk+7Vyc3iZW0FAA05RDn0wAAAA=="/>
                    <ns2:FolderId ChangeKey="AQAAABQAAADao4wXVcs7RIo7U7kl8KntAAIkAQ==" Id="AQMkADUwYWRiMTQzLTA2ZWMtNDEyZi05ZjgyLWUyNWYwNzVjZjViNQAuAAADsJ39BzCTikK07SQtfYnJhwEACthrv1y0RUyxtNEACu0ptABAzY4ADQAAAA=="/>
                </ParentFolderIds>
            </FindItem>
        </soap:Body>
    </soap:Envelope>
    

    当然,我也有一些限制,比如日期。

    来自Exchange服务器的My Inbound消息如下所示:

    ID: 4
    Response-Code: 400
    Encoding: ISO-8859-1
    Content-Type: 
    Headers: {
     Cache-Control=[private],
     Content-Length=[0],
     Date=[Fri, 29 Apr 2016 08:32:44 GMT],
     request-id=[8a3d7697-3f2b-458a-904d-703d5e2f0664],
     Server=[Microsoft-IIS/8.5],
     Set-Cookie=[X-BackEndCookie=S-1-5-21-436374069-789336058-1060284298-3660=u56Lnp2ejJqBz53Nzs+ayJ3SnJ2bnNLLzMfJ0p6bzMvSx57Iyc2ensfHxsibgYHNz87J0s/K0s3Gq8/HxczNxcvK; expires=Sun, 29-May-2016 08:32:45 GMT; path=/EWS; HttpOnly, exchangecookie=5096a0de261c45019aa1523ce05cd77c; expires=Sat, 29-Apr-2017 08:32:42 GMT; path=/; HttpOnly, ClientId=MASOZZCUPEOBNCBZRFNOMQ; expires=Sat, 29-Apr-2017 08:32:42 GMT; path=/; HttpOnly],
     X-AspNet-Version=[4.0.30319], X-BEServer=[SABCEXH04],
     X-CalculatedBETarget=[sabcexh04.company.local],
     X-DiagInfo=[SABCEXH04],
     X-FEServer=[SABCEXH04],
     X-Powered-By=[ASP.NET]
    }
    
  2. 我可以使用Microsoft的EWSEditor,并将完全相同的SOAP请求发布到同一个Exchange Server。令人惊讶的是,我按照我想要的方式得到了成功的回应。

  3. 如果有人可以请指点我如何解决这个问题,那将非常感激。

1 个答案:

答案 0 :(得分:0)

好的,我终于找到了我的问题。在Apache CXF中,我必须设置禁用分块:

import org.apache.cxf.endpoint.Client;
import org.apache.cxf.frontend.ClientProxy;
...
Client client = ClientProxy.getClient(port);
HTTPConduit conduit = (HTTPConduit) client.getConduit();
HTTPClientPolicy policy = conduit.getClient();
if(policy == null) {
   policy = new HTTPClientPolicy();
}
policy.setAllowChunking(false);