public void onRequest(AtmosphereResource resource) throws IOException {
AtmosphereResourceSession resourceSession =
AtmosphereResourceSessionFactory.getDefault().getSession(resource);
AtmosphereChannel resourceChannel =
resourceSession.getAttribute(WAVE_CHANNEL_ATTRIBUTE, AtmosphereChannel.class);
if (resourceChannel == null) {
ParticipantId loggedInUser =
provider.sessionManager.getLoggedInUser(resource.getRequest().getSession(false));
AtmosphereConnection connection = new AtmosphereConnection(loggedInUser, provider);
resourceChannel = connection.getAtmosphereChannel();
resourceSession.setAttribute(WAVE_CHANNEL_ATTRIBUTE, resourceChannel);
resourceChannel.onConnect(resource);
}
resource.setBroadcaster(resourceChannel.getBroadcaster()); // on every
// request
if (resource.getRequest().getMethod().equalsIgnoreCase("GET")) {
resource.suspend();
}
if (resource.getRequest().getMethod().equalsIgnoreCase("POST")) {
StringBuilder b = IOUtils.readEntirely(resource);
resourceChannel.onMessage(b.toString());
}
}