提问者:小点点

WireMock中的SOAP附件


我正在使用WireMock来模拟SOAP服务。

它工作得很好,但是其中一个服务包含一个附件。有没有办法用WireMock来模拟它?

谢啦


共1个答案

匿名用户

它将为您生成带有附件的响应。您可以看到原始部分如下所示:

Content-Type: multipart/related; type="application/xop+xml"; start="<rootpart@soapui.org>"; start-info="text/xml"; boundary="----=_Part_19_678369072.1513344309074",
MIME-Version: 1.0
------=_Part_19_678369072.1513344309074
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <rootpart@soapui.org>

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getFileResponse xmlns:ns3="urn:eu:europa:ec:etrustex:integration:service:notification:v2.0" xmlns:ns2="urn:eu:europa:ec:etrustex:integration:service:filerepository:v2.0" xmlns="urn:eu:europa:ec:etrustex:integration:model:common:v2.0">
         <ns2:fileWrapper>
            <Content><inc:Include href="cid:test.txt" xmlns:inc="http://www.w3.org/2004/08/xop/include"/></Content>
         </ns2:fileWrapper>
      </ns2:getFileResponse>
   </S:Body>
</S:Envelope>
------=_Part_19_678369072.1513344309074
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-ID: <test.txt>
Content-Disposition: attachment; name="test.txt"

TEST
------=_Part_19_678369072.1513344309074--

现在,您可以使用如下内容设置wiremck:

{        
    "request": {                                    
        "method": "POST",
        "urlPattern": "/mockFileRepository"
    },                                      
    "response": {                                   
        "status": 200,                          
        "bodyFileName": "responseTest.raw",
        "headers": {
            "Content-Type": "multipart/related; type=\"application/xop+xml\"; start=\"<rootpart@soapui.org>\"; start-info=\"text/xml\"; boundary=\"----=_Part_19_678369072.1513344309074\"",
            "MIME-Version": "1.0"
        }
    }                                               
}

请注意,标题内容类型应该与从肥皂用户界面获得的原始部分相同。

响应测试。原始看起来像这样:

 ------=_Part_19_678369072.1513344309074
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml"
Content-Transfer-Encoding: 8bit
Content-ID: <rootpart@soapui.org>

<S:Envelope xmlns:S="http://schemas.xmlsoap.org/soap/envelope/">
   <S:Body>
      <ns2:getFileResponse xmlns:ns3="urn:eu:europa:ec:etrustex:integration:service:notification:v2.0" xmlns:ns2="urn:eu:europa:ec:etrustex:integration:service:filerepository:v2.0" xmlns="urn:eu:europa:ec:etrustex:integration:model:common:v2.0">
         <ns2:fileWrapper>
            <Content><inc:Include href="cid:test.txt" xmlns:inc="http://www.w3.org/2004/08/xop/include"/></Content>
         </ns2:fileWrapper>
      </ns2:getFileResponse>
   </S:Body>
</S:Envelope>
------=_Part_19_678369072.1513344309074
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
Content-ID: <test.txt>
Content-Disposition: attachment; name="test.txt"

TEST
------=_Part_19_678369072.1513344309074--

瞧!