Alexei
Alexei

Reputation: 15726

WireMock not mapping request by body contains

My http request send to this: https://myhost.com/ap

My http request with body :

{

  "Body": {
    "CommandName": "GetApplicationProfile"
  },
  "Header": {
    "Command": "GetApplicationProfile",
  }
}

I want to mapping this request by WireMock.

Here WireMock's mapping file.

    {
  "request": {
    "url": "/my_host/ap",
    "bodyPatterns": [
      {
        "contains": "GetApplicationProfile"
      }
    ]
  },
  "response": {
    "headers": {
      "Content-Type": "application/json"
    },
    "status": 200,
    "bodyFileName": "get_profile.json"
  }
}

I start wireMock like this:

java -jar wiremock-standalone-2.18.0.jar --port 8080 --enable-browser-proxying -verbose

But when request was started the WireMock not map this request. Nothing happened. why?

Upvotes: 1

Views: 6163

Answers (3)

Shmuel P.
Shmuel P.

Reputation: 129

I see 2 issues here: 1. you need to remove the host name from the url in the mapping file. 2. your request is HTTPS which means you need to start your wiremock port with https: --https-port 8080 or you change your request to HTTP

Upvotes: 0

A. Kootstra
A. Kootstra

Reputation: 6981

The problem you're having is that you shouldn't have the hostname in the url part. This is not needed. Your example message can be sent and will be matched using the following rule.

{
  "request": {
    "url": "/app",
    "bodyPatterns": [
      {
        "contains": "GetApplicationProfile"
      }
    ]
  },
  "response": {
    "headers": {
      "Content-Type": "application/json"
    },
    "status": 200,
    "body": "ddd"
  }
}

Upvotes: 1

RAJESH KUMAR
RAJESH KUMAR

Reputation: 31

The URL should not contain the host name. It should only contain the resource path.

The url format should start with "/" e.g. /https://myhost.com/ap. Now if u r trying this on localhost then the URL should be localhost:<port>/https://myhost.com/ap.

The file should be present at src/test/resources/__files If not it will give error file not present.

Upvotes: 0

Related Questions