Search in sources :

Example 1 with JMSSecurityException

use of javax.jms.JMSSecurityException in project ACS by ACS-Community.

the class DefaultSubscriberImpl method subscribe.

/**
   * Method subscribe
   *
   *
   * @param topic
   * @param listener
   * @param selector
   *
   * @return long the subscription handle identifier
   *
   * @throws JMSException
   * @throws NamingException
   *
   */
public long subscribe(String topic, SubscriptionListener listener, String selector) throws JMSException, NamingException {
    cat.info("subscribe(" + topic + ", listener, " + selector + ")");
    if (closed) {
        throw (new JMSException("Subscriber closed."));
    }
    SubscriptionHandle handle = new SubscriptionHandle();
    handle.setSubscriptionTopic(topic);
    handle.setSubscriptionSelector(selector);
    handle.setSubscriptionListener(listener);
    StringBuffer local_selector = new StringBuffer();
    if (NotificationHelper.isNotification(topic)) {
        // this is a subscription to notifications, no further selection is required
        local_selector.append(selector);
    } else {
        // subscription to a generic topic, adding subscriber specific selection
        if (selector != null) {
            local_selector.append(selector);
            local_selector.append(" AND ");
        }
        local_selector.append("( (");
        local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
        local_selector.append(" IS NULL) OR (");
        local_selector.append(NotificationHelper.SUBSCRIPTION_ID_PROPERTY);
        local_selector.append(" = '");
        local_selector.append(subscriberId);
        local_selector.append("@");
        local_selector.append(handle.getSubscriptionToken());
        local_selector.append("') )");
    }
    TopicSession session = null;
    TopicSubscriber subscriber = null;
    Topic the_topic = createTopic(topic);
    try {
        session = connection.createTopicSession();
        subscriber = session.createSubscriber(the_topic, local_selector.toString(), false);
    } catch (JMSSecurityException jse) {
        cat.error("JMSSecurityException caught");
        throw (new NamingException(jse.getMessage()));
    } catch (JMSException je) {
        cat.error("JMSException caught");
        throw (new NamingException(je.getMessage()));
    } catch (ConnectionException ce) {
        cat.error("ConnectionException caught");
        throw (new JMSException(ce.getMessage()));
    } catch (Exception e) {
        cat.error("Generic exception caught", e);
    }
    subscriber.setMessageListener(listener);
    handle.setSubscriber(subscriber);
    handle.setSession(session);
    synchronized (subscribers) {
        subscribers.put(new Long(handle.getSubscriptionToken()), handle);
    }
    if (!NotificationHelper.isNotification(topic)) {
        publishNotification(NotificationHelper.CONSUMER_OPEN_NOTIFICATION, handle);
    }
    return handle.getSubscriptionToken();
}
Also used : TopicSubscriber(javax.jms.TopicSubscriber) TopicSession(javax.jms.TopicSession) JMSSecurityException(javax.jms.JMSSecurityException) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) Topic(javax.jms.Topic) NamingException(javax.naming.NamingException) JMSException(javax.jms.JMSException) MOMException(cern.cmw.mom.pubsub.MOMException) JMSSecurityException(javax.jms.JMSSecurityException)

Example 2 with JMSSecurityException

use of javax.jms.JMSSecurityException in project ACS by ACS-Community.

the class DefaultPublisherImpl method publish.

/**
   * Publish a message to the given topic.
   * @param topic The String representation of the topic
   * @param message The Message object to publish
   * @param deliveryMode The Message persistence
   * @param priority The Message priority
   * @param timeToLive The Message time to live
   * @exception JMSException if JMS fails to publish the message due to some internal JMS error.
   * @exception NamingException  if there is a violation in the namespace policy.
   */
public void publish(String topic, Message message, int deliveryMode, int priority, long timeToLive) throws JMSException, NamingException {
    cat.debug("publish(" + topic + ", " + message + ")");
    if (closed) {
        throw (new JMSException("Publisher object has been closed"));
    }
    Topic t = createTopic(topic);
    try {
        publisher.publish(t, message, deliveryMode, priority, timeToLive);
    } catch (JMSSecurityException jse) {
        cat.error("JMSSecurityException caught");
        throw (new NamingException(jse.getMessage()));
    }
}
Also used : JMSSecurityException(javax.jms.JMSSecurityException) JMSException(javax.jms.JMSException) NamingException(javax.naming.NamingException) Topic(javax.jms.Topic)

Aggregations

JMSException (javax.jms.JMSException)2 JMSSecurityException (javax.jms.JMSSecurityException)2 Topic (javax.jms.Topic)2 NamingException (javax.naming.NamingException)2 MOMException (cern.cmw.mom.pubsub.MOMException)1 TopicSession (javax.jms.TopicSession)1 TopicSubscriber (javax.jms.TopicSubscriber)1