问题描述
我面临着wiremock的怪异问题。它使响应主体为空。任何见识将不胜感激。
我的测试存根:
wiremock.stubFor(post(urlPathEqualTo("http://localhost:8080/mapper"))
.willReturn(wiremock.aResponse()
.withStatus(HttpStatus.OK.value())
.withBody(asJson("ct/slotting-response/create_sample_response1.json"))
.withHeader("Content-Type","application/json;charset=UTF-8")));
使用spring boot resttemplate进行的实际API调用:
public ResponseEntity<SampleResponse> getsampleValue(final SampleRequest request,RequestHeader requestHeader) throws SlottingException {
try {
log.info("Sending request[payload={}]",request);
final HttpHeaders headers = getRequestHeader(requestHeader);
httpentity<?> entity = new httpentity<>(request,headers);
final ResponseEntity<SampleResponse> response =
restTemplate.postForEntity("http://localhost:8080/mapper",entity,SampleResponse.class);
log.info("Sample response {}",response); // response.getBody() gives null
if (HttpStatus.OK.equals(response.getStatusCode())) {
log.info("Sample allocated successfully.");
}
else {
throw new SampleException("Failed");
}
return response;
} catch (Exception e) {
throw new SampleException("Failed",e);
}
}
有人可以指出您在wiremock存根中看到的任何明显错误吗?
感谢adv
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)