我目前正在开发一个 Spring Boot 应用程序。我为 httpBasic 身份验证实现了 Spring Boot 安全性。身份验证成功后,我的自定义过滤器方法会被调用。
protected void onSuccessfulAuthentication(javax.servlet.http.HttpServletRequest request,
javax.servlet.http.HttpServletResponse response, Authentication authResult) throws IOException {
Iterator<? extends GrantedAuthority> it = authResult.getAuthorities().iterator();
switch (it.next().getAuthority()) {
case (MyConstants.ROLE_USER): {
try {
request.getRequestDispatcher("/user/data").forward(request, response); break;
} catch (ServletException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
所以我想将我需要的带有 JSON 数据的 rquest 对象转发到我的 RestController 端点。这有效。在我的控制器中,我想返回带有数据和 Http 状态代码的 ResponseEntity。
@RequestMapping(value="/upload", consumes = MediaType.APPLICATION_JSON_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public ResponseEntity< HttpStatus> upload(@RequestBody String uploadData){
ResponseEntity<String> httpStatus = sendExchangeToRestApi(MediaType.APPLICATION_JSON, uploadData,
"http://localhost:8080/upload", HttpMethod.PUT);
return new ResponseEntity<String>("Test". HttpStatus.OK);
}
我用邮递员测试了这个。输出没问题,所以我在我的身体输出中得到状态 200 和测试。
慕村225694
相关分类