Search in sources :

Example 1 with JMSServiceException

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

the class DirectSession method _fetchMessage.

/**
 * Fetch a message for a consumer performing a sync receive.
 * <p>
 * Only one thread in a session can do this at a time.
 */
protected synchronized jakarta.jms.Message _fetchMessage(DirectConsumer consumer, long consumerId, long timeout, String methodName) throws JMSException {
    JMSPacket jmsPacket = null;
    jakarta.jms.Message jmsMsg = null;
    SysMessageID messageID = null;
    long xaTxnId = 0L;
    if (this.dc.isManaged() && this.dc.isEnlisted()) {
        xaTxnId = this.dc._getXAResource()._getTransactionId();
    } else {
        xaTxnId = this._getTransactionId();
    }
    try {
        jmsPacket = this.jmsservice.fetchMessage(this.connectionId, this.sessionId, consumerId, timeout, this.ackOnFetch, xaTxnId);
    } catch (JMSServiceException jmsse) {
    }
    if (jmsPacket == null) {
        return null;
    } else {
        try {
            jmsMsg = DirectPacket.constructMessage(jmsPacket, consumerId, this, this.jmsservice, false);
            consumer.setLastMessageSeen(((DirectPacket) jmsMsg).getReceivedSysMessageID());
            if (this.ackMode == SessionAckMode.CLIENT_ACKNOWLEDGE) {
                messageID = ((DirectPacket) jmsMsg).getReceivedSysMessageID();
                // Insert the message's ReceivedSysMessageID + consumerId
                // for recover
                unackedMessageIDs.add(messageID);
                unackedConsumerIDs.add(consumerId);
            }
            return jmsMsg;
        } catch (Exception e) {
            String exerrmsg = _lgrMID_EXC + "receive:Exception constructing message:" + e.getMessage();
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(e);
            _loggerJS.warning(exerrmsg);
            throw jmse;
        }
    }
}
Also used : Message(jakarta.jms.Message) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSPacket(com.sun.messaging.jmq.io.JMSPacket) SysMessageID(com.sun.messaging.jmq.io.SysMessageID) JMSException(jakarta.jms.JMSException) JMSException(jakarta.jms.JMSException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) InvalidDestinationException(jakarta.jms.InvalidDestinationException) MessageFormatException(jakarta.jms.MessageFormatException) InvalidSelectorException(jakarta.jms.InvalidSelectorException) ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) IllegalStateException(com.sun.messaging.jms.IllegalStateException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) JMSSecurityException(jakarta.jms.JMSSecurityException)

Example 2 with JMSServiceException

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

the class DirectSession method _createAndAddConsumer.

/**
 * Create a consumerId with the jmsservice and return a MessageConsumer object that can be returned by the JMS API
 * method.
 * <p>
 * This method is used by the methods implementing jakarta.jms.Session, jakarta.jms.QueueSession, and
 * jakarta.jms.TopicSession<br>
 * A successfully created DirectConsumer is added to the table of Consumer objects maintained by this DirectSession.<br>
 * A successfully created durable DirectConsumer is added to the table of durable Consumer objects maintained by the
 * DirectConnection of this DirectSession.
 *
 * @param methodName The JMS API method that was called.
 * @param destination The JMS Destination object identifying the destination on which the consumer is to be created.
 * @param selector The JMS Message selector to be used.
 * @param subscriptionName if dest is Topic and if either durable true or share true, the subscription name
 * @param durable if dest is Topic, if true, this is a durable subscription
 * @param share if dest is Topic, if true, this is a shared subscription
 * @param jmsshare if dest is Topic, if true and share true, this is a JMS 2.0 Shared Subscription if false and share
 * true, this is a MQ Shared Subscription
 *
 * MQ Shared Subscription: messages will be shared with other consumers in the same group that have the same
 * clientId+DurableName for Shared Durable Subscriptions
 * <p>
 * OR
 * <p>
 * clientId+TopicName+Selector for Shared Non-Durable Sunscriptions
 *
 * @param noLocal If {@code true} then this consumer does not want to messages produced on it'sconnection to be
 * delivered to it.
 *
 * @return The DirectConsumer object to be returned by the JMS API method.
 *
 * @throws JMSException if any JMS error occurred.
 */
private DirectConsumer _createAndAddConsumer(String methodName, Destination destination, String selector, String subscriptionName, boolean durable, boolean share, boolean jmsshare, boolean noLocal) throws JMSException {
    JMSServiceReply reply;
    long consumerId = 0L;
    com.sun.messaging.jmq.jmsservice.Destination jmsservice_dest;
    if (_logFINE) {
        _loggerJS.fine(_lgrMID_INF + "sessionId=" + this.sessionId + ":" + methodName + ":Destination=" + destination + ":Selector=" + selector + ":subscriptionName=" + subscriptionName + ":durable=" + durable + ":share=" + share + ":jmsshare=" + jmsshare + ":noLocal=" + noLocal);
    }
    this._checkIfClosed(methodName);
    jmsservice_dest = this._checkDestinationForConsumer(destination);
    String duraname = (durable ? subscriptionName : null);
    DirectConsumer consumer = new DirectConsumer(this, jmsservice, destination, jmsservice_dest, noLocal, selector, duraname);
    try {
        // adjusted for JMS 2.0
        reply = jmsservice.addConsumer(connectionId, sessionId, jmsservice_dest, selector, subscriptionName, durable, share, jmsshare, this.getConnection()._getClientID(), noLocal);
        /*
             * reply = jmsservice.addConsumer(connectionId, sessionId, jmsservice_dest, selector, durableName,
             * this.getConnection()._getClientID(), noLocal, //XXX:tharakan:using false for shared temporarily false, false);
             */
        try {
            // Set consumerId right away
            consumerId = reply.getJMQConsumerID();
            consumer._setConsumerId(consumerId);
        } catch (NoSuchFieldException nsfe) {
            String exerrmsg = _lgrMID_EXC + "JMSServiceException:Missing JMQConsumerID";
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(nsfe);
            _loggerJS.severe(exerrmsg);
            throw jmse;
        }
    } catch (JMSServiceException jse) {
        JMSServiceReply.Status status = jse.getJMSServiceReply().getStatus();
        String failure_cause;
        JMSException jmsse = null;
        String exerrmsg = "createConsumer on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and sessionId:" + sessionId + " due to ";
        switch(status) {
            case FORBIDDEN:
                failure_cause = "client forbidden to receive 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;
            case PRECONDITION_FAILED:
                if (jse.getCause() != null && jse.getCause() instanceof BrokerException) {
                    failure_cause = jse.getCause().getMessage();
                    exerrmsg = exerrmsg + failure_cause;
                    jmsse = new IllegalStateException(exerrmsg, ((BrokerException) jse.getCause()).getErrorCode());
                    break;
                }
            default:
                failure_cause = "unknown JMSService server error.";
        }
        _loggerJS.severe(exerrmsg);
        if (jmsse == null) {
            exerrmsg = exerrmsg + failure_cause;
            jmsse = new JMSException(exerrmsg);
        }
        jmsse.initCause(jse);
        throw jmsse;
    }
    this.addConsumer(consumer);
    if (subscriptionName != null && durable) {
        this.dc.addDurableConsumer(consumer);
    }
    if (destination instanceof TemporaryDestination) {
        this.dc._incrementTemporaryDestinationUsage((TemporaryDestination) destination);
    }
    return consumer;
}
Also used : IllegalStateException(com.sun.messaging.jms.IllegalStateException) InvalidSelectorException(jakarta.jms.InvalidSelectorException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) JMSSecurityException(jakarta.jms.JMSSecurityException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException)

Example 3 with JMSServiceException

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

the class DirectSession method _fetchMessageBody.

/**
 * Fetch the body of a message for a consumer performing a sync receive.
 * <p>
 * Only one thread in a session can do this at a time.
 */
protected synchronized <T> T _fetchMessageBody(DirectConsumer consumer, long consumerId, long timeout, Class<T> c, String methodName) throws JMSException {
    T body = null;
    MessageFormatException savedMFE = null;
    JMSPacket jmsPacket = null;
    jakarta.jms.Message jmsMsg = null;
    SysMessageID messageID = null;
    long xaTxnId = 0L;
    if (this.dc.isManaged() && this.dc.isEnlisted()) {
        xaTxnId = this.dc._getXAResource()._getTransactionId();
    } else {
        xaTxnId = this._getTransactionId();
    }
    try {
        // get the next message but don't auto-acknowledge it
        boolean autoAcknowledge = false;
        jmsPacket = this.jmsservice.fetchMessage(this.connectionId, this.sessionId, consumerId, timeout, autoAcknowledge, xaTxnId);
    } catch (JMSServiceException jmsse) {
        throw new com.sun.messaging.jms.JMSException(jmsse.getMessage(), null, jmsse);
    }
    if (jmsPacket != null) {
        try {
            jmsMsg = DirectPacket.constructMessage(jmsPacket, consumerId, this, this.jmsservice, false);
            if (this.ackMode == SessionAckMode.CLIENT_ACKNOWLEDGE) {
                messageID = ((DirectPacket) jmsMsg).getReceivedSysMessageID();
                // Insert the message's ReceivedSysMessageID + consumerId
                // for recover
                unackedMessageIDs.add(messageID);
                unackedConsumerIDs.add(consumerId);
            }
        } catch (Exception e) {
            String exerrmsg = _lgrMID_EXC + "receive:Exception constructing message:" + e.getMessage();
            JMSException jmse = new JMSException(exerrmsg);
            jmse.initCause(e);
            _loggerJS.warning(exerrmsg);
            throw jmse;
        }
        try {
            body = returnPayload(jmsMsg, c);
            consumer.setLastMessageSeen(((DirectPacket) jmsMsg).getReceivedSysMessageID());
        } catch (MessageFormatException mfe) {
            // message could not be converted
            if (xaTxnId == 0L && (getAcknowledgeMode() == Session.AUTO_ACKNOWLEDGE || getAcknowledgeMode() == Session.DUPS_OK_ACKNOWLEDGE)) {
                // note that we don't call setLastMessageSeen in this case
                try {
                    SysMessageID[] messageIDs = new SysMessageID[1];
                    messageIDs[0] = jmsPacket.getPacket().getSysMessageID();
                    Long[] consumerIDs = new Long[1];
                    consumerIDs[0] = consumerId;
                    boolean setRedelivered = false;
                    jmsservice.redeliverMessages(this.connectionId, this.sessionId, messageIDs, consumerIDs, xaTxnId, setRedelivered);
                } catch (JMSServiceException jmsse) {
                    throw new com.sun.messaging.jms.JMSException(jmsse.getMessage(), null, jmsse);
                }
                // throw now before we acknowledge it
                throw mfe;
            } else {
                consumer.setLastMessageSeen(((DirectPacket) jmsMsg).getReceivedSysMessageID());
                // throw at end of method
                savedMFE = mfe;
            }
        }
        if (this.ackOnFetch) {
            try {
                // ??
                SysMessageID sysMessageID = jmsPacket.getPacket().getSysMessageID();
                jmsservice.acknowledgeMessage(connectionId, sessionId, consumerId, sysMessageID, xaTxnId, MessageAckType.ACKNOWLEDGE);
            } catch (JMSServiceException e) {
            }
        }
    }
    if (savedMFE != null)
        throw savedMFE;
    return body;
}
Also used : MessageFormatException(jakarta.jms.MessageFormatException) Message(jakarta.jms.Message) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSPacket(com.sun.messaging.jmq.io.JMSPacket) JMSException(jakarta.jms.JMSException) JMSException(jakarta.jms.JMSException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) InvalidDestinationException(jakarta.jms.InvalidDestinationException) MessageFormatException(jakarta.jms.MessageFormatException) InvalidSelectorException(jakarta.jms.InvalidSelectorException) ConsumerClosedNoDeliveryException(com.sun.messaging.jmq.jmsservice.ConsumerClosedNoDeliveryException) IllegalStateException(com.sun.messaging.jms.IllegalStateException) BrokerException(com.sun.messaging.jmq.jmsserver.util.BrokerException) JMSSecurityException(jakarta.jms.JMSSecurityException) SysMessageID(com.sun.messaging.jmq.io.SysMessageID)

Example 4 with JMSServiceException

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

the class DirectSession method unsubscribe.

/**
 * Unsubscribe the durable subscription specified by name
 */
@Override
public void unsubscribe(String name) throws JMSException {
    String methodName = "unsubscribe()";
    if (_logFINE) {
        _loggerJS.fine(_lgrMID_INF + "sessionId=" + sessionId + ":" + methodName);
    }
    this._checkIfClosed(methodName);
    if (name == null || "".equals(name)) {
        throw new InvalidDestinationException("NULL or empty name for unsubscribe");
    }
    // cycle through consumers and check if one of them is lose them one by one
    DirectConsumer dc = null;
    Iterator<DirectConsumer> k = this.dc._getDurableConsumers().iterator();
    while (k.hasNext()) {
        dc = k.next();
        if (name.equals(dc.getDurableName())) {
            String exErrMsg = _lgrMID_WRN + "sessionId=" + sessionId + ":" + methodName + ":name:" + name + ":Is in use";
            _loggerJS.warning(exErrMsg);
            JMSException jmse = new JMSException(exErrMsg);
            throw jmse;
        }
    }
    try {
        // this method returns a JMSServiceReply but we don't need to check it since
        // an exception will be thrown if it is not OK
        jmsservice.deleteConsumer(this.connectionId, this.sessionId, 0L, null, false, name, this.dc._getClientID());
    } catch (JMSServiceException jmsse) {
        String exErrMsg = _lgrMID_EXC + "sessionId=" + sessionId + ":" + methodName + ":name:" + name + ":error=" + jmsse.getMessage();
        _loggerJS.warning(exErrMsg);
        JMSException jmse = new InvalidDestinationException(exErrMsg);
        jmse.initCause(jmsse);
        throw jmse;
    }
}
Also used : JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) InvalidDestinationException(jakarta.jms.InvalidDestinationException) JMSException(jakarta.jms.JMSException)

Example 5 with JMSServiceException

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

the class DirectXAResource method commit.

/**
 * Commit the global transaction specified by xid.
 *
 * @param foreignXid A global transaction identifier
 *
 * @param onePhase If true, the resource manager should use a one-phase commit protocol to commit the work done on
 * behalf of xid.
 *
 * @throws XAException An error has occurred. Possible XAExceptions are XA_HEURHAZ, XA_HEURCOM, XA_HEURRB, XA_HEURMIX,
 * XAER_RMERR, XAER_RMFAIL, XAER_NOTA, XAER_INVAL, or XAER_PROTO.
 *
 * <P>
 * If the resource manager did not commit the transaction and the parameter onePhase is set to true, the resource
 * manager may throw one of the XA_RB* exceptions. Upon return, the resource manager has rolled back the branch's work
 * and has released all held resources.
 */
@Override
public synchronized void commit(Xid foreignXid, boolean onePhase) throws XAException {
    if (_logger.isLoggable(Level.FINE)) {
        _logger.fine(_lgrMID_INF + "DirectXAResource (" + this.hashCode() + ") Commit  " + printXid(foreignXid) + " (onePhase=" + onePhase + "), connectionId=" + connectionId);
    }
    // convert to XidImpl
    // XidImpl mqxid = new XidImpl(foreignXid);
    String methodName = "commit()";
    if (_logFINE) {
        // +"Xid="+mqxid.toString()
        _loggerJX.fine(// +"Xid="+mqxid.toString()
        _lgrMID_INF + methodName + ":onePhase=" + onePhase + ":transactionId=" + this.mTransactionId);
    }
    boolean rbrollback = false;
    Exception rbrollbackex = null;
    // JMSServiceReply reply = null;
    JMSServiceReply.Status status;
    try {
        // reply = jmsservice.commitTransaction(this.connectionId,
        jmsservice.commitTransaction(this.connectionId, this.mTransactionId, foreignXid, (onePhase ? XAResource.TMONEPHASE : XAResource.TMNOFLAGS));
        this.setEnlisted(false);
        if (_logFINE) {
            _loggerJX.fine(_lgrMID_INF + methodName + ":connectionId=" + this.connectionId + ":committed 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 = "commitTransaction (XA) on JMSService:" + jmsservice.getJMSServiceID() + " failed for connectionId:" + connectionId + " and onePhase:" + onePhase + // "and Xid:" + mqxid.toString() +
        " due to " + failure_cause;
        _loggerOC.severe(exerrmsg);
        if (onePhase) {
            rbrollback = true;
            rbrollbackex = jse;
        }
        if (!rbrollback) {
            XAException xae = new XAException(XAException.XAER_RMFAIL);
            xae.initCause(jse);
            throw xae;
        }
    } finally {
        if (!rbrollback) {
            // finish up this resource and any others joined to it in this transaction
            boolean throwExceptionIfNotFound = false;
            XidImpl savedXid = this.mXid;
            DirectXAResource[] resources = DirectXAResourceMap.getXAResources(this.mXid, throwExceptionIfNotFound);
            for (int i = 0; i < resources.length; i++) {
                DirectXAResource xari = resources[i];
                try {
                    xari.clearTransactionInfo();
                } catch (JMSException jmse) {
                    _loggerJX.log(Level.SEVERE, "MQRA:DXAR:commit:XAException-Exception=" + jmse.getMessage(), jmse);
                    Debug.printStackTrace(jmse);
                    XAException xae = new XAException(XAException.XAER_RMFAIL);
                    xae.initCause(jmse);
                    throw xae;
                }
            }
            DirectXAResourceMap.unregister(savedXid);
        }
    }
    if (rbrollback) {
        XAException xae;
        try {
            rollback(foreignXid, DirectXAResourceMap.MAXROLLBACKS, DirectXAResourceMap.DMQ_ON_MAXROLLBACKS);
            xae = new XAException(XAException.XA_RBROLLBACK);
            xae.initCause(rbrollbackex);
        } catch (Exception e) {
            _loggerJX.log(Level.SEVERE, "Exception on rollback transaction " + foreignXid + "[" + mTransactionId + "] after 1-phase-commit failure", e);
            xae = new XAException(XAException.XAER_RMFAIL);
            xae.initCause(rbrollbackex);
        }
        throw xae;
    }
}
Also used : XAException(javax.transaction.xa.XAException) JMSServiceReply(com.sun.messaging.jmq.jmsservice.JMSServiceReply) XidImpl(com.sun.messaging.jmq.util.XidImpl) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) JMSException(jakarta.jms.JMSException) JMSException(jakarta.jms.JMSException) JMSServiceException(com.sun.messaging.jmq.jmsservice.JMSServiceException) XAException(javax.transaction.xa.XAException) Status(com.sun.messaging.jmq.jmsservice.JMSServiceReply.Status)

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