正如我在标题中提到的那样,在Atmosphere framework
与Spring MVC
集成之后,我想通过SecurityContext(或身份验证)的帮助访问当前的LoggedIn用户,但是当我发送ajax时我给了null来自JSP页面(客户端)的请求。
我的代码或其他一些问题是否有任何问题。下面是我的MyController.java和JSP文件
MyController.Java
@Controller public class MyController { @Autowired PartyManagementService partyManagementService; @RequestMapping(value = "/websockets", method = RequestMethod.POST) @ResponseBody public String post(final AtmosphereResource event, @RequestBody String message) throws JsonGenerationException, JsonMappingException, IOException { User user = (User)SecurityContextHolder.getContext(). getAuthentication().getPrincipal(); String username = user.getUsername(); Person person = partyManagementService.getPersonFromUsername(username); logger.info("Received message to broadcast: {}", message); final int noClients = event.getBroadcaster().getAtmosphereResources().size(); event.getBroadcaster().broadcast(message); return " message successfully send "; } }
在我的家庭jsp中,我提供了一个将消息推送到服务器的ajax请求。