use of org.codehaus.stomp.ProtocolException in project narayana by jbosstm.
the class ProtocolConverter method onStompConnect.
// Implemenation methods
// -------------------------------------------------------------------------
protected void onStompConnect(StompFrame command) throws IOException, JMSException {
if (noneXaSession != null) {
throw new ProtocolException("Already connected.");
}
Map<String, Object> headers = command.getHeaders();
login = (String) headers.get(Stomp.Headers.Connect.LOGIN);
passcode = (String) headers.get(Stomp.Headers.Connect.PASSCODE);
clientId = (String) headers.get(Stomp.Headers.Connect.CLIENT_ID);
Connection noneXaConnection;
if (login != null) {
noneXaConnection = noneXAConnectionFactory.createConnection(login, passcode);
} else {
noneXaConnection = noneXAConnectionFactory.createConnection();
}
if (clientId != null) {
noneXaConnection.setClientID(clientId);
}
noneXaConnection.start();
Session session = noneXaConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
if (log.isDebugEnabled()) {
log.debug("Created session with ack mode: " + session.getAcknowledgeMode());
}
this.noneXaSession = new StompSession(initialContext, this, session, noneXaConnection);
Map<String, Object> responseHeaders = new HashMap<String, Object>();
responseHeaders.put(Stomp.Headers.Connected.SESSION, clientId);
String requestId = (String) headers.get(Stomp.Headers.Connect.REQUEST_ID);
if (requestId == null) {
// TODO legacy
requestId = (String) headers.get(Stomp.Headers.RECEIPT_REQUESTED);
}
if (requestId != null) {
// TODO legacy
responseHeaders.put(Stomp.Headers.Connected.RESPONSE_ID, requestId);
responseHeaders.put(Stomp.Headers.Response.RECEIPT_ID, requestId);
}
StompFrame sc = new StompFrame();
sc.setAction(Stomp.Responses.CONNECTED);
sc.setHeaders(responseHeaders);
sendToStomp(sc);
}
Aggregations