if (client!=null)
throw new IllegalStateException();
if (_securityPolicy!=null && !_securityPolicy.canHandshake(message))
{
Message reply=newMessage(message);
reply.put(CHANNEL_FIELD,META_HANDSHAKE);
reply.put(SUCCESSFUL_FIELD,Boolean.FALSE);
reply.put(ERROR_FIELD,"403::Handshake denied");
for (Extension e:_extensions)
reply=e.sendMeta(reply);
transport.send(reply);
return;
}
client=newRemoteClient();
Map<?,?> ext = (Map<?,?>)message.get(EXT_FIELD);
boolean commented=_JSONCommented && ext!=null && Boolean.TRUE.equals(ext.get("json-comment-filtered"));
Message reply=newMessage(message);
reply.put(CHANNEL_FIELD,META_HANDSHAKE);
reply.put("version","1.0");
reply.put("minimumVersion","0.9");
if (isJSONCommented())
reply.put(EXT_FIELD,EXT_JSON_COMMENTED);
if (client!=null)
{
reply.put("supportedConnectionTypes",_transports);
reply.put("successful",Boolean.TRUE);
reply.put(CLIENT_FIELD,client.getId());
if (_advice!=null)
reply.put(ADVICE_FIELD,_advice);
client.setJSONCommented(commented);
transport.setJSONCommented(commented);
}
else
{
reply.put(Bayeux.SUCCESSFUL_FIELD,Boolean.FALSE);
if (_advice!=null)
reply.put(ADVICE_FIELD,_advice);
}
if (isLogDebug())
logDebug("handshake.handle: reply="+reply);
String id=message.getId();
if (id!=null)
reply.put(ID_FIELD,id);
for (Extension e:_extensions)
reply=e.sendMeta(reply);
transport.send(reply);
}