SpringMVC-使用java为控制器创建httprequest
以下是我在web应用程序上获得的一个控制器:SpringMVC-使用java为控制器创建httprequest,java,spring,web-services,apache,rest,Java,Spring,Web Services,Apache,Rest,以下是我在web应用程序上获得的一个控制器: @RequestMapping(value = "/createAccount", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE) @ResponseStatus(value = HttpStatus.OK) @ResponseBody public ResponseDTO createAccount(@RequestBody PlayerAc
@RequestMapping(value = "/createAccount", method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(value = HttpStatus.OK)
@ResponseBody
public ResponseDTO createAccount(@RequestBody PlayerAccountDTO playerAccountDTO,
HttpServletRequest request) {
this.playerService.createAccount(playerAccountDTO);
return new ResponseDTO();
}
该控制器通过ajax使用post调用,并传递json,jackson mapper负责将其作为POJO(很好!)
我现在想做的是:
在另一个web应用程序中,我想通过http post请求调用,将PlayerAccountd传递给这个确切的控制器,当然也会收到响应
我希望这是尽可能简单
有可能做到这一点吗?以下是我的wishfull解决方案(另一个web应用程序上的服务):
您可以使用您的web服务器没有接收到
playerAccount to
对象。它接收一个HTTP请求,其主体(可能)包含一个JSON对象。SpringWeb应用程序尝试将该JSON反序列化为PlayerAccountDTO
对象,并将其传递给处理程序方法
因此,您要做的是使用一个HTTP客户端,它将客户端上的playeracocountdto
序列化为您在HTTP请求中发送的JSON
检查哪一个是Spring HTTP客户端,它使用与Spring用于序列化和反序列化@ResponseBody
注释方法和@RequestBody
注释参数中的对象相同的HttpMessageConverter
对象
public ResponseDTO createAccountOnADifferentWebApp() {
PlayerAccountDTO dto = new PlayerAccountDTO(...);
ResponseDTO result = httpRequestPost(url, dto, ResponseDTO.class);
return result;
}