Search in sources :

Example 1 with ProtocolException

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);
}
Also used : ProtocolException(org.codehaus.stomp.ProtocolException) HashMap(java.util.HashMap) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) StompFrame(org.codehaus.stomp.StompFrame) XAConnection(javax.jms.XAConnection) Connection(javax.jms.Connection) Session(javax.jms.Session)

Aggregations

HashMap (java.util.HashMap)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Connection (javax.jms.Connection)1 Session (javax.jms.Session)1 XAConnection (javax.jms.XAConnection)1 ProtocolException (org.codehaus.stomp.ProtocolException)1 StompFrame (org.codehaus.stomp.StompFrame)1