Search in sources :

Example 6 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompConnectionImpl method connect.

/**
 * @return the connection id
 */
@Override
public synchronized String connect(String login, String passcode, String clientid) throws Exception {
    this.clientID = clientid;
    if (connectionID != null) {
        throw new jakarta.jms.IllegalStateException("Unexpected " + StompFrameMessage.Command.CONNECT + ", already connected");
    }
    JMSServiceReply reply = jmsservice.createConnection(login, passcode);
    long connid = reply.getJMQConnectionID();
    connectionID = Long.valueOf(connid);
    closed = false;
    Connection conn = Globals.getConnectionManager().getConnection(new ConnectionUID(connid));
    if (conn != null) {
        conn.addConnectionClosedListener(this);
    } else {
        throw new StompProtocolException("No connection");
    }
    jmsservice.setClientId(connid, clientid, false, /* share */
    null);
    jmsservice.startConnection(connid);
    return connectionID.toString();
}
Also used : JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) StompConnection(com.sun.messaging.bridge.api.StompConnection) Connection(com.sun.messaging.jmq.jmsserver.service.Connection) ConnectionUID(com.sun.messaging.jmq.jmsserver.service.ConnectionUID) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 7 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompSubscriberSession method ack.

public void ack(String msgid, boolean nack) throws Exception {
    checkSession();
    String cmd = (nack ? "[NACK]" : "[ACK]");
    long conid = consumerId;
    if (conid == 0L) {
        throw new StompProtocolException("Can't " + cmd + msgid + " because the subscriber " + subid + "is closed");
    }
    SysMessageID sysid = null;
    try {
        sysid = SysMessageID.get(msgid);
    } catch (RuntimeException e) {
        throw new StompProtocolException(cmd + "invalid message-id" + e.getMessage(), e);
    }
    List<SysMessageID> list = new ArrayList<>();
    synchronized (unackedMessages) {
        int index = unackedMessages.indexOf(sysid);
        if (index < 0) {
            String emsg = cmd + br.getKString(br.X_STOMP_MSG_NOTFOUND_ON_ACK, msgid, this.toString());
            throw new StompProtocolException(emsg);
        }
        if (clientackThisMessage || nack) {
            list.add(sysid);
        } else {
            SysMessageID tmpsysid = null;
            for (int i = 0; i <= index; i++) {
                tmpsysid = unackedMessages.get(i);
                list.add(tmpsysid);
            }
        }
    }
    if (logger.isFineLoggable() || stompconn.getDEBUG()) {
        logger.logInfo(cmd + list.size() + " messages for subscriber " + subid + " on connection " + stompconn, null);
    }
    Iterator<SysMessageID> itr = list.iterator();
    SysMessageID tmpsysid = null;
    while (itr.hasNext()) {
        tmpsysid = itr.next();
        if (logger.isFinestLoggable() || stompconn.getDEBUG()) {
            logger.logInfo(cmd + "message " + tmpsysid + " for subscriber " + subid + " on connection " + stompconn, null);
        }
        if (!nack) {
            jmsservice.acknowledgeMessage(connectionId, sessionId, consumerId, tmpsysid, 0L, MessageAckType.ACKNOWLEDGE, 0);
        } else {
            jmsservice.acknowledgeMessage(connectionId, sessionId, consumerId, tmpsysid, 0L, MessageAckType.DEAD, 1, "STOMP:NACK", null);
        }
        unackedMessages.remove(tmpsysid);
    }
}
Also used : ArrayList(java.util.ArrayList) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 8 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompProtocolHandlerImpl method negotiateVersion.

@Override
public String negotiateVersion(String acceptVersions) throws StompProtocolException {
    if (acceptVersions == null) {
        throw new StompProtocolException(br.getKString(br.X_STOMP_PROTOCOL_VERSION_NO_SUPPORT, StompFrameMessage.STOMP_PROTOCOL_VERSION_10));
    }
    StringTokenizer st = new StringTokenizer(acceptVersions, ",");
    String ver = null;
    while (st.hasMoreElements()) {
        ver = st.nextToken();
        if (Version.compareVersions(ver, StompFrameMessage.STOMP_PROTOCOL_VERSION_12) == 0) {
            return StompFrameMessage.STOMP_PROTOCOL_VERSION_12;
        }
    }
    throw new StompProtocolException(br.getKString(br.X_STOMP_PROTOCOL_VERSION_NO_SUPPORT, acceptVersions));
}
Also used : StringTokenizer(java.util.StringTokenizer) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 9 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompConnectionImpl method createSubscriberSession.

/**
 */
private synchronized StompSubscriberSession createSubscriberSession(String subid, StompAckMode ackMode) throws Exception {
    Connection conn = _connection;
    checkConnection(conn);
    if (subid == null) {
        throw new IllegalArgumentException("No subscription id");
    }
    StompSubscriberSession ss = _subSessions.get(subid);
    if (ss != null) {
        throw new StompProtocolException(_sbr.getKString(_sbr.X_SUBSCRIBER_ID_EXIST, subid));
    }
    ss = new StompSubscriberSession(subid, ackMode, this);
    _subSessions.put(subid, ss);
    return ss;
}
Also used : StompConnection(com.sun.messaging.bridge.api.StompConnection) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 10 with StompProtocolException

use of com.sun.messaging.bridge.api.StompProtocolException in project openmq by eclipse-ee4j.

the class StompTransactedSession method begin.

public void begin(String stomptid) throws Exception {
    checkSession();
    synchronized (this) {
        if (getDEBUG()) {
            logger.log(logger.INFO, "Begin transaction " + stomptid + " in [" + this + "]");
        }
        if (tid != null) {
            throw new StompProtocolException("Transaction session has current transaction " + tid);
        }
        JMSServiceReply reply = jmsservice.startTransaction(connectionId, sessionId, null, 0, TransactionAutoRollback.UNSPECIFIED, 0L);
        transactionId = reply.getJMQTransactionID();
        setStompTransactionId(stomptid);
    }
}
Also used : JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Aggregations

StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)10 StompConnection (com.sun.messaging.bridge.api.StompConnection)5 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)3 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)2 ArrayList (java.util.ArrayList)2 StompDestination (com.sun.messaging.bridge.api.StompDestination)1 Connection (com.sun.messaging.jmq.jmsserver.service.Connection)1 ConnectionUID (com.sun.messaging.jmq.jmsserver.service.ConnectionUID)1 Destination (com.sun.messaging.jmq.jmsservice.Destination)1 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)1 StringTokenizer (java.util.StringTokenizer)1