final QueueSession session;
final EJValue val = JSONDecoder.decode(((TextFrame) frame).getText());
// this is not an active channel.
if (!activeChannels.containsKey(socket)) {
final EJObject ejObject = val.isObject();
if (ejObject == null) {
return;
}
final String commandType = ejObject.get(MessageParts.CommandType.name()).isString().stringValue();
// this client apparently wants to connect.
if (BusCommand.Associate.name().equals(commandType)) {
final String sessionKey = ejObject.get(MessageParts.ConnectionSessionKey.name()).isString().stringValue();
// has this client already attempted a connection, and is in a wait verify state
if (sessionKey != null && (session = service.getBus().getSessionBySessionId(sessionKey)) != null) {
final LocalContext localCometSession = LocalContext.get(session);
if (localCometSession.hasAttribute(WebSocketServerHandler.SESSION_ATTR_WS_STATUS) &&
WebSocketServerHandler.WEBSOCKET_ACTIVE.equals(localCometSession.getAttribute(String.class, WebSocketServerHandler.SESSION_ATTR_WS_STATUS))) {
// set the session queue into direct channel mode.
final MessageQueue queue = service.getBus().getQueueBySession(sessionKey);
queue.setDeliveryHandler(DirectDeliveryHandler.createFor(new SimpleEventChannelWrapped(socket)));
activeChannels.put(socket, session);
return;
}
// check the activation key matches.
final EJString activationKey = ejObject.get(MessageParts.WebSocketToken.name()).isString();
if (activationKey == null || !WebSocketTokenManager.verifyOneTimeToken(session, activationKey.stringValue())) {
// nope. go away!
sendMessage(new SimpleEventChannelWrapped(socket), getFailedNegotiation("bad negotiation key"));
}