Search in sources :

Example 1 with InvalidSelectorException

use of jakarta.jms.InvalidSelectorException 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 2 with InvalidSelectorException

use of jakarta.jms.InvalidSelectorException in project openmq by eclipse-ee4j.

the class JMSContextImpl method createBrowser.

@Override
public QueueBrowser createBrowser(Queue queue, String messageSelector) {
    checkNotClosed();
    disallowSetClientID();
    try {
        return session.createBrowser(queue, messageSelector);
    } catch (InvalidDestinationException e) {
        throw new MQInvalidDestinationRuntimeException(e);
    } catch (InvalidSelectorException e) {
        throw new MQInvalidSelectorRuntimeException(e);
    } catch (JMSException e) {
        throw new MQRuntimeException(e);
    }
}
Also used : InvalidSelectorException(jakarta.jms.InvalidSelectorException) MQInvalidDestinationRuntimeException(com.sun.messaging.jms.MQInvalidDestinationRuntimeException) MQInvalidSelectorRuntimeException(com.sun.messaging.jms.MQInvalidSelectorRuntimeException) InvalidDestinationException(jakarta.jms.InvalidDestinationException) JMSException(jakarta.jms.JMSException) MQRuntimeException(com.sun.messaging.jms.MQRuntimeException)

Example 3 with InvalidSelectorException

use of jakarta.jms.InvalidSelectorException 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

InvalidSelectorException (jakarta.jms.InvalidSelectorException)3 JMSException (jakarta.jms.JMSException)3 JMSServiceException (com.sun.messaging.jmq.jmsservice.JMSServiceException)2 JMSServiceReply (com.sun.messaging.jmq.jmsservice.JMSServiceReply)2 JMSSecurityException (jakarta.jms.JMSSecurityException)2 BrokerException (com.sun.messaging.jmq.jmsserver.util.BrokerException)1 IllegalStateException (com.sun.messaging.jms.IllegalStateException)1 MQInvalidDestinationRuntimeException (com.sun.messaging.jms.MQInvalidDestinationRuntimeException)1 MQInvalidSelectorRuntimeException (com.sun.messaging.jms.MQInvalidSelectorRuntimeException)1 MQRuntimeException (com.sun.messaging.jms.MQRuntimeException)1 InvalidDestinationException (jakarta.jms.InvalidDestinationException)1