@RequestMapping(value = "testService", method = RequestMethod.POST)
public Object testService(@RequestParam(value = "ipPort", required = true) String ipPort,
@RequestBody GrpcServiceTestModel model) throws Exception {
String serviceUrl = "http://" + ipPort + "/service/test";
HttpPost request = new HttpPost(serviceUrl);
request.addHeader("content-type", "application/json");
request.addHeader("Accept", "application/json");
try {
StringEntity entity = new StringEntity(gson.toJson(model), "utf-8");
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
request.setEntity(entity);
HttpResponse httpResponse = httpClient.execute(request);
if (httpResponse.getStatusLine().getStatusCode() == 200) {
String minitorJson = EntityUtils.toString(httpResponse.getEntity());
Object response = gson.fromJson(minitorJson, new TypeToken<Object>() {}.getType());
return response;
}
} catch (Exception e) {
throw e;
}
return null;
}
ServiceTestController.java 文件源码
java
阅读 33
收藏 0
点赞 0
评论 0
项目:saluki
作者:
评论列表
文章目录