春云合约存根运行器试运行因404失败


当我

使用 stubrunner 运行我的客户端应用程序时,我收到以下错误

    Getting org.springframework.web.client.HttpClientErrorException: 404    
at org.springframework.web.client.DefaultResponseErrorHandler.handleError(DefaultResponseErrorHandler.java:63)  
at org.springframework.web.client.RestTemplate.handleResponse(RestTemplate.java:700)

Wiremock 提供以下信息

    {
  "url" : "/app/crm/customer/40",
  "absoluteUrl" : "http://localhost:6565/app/crm/customer/40",
  "method" : "GET",
  "clientIp" : "127.0.0.1",
  "headers" : {
    "accept" : "text/plain, text/plain, application/json, application/json, application/*+json, application/*+json, */*, */*",
    "domain" : "IND",
    "host" : "localhost:6565",
    "connection" : "Keep-Alive",
    "user-agent" : "Apache-HttpClient/4.5.3 (Java/1.8.0_144)",
    "accept-encoding" : "gzip,deflate"
  },
  "cookies" : { },
  "browserProxyRequest" : false,
  "loggedDate" : 1508757427831,
  "bodyAsBase64" : "",
  "body" : "",
  "loggedDateString" : "2017-10-23T11:17:07Z"
}
Closest match:
{
  "urlPattern" : "/app/crm/customer/[0-9]{2}",
  "method" : "GET",
  "headers" : {
    "Content-Type" : {
      "equalTo" : "application/json"
    },
    "domain" : {
      "equalTo" : "IND"
    }
  }
}

我的合同看起来像这样

    package contracts
import org.springframework.cloud.contract.spec.Contract
Contract.make {
    request {
        method 'GET'
        url value(consumer(regex('/app/crm/customer/[0-9]{2}')), producer('/app/crm/customer/40'))
        headers {
           contentType(applicationJson())
         }   
    }
    response {
        status 200
        headers {
            contentType(applicationJson())
        }
    }
}

试图通过更改内容类型和其他详细信息来解决此问题。我哪里做错了。谢谢。

它写的正是问题所在。换句话说,答案就在你的问题中。

为了匹配您的请求,它需要看起来像这样

{
  "urlPattern" : "/app/crm/customer/[0-9]{2}",
  "method" : "GET",
  "headers" : {
    "Content-Type" : {
      "equalTo" : "application/json"
    },
    "domain" : {
      "equalTo" : "IND"
    }
  }
}    

这些是您正在传递的标头

"headers" : {
    "accept" : "text/plain, text/plain, application/json, application/json, application/*+json, application/*+json, */*, */*",
    "domain" : "IND",
    "host" : "localhost:6565",
    "connection" : "Keep-Alive",
    "user-agent" : "Apache-HttpClient/4.5.3 (Java/1.8.0_144)",
    "accept-encoding" : "gzip,deflate"
  },

我没有看到Content-Type等于application/json标题。这就是请求不匹配的原因。

最新更新