Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/312.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
SpringMVC-使用java为控制器创建httprequest_Java_Spring_Web Services_Apache_Rest - Fatal编程技术网

SpringMVC-使用java为控制器创建httprequest

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

以下是我在web应用程序上获得的一个控制器:

@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;
}