Search in sources :

Example 11 with JMSServiceException

use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.

the class DirectXAResource method prepare.

/**
 * Ask the resource manager to prepare for a transaction commit of the transaction specified in xid.
 *
 * @param foreignXid A global transaction identifier.
 *
 * @return A value indicating the resource manager's vote on the outcome of the transaction. The possible values are:
 * XA_RDONLY or XA_OK. If the resource manager wants to roll back the transaction, it should do so by raising an
 * appropriate XAException in the prepare method.
 *
 * @throws XAException If an error has occurred. Possible exception values are: XA_RB*, XAER_RMERR, XAER_RMFAIL,
 * XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 */
@Override
public synchronized int prepare(Xid foreignXid) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Prepare     " + printXid(foreignXid) + ", connectionId=" + connectionId);
    }
    // convert to XidImpl
    // XidImpl mqxid = new XidImpl(foreignXid);
    String methodName = "prepare()";
    if (_logFINE) {
        // +
        _loggerJX.fine(// +
        _lgrMID_INF + methodName + ":transactionId=" + this.mTransactionId);
    }
    // JMS does not do RDONLY transactions
    int result = XA_OK;
    // JMSServiceReply reply = null;
    JMSServiceReply.Status status;
    try {
        // reply = jmsservice.prepareTransaction(this.connectionId,
        jmsservice.prepareTransaction(this.connectionId, this.mTransactionId, foreignXid);
        if (_logFINE) {
            _loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":prepared transactionId=" + this.mTransactionId);
        }
    } catch (JMSServiceException jse) {
        status = jse.getJMSServiceReply().getStatus();
        String failure_cause = getFailureCauseAsString(status, jse);
        // XXX:tharakan:This message should be in the JMSServiceException
        String exerrmsg = "prepareTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + // "and Xid:" + mqxid.toString() +
        " due to " + failure_cause;
        _loggerOC.severe(exerrmsg);
        XAException xae = new XAException(XAException.XAER_RMERR);
        xae.initCause(jse);
        throw xae;
    }
    // update the resource state
    resourceState = PREPARED;
    return result;
}
Also used : XAException(javax.transaction.xa.XAException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) Status(com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)

Example 12 with JMSServiceException

use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.

the class StompTransactedSession method createSubscriber.

public StompSubscriber createSubscriber(String subid, StompDestination d, String selector, String duraname, boolean nolocal, StompOutputHandler out) throws Exception {
    checkSession();
    synchronized (this) {
        if (subscribers.get(subid) != null) {
            throw new StompProtocolException("Subscriber " + subid + " already exist in transacted session " + this);
        }
        String stompdest = stompconn.getProtocolHandler().toStompFrameDestination(d, false);
        Destination dest = ((StompDestinationImpl) d).getDestination();
        JMSServiceReply reply = null;
        try {
            reply = jmsservice.createDestination(connectionId, dest);
        } catch (JMSServiceException jmsse) {
            JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
            if (status == JMSServiceReply.Status.CONFLICT) {
                if (getDEBUG()) {
                    logger.log(logger.INFO, "Destination " + stompdest + " already exist");
                }
            } else {
                throw jmsse;
            }
        }
        reply = jmsservice.startConnection(connectionId);
        reply = jmsservice.addConsumer(connectionId, sessionId, dest, selector, duraname, (duraname != null), false, false, stompconn.getClientID(), nolocal);
        long consumerId = reply.getJMQConsumerID();
        TransactedSubscriber sub = new TransactedSubscriber(subid, consumerId, duraname, stompdest, out);
        subscribers.put(subid, sub);
        return sub;
    }
}
Also used : Destination(com.sun.messaging.jmq.jmsservice.Destination) StompDestination(com.sun.messaging.bridge.api.StompDestination) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) StompProtocolException(com.sun.messaging.bridge.api.StompProtocolException)

Example 13 with JMSServiceException

use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.

the class StompSenderSession method sendStompMessage.

public void sendStompMessage(StompFrameMessage message) throws Exception {
    checkSession();
    Packet pkt = new Packet();
    pkt.setPersistent(jmsservice.DEFAULT_MessageDeliveryMode == MessageDeliveryMode.PERSISTENT);
    pkt.setPriority(jmsservice.DEFAULT_MessagePriority.priority());
    pkt.setExpiration(jmsservice.DEFAULT_TIME_TO_LIVE);
    pkt.setDeliveryTime(jmsservice.DEFAULT_DELIVERY_DELAY);
    stompconn.fillRemoteIPAndPort(pkt);
    StompDestinationImpl d = fromStompFrameMessage(message, pkt);
    String stompdest = d.getStompDestinationString();
    try {
        jmsservice.createDestination(connectionId, d.getDestination());
    } catch (JMSServiceException jmsse) {
        JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
        if (status == JMSServiceReply.Status.CONFLICT) {
            if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
                logger.log(logger.INFO, "Destination " + stompdest + " already exist");
            }
        } else {
            throw jmsse;
        }
    }
    synchronized (this) {
        Long prodid = producers.get(stompdest);
        if (prodid == null) {
            JMSServiceReply reply = jmsservice.addProducer(connectionId, sessionId, d.getDestination());
            prodid = Long.valueOf(reply.getJMQProducerID());
            producers.put(stompdest, prodid);
        }
        pkt.setProducerID(prodid.longValue());
    }
    pkt.prepareToSend();
    synchronized (this) {
        if (isTransacted()) {
            pkt.setTransactionID(getTransactionId());
        } else {
            pkt.setTransactionID(0L);
        }
        final Packet p = pkt;
        jmsservice.sendMessage(connectionId, new JMSPacket() {

            @Override
            public Packet getPacket() {
                return p;
            }
        });
    }
    if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
        logger.log(logger.INFO, "Sent message " + pkt.getSysMessageID());
    }
}
Also used : JMSPacket(com.sun.messaging.jmq.io.JMSPacket) Packet(com.sun.messaging.jmq.io.Packet) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSPacket(com.sun.messaging.jmq.io.JMSPacket)

Example 14 with JMSServiceException

use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.

the class StompSubscriberSession method createSubscriber.

public StompSubscriber createSubscriber(StompDestination d, String selector, String duraname, boolean nolocal, StompOutputHandler out) throws Exception {
    if (consumerId != 0L) {
        throw new IllegalStateException("Subscriber already exists on this Session");
    }
    this.out = out;
    this.stompdest = stompconn.getProtocolHandler().toStompFrameDestination(d, false);
    this.duraname = duraname;
    Destination dest = ((StompDestinationImpl) d).getDestination();
    JMSServiceReply reply = null;
    try {
        reply = jmsservice.createDestination(connectionId, dest);
    } catch (JMSServiceException jmsse) {
        JMSServiceReply.Status status = jmsse.getJMSServiceReply().getStatus();
        if (status == JMSServiceReply.Status.CONFLICT) {
            if (logger.isFineLoggable() || stompconn.getProtocolHandler().getDEBUG()) {
                logger.log(logger.INFO, "Destination " + stompdest + " already exist");
            }
        } else {
            throw jmsse;
        }
    }
    reply = jmsservice.startConnection(connectionId);
    reply = jmsservice.addConsumer(connectionId, sessionId, dest, selector, duraname, (duraname != null), false, false, stompconn.getClientID(), nolocal);
    consumerId = reply.getJMQConsumerID();
    if (getDEBUG()) {
        logger.log(logger.INFO, "Created " + this);
    }
    return this;
}
Also used : Destination(com.sun.messaging.jmq.jmsservice.Destination) StompDestination(com.sun.messaging.bridge.api.StompDestination) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException)

Example 15 with JMSServiceException

use of com.sun.messaging.jmq.jmsservice.JMSServiceException in project openmq by eclipse-ee4j.

the class DirectSession method _createAndAddBrowser.

/**
 * Create a Browser with the jmsservice and return a consumerId. Used by the methods implementing jakarta.jms.Session,
 * jakarta.jms.QueueSession, and jakarta.jms.TopicSession
 *
 * @param methodName The JMS API method that was called.
 * @param destination The JMS Destination object identifying the destination on which the browser is to be created.
 * @param selector The JMS Message selector to be used.
 *
 * @return The DirectQueueBrowser object to be returned by the JMS API method.
 *
 * @throws JMSException if any JMS error occurred.
 */
private DirectQueueBrowser _createAndAddBrowser(String methodName, Queue destination, String selector) throws JMSException {
    JMSServiceReply reply;
    long consumerId = 0L;
    DirectQueueBrowser browser = null;
    com.sun.messaging.jmq.jmsservice.Destination jmsservice_dest;
    if (_logFINE) {
        _loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName + ":Destination=" + destination + ":selector=" + selector);
    }
    this._checkIfClosed(methodName);
    jmsservice_dest = this._checkDestinationForConsumer(destination);
    try {
        reply = jmsservice.addBrowser(connectionId, sessionId, jmsservice_dest, selector);
        try {
            // Must get a consumerId from the addBrowser method
            consumerId = reply.getJMQConsumerID();
        } catch (NoSuchFieldException nsfe) {
            String exerrmsg = _lgrMID_EXC + methodName + "JMSServiceException:Missing JMQConsumerID";
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(nsfe);
            _loggerJS.severe(exerrmsg);
            throw jmse;
        }
        browser = new DirectQueueBrowser(this, jmsservice, consumerId, destination, jmsservice_dest, selector);
    } catch (JMSServiceException jse) {
        JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
        String failure_cause;
        JMSException jmsse = null;
        String exerrmsg = "createBrowser on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and sessionId:" + sessionId + " due to ";
        switch(status) {
            case FORBIDDEN:
                failure_cause = "client forbidden to browse messages from this destination.";
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new JMSSecurityException(exerrmsg, jse.getJMSServiceReply().getErrorCode());
                break;
            case NOT_FOUND:
                failure_cause = "destination not found and cannot be auto-created.";
                break;
            case CONFLICT:
                failure_cause = "destination limit for number of consumers exceeded.";
                break;
            case BAD_REQUEST:
                failure_cause = "invalid selector=" + selector;
                exerrmsg = exerrmsg + failure_cause;
                jmsse = new InvalidSelectorException(exerrmsg);
                break;
            default:
                failure_cause = "unkown JMSService server error.";
        }
        _loggerJS.severe(exerrmsg);
        if (jmsse == null) {
            exerrmsg = exerrmsg + failure_cause;
            jmsse = new JMSException(exerrmsg);
        }
        jmsse.initCause(jse);
        throw jmsse;
    }
    this.addBrowser(browser);
    return browser;
}
Also used : InvalidSelectorException(jakarta.jms.InvalidSelectorException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSSecurityException(jakarta.jms.JMSSecurityException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException)

Aggregations

JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)21 JMSException (jakarta.jms.JMSException)15 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)14 JMSSecurityException (jakarta.jms.JMSSecurityException)6 Status (com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)5 XAException (javax.transaction.xa.XAException)5 InvalidSelectorException (jakarta.jms.InvalidSelectorException)4 JMSPacket (com.sun.messaging.jmq.io.JMSPacket)3 SysMessageID (com.sun.messaging.jmq.io.SysMessageID)3 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)3 IllegalStateException (com.sun.messaging.jms.IllegalStateException)3 InvalidDestinationException (jakarta.jms.InvalidDestinationException)3 StompDestination (com.sun.messaging.bridge.api.StompDestination)2 ConsumerClosedNoDeliveryException (com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException)2 Destination (com.sun.messaging.jmq.jmsservice.Destination)2 XidImpl (com.sun.messaging.jmq.util.XidImpl)2 Message (jakarta.jms.Message)2 MessageFormatException (jakarta.jms.MessageFormatException)2 StompProtocolException (com.sun.messaging.bridge.api.StompProtocolException)1 Packet (com.sun.messaging.jmq.io.Packet)1