使用 WildFly 和 Apache CXF 查询 Exchange Web 服务给出错误请求 (400)

Querying Exchange Web Service gives Bad Request (400) with WildFly and Apache CXF

我在查询 Microsoft Exchange Server Web 服务以获取特定文件夹中的项目时遇到问题。按照这个顺序,我可以向方法 expandDL 和方法 findFolders 发出请求。这些工作正常。但是,当我向 findItems 发出所有找到的文件夹的请求时,我收到 400 Bad Request 并且没有错误消息。

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

有关

我正在使用 WildFly 10 和 Java 1.8。 Apache CXF 用作网络服务调用的框架。 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 服务器的入站消息如下所示:

    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 和 post 对同一 Exchange 服务器发出完全相同的 SOAP 请求。令人惊讶的是,我得到了我想要的成功响应。

如果有人能指出解决此问题的方向,我将不胜感激。

好的,我终于找到了我的问题。在 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);