WireMock中的SOAP附件

时间:2017-07-07 09:13:42

标签: soap wiremock

我使用WireMock来模拟SOAP服务。

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

由于

1 个答案:

答案 0 :(得分:0)

Yes it's possible. First, you can use SOAP ui to mock the response you are expecting with the attachment. [On the soap resource, right click: generate SOAP mock service] On the mock created, in the response you should see a dummy body corresponding to the wsld. There you can click on attachment and add a file: enter image description here You run this mock and try to hit it manually with a soap request that should then appear on the request part.

It will produce for you the response with the attachment. You can see the raw part looking like this:

public function getServingsAttribute()
{
    return $this->pivot->quantity;
}

Now, you can set up wiremock with something like this:

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

Pay attention the headers content-type should be the same as on the raw parts you got from soap ui.

the responseTest.raw looks something like this:

{        
    "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"
        }
    }                                               
}

And voila!