从另一个内部调用一个REST服务,我目前遇到一个非常奇怪的问题,我真的可以帮忙弄清楚我在做什么错。
所以首先,有一点上下文:
我有一个webapp可以调用REST服务来创建用户帐户(为了便于说明,端点为localhost:8080 / register)。在用户旅程的早期,我调用了另一项服务来创建用户的登录凭据,localhost:8090/signup但是我需要检查对/ register的调用中的一些内容,因此在调用过程中,我要向8090上的另一个端点进行调用以获取此信息信息(localhost:8090/availability)。长话短说,Web应用程序会调用localhost:8080 / register,而依次调用localhost:8090/availability。
当我从REST客户端或Webapp本身直接调用可用性终结点时,一切都按预期方式运行,但是由于某些奇怪的原因,当我从调用注册内部的终结点中调用时,得到了HTTP415。有人对出什么问题有任何见解吗?
寄存器控制器如下所示:
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public UserModel createUser(@RequestBody UserModel userModel) throws InvalidSignupException {
// a load of business logic that validates the user model
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Boolean> response = restTemplate.postForEntity("http://localhost:8090/availability",
userModel.getUsername(), Boolean.class);
System.out.println(response.getBody());
// a load more business logic
return userModel;
}
Run Code Online (Sandbox Code Playgroud)
可用性控制器如下所示:
@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@ResponseStatus(HttpStatus.OK)
public Boolean isUsernameAvailable(@RequestBody …Run Code Online (Sandbox Code Playgroud)