Skip to content
This repository was archived by the owner on Oct 6, 2022. It is now read-only.

how to do body transforming for soap request with multiple tags with same name #39

Open
Bhavana23 opened this issue Jul 5, 2018 · 3 comments

Comments

@Bhavana23
Copy link

Bhavana23 commented Jul 5, 2018

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.

<?xml version="1.0" encoding="UTF-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xalan="http://xml.apache.org/xslt" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <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</site>
                        <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>
            <content id="Content1">
               <SenderID>1234</SenderID>
               <TargetID>2232</TargetID>
               <ConversationID>AD-1-324324</ConversationID>
               <SentTimeStamp>2018-07-05T03:01:49-04:00</SentTimeStamp>
               <MessageType>DSPCreditApplication</MessageType>
               <SequenceNo>1</SequenceNo>
            </content>
         </payload>
      </PutMessage>
   </soap:Body>
</soap:Envelope>

When Iam accessing $(Body.ProcessMessage.payload.content.Process.apparea.sender.Component), then iam getting null value.

I observed that the $(Body.ProcessMessage.payload.content) is returning the values of second content tag.

I need to access the data in the first content tag.

Could you please help me on it.

@KRoLer
Copy link

KRoLer commented Jul 5, 2018

Hi @Bhavana23,
The paths you mentioned do not exist in your XML.
Try to replace ProcessMessage on the PutMessage and hopefully it will work fine.
${Body.PutMessage.payload.content.Process.apparea.Sender.Component}

@Bhavana23
Copy link
Author

Bhavana23 commented Jul 5, 2018

Hi @KRoLer

Yeah, I did the change, but ${Body.PutMessage.payload.content} is giving the values of second tag <content id="Content1">,

I need the values in the below content <content id="Content0"> tag.

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

@KRoLer
Copy link

KRoLer commented Jul 5, 2018

Hey @Bhavana23,

It looks like the code didn't handle such kind of situation.
As I see, it stores the request as Map with the field name as a key and it will have only unique keys.

for (String field : fieldNames) {
            if (tempObject instanceof Map) {
                tempObject = ((Map) tempObject).get(field);
            }
        }

There are two ways to fix it:

  • Change the request structure to have only unique fields
  • Fix it in code and submit a pull request :-)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants