我正在尝试从服务A呼叫服务B
服务A:
SideMenu
服务B:
@RequestMapping(value = { ""getCustomer"}, method = RequestMethod.POST)
public @ResponseBody ResponseEntity<Object> webApiQueryByPost(HttpServletRequest request)
throws JsonParseException, JsonMappingException, IOException {
Map<String, String[]> email = request.getParameterMap();
RestTemplate rest = new RestTemplate();
Object response = rest.postForObject("http://localhost:8084/getCustomer", request, Object.class, email);
return new ResponseEntity<>(response,HttpStatus.OK);
}
服务A需要将请求传递给服务B.
例外:
@RequestMapping(value = "getCustomer", method = RequestMethod.POST) public ResponseEntity<Object> getWebCustomer(@RequestParam String email, HttpServletRequest request) { return webCustomerDataService.getCustomerData(email); }
传递整个请求的动机是使此方法对于不同的请求是通用的,它应该只将服务A的请求传递给服务B.
我们是否需要将请求转换为Map(从HttpServletRequest中提取请求参数)?
有没有办法将HttpServletRequest直接传递给Service B?
请注意:我在RestTemplate中尝试了不同的方法。
任何帮助/指针都将不胜感激。
由于