Java API websocket. https://spring.io/blog/2013/05/23/spring-framework-4-0-m1-websocket-support
, Spring.
, -
@ServerEndpoint(value = "/sample", configurator = SpringConfigurator.class)
public class SampleEndpoint {
private SessionScopedBean sessionScopedBean;
@Autowired
public SampleEndpoint(SessionScopedBean sessionScopedBean) {
this.sessionScopedBean = sessionScopedBean;
}
}
( bean ), singleton prototype beans .
hanshake :
public class CustomWebSocketConfigurator extends SpringConfigurator {
@Override
public void modifyHandshake(ServerEndpointConfig config,
HandshakeRequest request,
HandshakeResponse response) {
HttpSession httpSession = (HttpSession) request.getHttpSession();
config.getUserProperties().put("some_attribute",
httpSession.getAttribute("some_attribute_in_http_session"));
}
}
. S. , . websocket -. , , , websocket.