2017-07-07 63 views
1

我正在使用WireMock来模拟SOAP服务。WireMock中的SOAP附件

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

谢谢

+0

那么你使用MTOM? – ThomasRS

+0

是的,我是。在我的响应对象中,它存储为'org.apache.axis.attachments.AttachmentPart'。 –

+0

那么附件是内置还是外置? – ThomasRS

回答

0

是的,这是可能的。 首先,您可以使用SOAP ui来模拟您期望的附件响应。 [在soap资源上,右键单击:生成SOAP模拟服务] 在创建的模拟上,响应中应该会看到与wsld相对应的虚拟主体。在那里你可以点击附件并添加一个文件: enter image description here 你运行这个模拟并尝试用肥皂请求手动点击它,然后应该出现在请求部分。

它会为您生成附件的回复。 您可以看到原始的部分看起来像这样:

Content-Type: multipart/related; type="application/xop+xml"; start="<[email protected]>"; 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: <[email protected]> 

<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像这样的东西:

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

注重标题内容类型应该是一样的你从肥皂用户那里得到的原料。

的responseTest.raw看起来是这样的:

------=_Part_19_678369072.1513344309074 
Content-Type: application/xop+xml; charset=UTF-8; type="text/xml" 
Content-Transfer-Encoding: 8bit 
Content-ID: <[email protected]> 

<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-- 

瞧!