}
@Override
public StompFrame onConnect(StompFrame frame)
{
StompFrame response = null;
Map<String, String> headers = frame.getHeadersMap();
String login = headers.get(Stomp.Headers.Connect.LOGIN);
String passcode = headers.get(Stomp.Headers.Connect.PASSCODE);
String clientID = headers.get(Stomp.Headers.Connect.CLIENT_ID);
String requestID = headers.get(Stomp.Headers.Connect.REQUEST_ID);
try
{
if (connection.validateUser(login, passcode))
{
connection.setClientID(clientID);
connection.setValid(true);
response = this.createStompFrame(Stomp.Responses.CONNECTED);
// version
response.addHeader(Stomp.Headers.Connected.VERSION,
connection.getVersion());
// session
response.addHeader(Stomp.Headers.Connected.SESSION, connection
.getID().toString());
// server
response.addHeader(Stomp.Headers.Connected.SERVER,
connection.getHornetQServerName());
if (requestID != null)
{
response.addHeader(Stomp.Headers.Connected.RESPONSE_ID,
requestID);
}
// heart-beat. We need to start after connected frame has been sent.
// otherwise the client may receive heart-beat before it receives
// connected frame.
String heartBeat = headers.get(Stomp.Headers.Connect.HEART_BEAT);
if (heartBeat != null)
{
handleHeartBeat(heartBeat);
if (heartBeater == null)
{
response.addHeader(Stomp.Headers.Connected.HEART_BEAT, "0,0");
}
else
{
response.addHeader(Stomp.Headers.Connected.HEART_BEAT, heartBeater.getServerHeartBeatValue());
}
}
}
else
{
// not valid
response = new StompFrame(Stomp.Responses.ERROR, true);
response.addHeader(Stomp.Headers.Error.MESSAGE, "Failed to connect");
response.setBody("The login account is not valid.");
}
}
catch (HornetQStompException e)
{
response = e.getFrame();