在使用Spring MVC集成Atmosphere框架后无法访问SpringContext

时间:2014-08-01 10:25:18

标签: spring-mvc atmosphere

正如我在标题中提到的那样,在Atmosphere frameworkSpring 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 ";
     }
    }

针对home.jsp

在我的家庭jsp中,我提供了一个将消息推送到服务器的ajax请求。

0 个答案:

没有答案