opentable / wiremock-body-transformer

Wiremock Body Transformer Extension
Apache License 2.0
65 stars 42 forks source link

how to do body transforming for soap request #28

Closed srivi1225 closed 7 years ago

srivi1225 commented 7 years ago

Hi,

I am new to wiremock and wiremock-body-transformer i have a soap request(namespaced) for which i am using wiremock. my response should be dynamic . Response has to be changed based on the request data. i am providing the sample request and response below.

<?xml version="1.0"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema"
               xmlns:xalan="http://xml.apache.org/xslt">
    <soap:Header xmlns:SOAP-SEC="http://schemas.xmlsoap.org/soap/security/2000-12">
        <payloadManifest xmlns="http://www.starstandards.org/webservices/2005/10/transport">
            <manifest contentID="Content0" element="ProcessCreditContract"
                      namespaceURI="http://www.starstandards.org/STAR" version="4.3.3"/>
        </payloadManifest>
    </soap:Header>
    <soap:Body>
        <PutMessage xmlns="http://www.starstandards.org/webservices/2005/10/transport">
            <payload>
                <content id="Content0">
                    <Process xmlns="http://www.starstandards.org/STAR"
                                           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                                           xsi:schemaLocation="http://www.starstandards.org/STAR \STAR\Standalone\sample.xsd"
                                           revision="4.3.3" release="8.1-Lite" environment="Production" lang="en-US">
                        <apparea>
                            <Sender>
                                <site>www.abc.com</LogicalId>
                                <Component>validate</Component>
                                <Task>contract</Task>
                            </Sender>
                            <CreationDateTime>2017-07-24T07:51:21-04:00</CreationDateTime>
                            <BODId>ABC220000005170411</BODId>
                        </apparea>
                        <Data>
                            <PersonName>
                                <GivenName>TRACY</GivenName>
                                <MiddleName>RICHARD</MiddleName>
                                <FamilyName>FRITZ</FamilyName>
                                <Suffix>SR</Suffix>
                            </PersonName>
                        </Data>
                    </Process>
                </content>
            </payload>
        </PutMessage>
    </soap:Body>
</soap:Envelope>

response should be something like

<?xml>
<BODID>ABC220000005170411</BODID>
<provider>abc</provider>
<name>Suffix + GivenName + MiddleName +FamilyName</name>
<status>success</status>

i tried with the below xml

<root><foo type="string" xmlns="urn:APTLU0WS.APT.pragmasis.pt">Travis</foo></root>

and got the response like

<xml>
    <name>hello Travis</name>
</xml>

it is working fine

if i have namespaces in the requst xml and not enclose in "<root>" or if it find "<soap>" in the request xml it is not working.

Can you please guide me how to transform without "<root>" and for the namespaced soap request.

okondrashin commented 7 years ago

Hello,

You can use this issue to solve your problem) https://github.com/opentable/wiremock-body-transformer/issues/10

the xmlMapper will ignore the "soap:" ....
So the true object to be reached is:
$(Envelope.Body.....

And can you try with and without <?xml version="1.0"?>?)

srivi1225 commented 7 years ago

Hi,

I tried like <xml>$(Envelope.Body.PutMessage.payload.content.Process.apparea.Sender.Component.value)</xml> But i am getting null also i am not adding <root> tag.

Could you please suggest me what i am doing wrong here.

KRoLer commented 7 years ago

Hi @srivi1225,

In your case root tag is soap:Envelope, so you should start your path from Header or Body tag. Hope Body.PutMessage.payload.content.Process.apparea.Sender.Component.value will work fine.

srivi1225 commented 7 years ago

Hi @KRoLer

That worked like a charm. thanks a lot.

also i have one query regarding the wiremock stuff

in the above question i have the request and response right. instead of getting the response can i send that as input to another soap service??.

Please help me with your inputs.

Thank you

tranhungt commented 7 years ago

Thanks @KRoLer for the help. @srivi1225 To my understanding, it is not in the intention of the wiremock platform to be able to pass on requests to external services. And it wasn't the intention of this wiremock-body-transformer to do so either. But since the wiremock project is opensource and extensible, I'm sure some type of request passthrough transformer could be written for it.

tranhungt commented 7 years ago

@srivi1225 Looks like this ticket has been resolved so I'll close it now.

PraveenKumarDN commented 4 years ago

@tranhungt @KRoLer @okondrashin @stevenschlansker @srivi1225 How to parse for the value of below soap request?

654321 hello world Kkpravee_Test I tried with belows but still getting null in the response: 1. $(Body.request.requestId.value) 2. $(Body.ser:request.ser:requestId.value) Please help me where am i doing wrong guyz.