首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WireMock中的SOAP附件

WireMock中的SOAP附件
EN

Stack Overflow用户
提问于 2017-07-07 17:13:42
回答 1查看 1.8K关注 0票数 3

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

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

谢谢

EN

回答 1

Stack Overflow用户

发布于 2017-12-18 16:14:07

是的这是可能的。首先,您可以使用SOAP通过附件模拟您期望的响应。在soap资源上,右键单击: generate SOAP mock service On the mock created,在响应中您应该看到一个对应于wsld的虚拟主体。在这里你可以点击附件并添加一个文件:

您运行此模拟,并尝试使用soap请求手动访问它,然后该请求应出现在请求部分上。

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

代码语言:javascript
运行
复制
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--

现在,您可以设置wiremock,如下所示:

代码语言:javascript
运行
复制
{        
    "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"
        }
    }                                               
}

请注意,标头的content-type应该与您从soap ui获得的原始部分相同。

responseTest.raw如下所示:

代码语言:javascript
运行
复制
 ------=_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--

瞧!

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44966961

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档