0

使用 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())
        }
    }
}

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

4

1 回答 1

0

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

为了满足您的要求,它需要看起来像这样

{
  "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标题。这就是请求不匹配的原因。

于 2017-10-23T14:03:14.463 回答