Multiple Mappings to the Same URL

6,027 views
Skip to first unread message

simon.sjc...@gmail.com

unread,
May 15, 2015, 9:06:27 AM5/15/15
to wiremo...@googlegroups.com
Hi,

I am running wiremock 1.55 in standalone mode to try and mock a SOAP service.  I am trying to mock 2 soap operations which map to the same URL but have different SOAP request structures.  I have created corresponding mapping files and via the admin page I can see that these have been deployed successfully and the mappings have been applied:

{
  • mappings
    [
    • {
      • request
        {
        • urlPath"/MCEOfferManagement",
        • method"POST",
        • bodyPatterns
          [
          • {
            • matchesXPath"/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='CheckEligiblilityRequest']"
            }
          ]
        },
      • response
        {
        • status200,
        • body"
        • "Ommitted due to size of body"
        • }
        • "
        }
      },
    • {
      • request
        {
        • urlPath"/MCEOfferManagement",
        • method"POST",
        • bodyPatterns
          [
          • {
            • matchesXPath"/*[local-name()='Envelope']/*[local-name()='Body']/*[local-name()='GetCurrentPlanRequest']"
            }
          ]
        },
      • response
        {
        • status200,
        • body"Ommitted due to size of body"
        }
      }
    ]
}

When I send requests, wiremock only maps successfully to the 1st mapping defined, the 2nd mapping doesn't ever match even when I supply a SOAP body which matches the configured XPath.  The XPath configuration is correct as it maps successfully when I am running wiremock within junit.

Is it possible to have 2 mappings which match the same URL but differ on bodyPattern?  If so can you please tell me where I am going wrong?

Any help would be greatly appreciated.

Thanks

Siomn

Tom Akehurst

unread,
May 15, 2015, 12:24:17 PM5/15/15
to wiremo...@googlegroups.com, simon.sjc...@gmail.com
What you're attempting is definitely possible and you're on the right track here.

I find XPaths with namespaced XML to be quite tricky. WireMock uses XMLUnit's XPath evaluator internally, so I'd suggest writing a unit test directly against that, passing in the SOAP body you're testing with.

simon.sjc...@gmail.com

unread,
May 19, 2015, 11:54:57 AM5/19/15
to wiremo...@googlegroups.com, simon.sjc...@gmail.com
Hi Tom,

Many thanks for your response.  I have written unit tests and they work fine as per your suggestion.

I have ran wiremock standalone in verbose mode and can see the following log statement when it cannot match my request:

URL /MCEOfferManagement is match, but body is not

If I then copy the XML body that is written to the log and paste it into web client such as Postman and make the request it matches successfully.  I am really confused about this!

Any ideas why Wiremock is not recognising it as a match in one instance but it does in another?  Is there anything I should be looking for?

Thanks

Simon

Tom Akehurst

unread,
May 19, 2015, 12:55:15 PM5/19/15
to wiremo...@googlegroups.com, simon.sjc...@gmail.com
I'd hazard a guess that it might be to do with differing character sets from different clients.

When I have a problem like this I generally run tcpdump to view the raw requests. That way I can see an unbiased view of the requests coming from both sources and hopefully spot any differences.

Pallavi

unread,
Jun 22, 2017, 7:22:12 AM6/22/17
to wiremock-user, simon.sjc...@gmail.com
Hi @Tom Akehurst 

I tried in the same way in which simon mentioned above. 
{
    "mappings":
    [
        {
            "request": {
                "url": "/soaptest",
                "method": "POST",
                "bodyPatterns" : [
                    {
                        "matchesXPath" : "SOAP-ENV:Envelope/SOAP-ENV:Body/report:GetReportXml//report:First[text()='test']",
                        "xPathNamespaces" : {
                            "SOAP-ENV" : "http://schemas.xmlsoap.org/soap/envelope/",
                            "report" : "http://schemas.xmlsoap.org/soap/encoding/"
                        }
                    }
                ]
            },

            "response":
            {
                "status": 200,
                "headers":
                {
                    "Content-Type" : "application/json"
                },
                "bodyFileName": "sayhello.xml"
            }
        },

        {
            "request": {
                "url": "/soaptest",
                "method": "POST",
                "bodyPatterns" : [
                    {
                        "matchesXPath" : "SOAP-ENV:Envelope/SOAP-ENV:Body/report:GetReportXml//report:Surname[text()='JOSEPH']",
                        "xPathNamespaces" : {
                            "SOAP-ENV" : "http://schemas.xmlsoap.org/soap/envelope/",
                            "report" : "http://schemas.xmlsoap.org/soap/encoding/"
                        }
                    }
                ]
            },

            "response":
            {
                "status": 200,
                "headers":
                {
                    "Content-Type" : "application/json"
                },
                "bodyFileName": "sayhello.xml"
            }
        }
    ]
}

But I am getting below error.

Exception in thread "main" wiremock.com.fasterxml.jackson.databind.exc.UnrecognizedPropertyException: Unrecognized field "mappings" (class com.github.tomakehurst.wiremock.stubbing.StubMapping), not marked as ignorable (11 known properties: "response", "requiredScenarioState", "priority", "persistent", "id", "postServeActions", "request", "newScenarioState", "name", "uuid", "scenarioName"])

Did I make any mistake?

Pallavi

unread,
Jun 22, 2017, 7:36:01 AM6/22/17
to wiremock-user, simon.sjc...@gmail.com
I am using wiremock 2.6.0.
While running the jar itself (java -jar wiremock-standalone-2.6.0.jar) I am getting that error.

Tom Akehurst

unread,
Jun 22, 2017, 7:41:57 AM6/22/17
to wiremock-user, simon.sjc...@gmail.com
You can't post multiple mappings at once at the moment. You need to post them individually and the request and response keys must be in the top-level object.

Pallavi

unread,
Jun 22, 2017, 8:29:49 AM6/22/17
to wiremock-user, simon.sjc...@gmail.com
Thanks for the quick response Tom.
I have tried this with wiremock version 1.55 (mentioned by Simon). I didn't get that error. 
Means is that feature removed in next versions?

Tom Akehurst

unread,
Jun 22, 2017, 9:15:37 AM6/22/17
to wiremock-user, simon.sjc...@gmail.com
No, it was never a feature in the first place. Now I'm confused.
Reply all
Reply to author
Forward
0 new messages