Search in sources :

Example 11 with JMSRuntimeException

use of javax.jms.JMSRuntimeException in project pentaho-kettle by pentaho.

the class JmsStreamSourceTest method handlesJmsRuntimeException.

@Test(timeout = 5000)
public void handlesJmsRuntimeException() {
    when(consumer.receive(0)).thenThrow(new JMSRuntimeException("exception"));
    source.open();
    verify(delegate).getJmsContext();
    verify(delegate).getDestination();
    try {
        source.flowable().firstElement().blockingGet(Collections.emptyList());
        fail("Expected exception ");
    } catch (Exception e) {
        assertTrue(e instanceof JMSRuntimeException);
    }
}
Also used : JMSException(javax.jms.JMSException) JMSRuntimeException(javax.jms.JMSRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 12 with JMSRuntimeException

use of javax.jms.JMSRuntimeException in project qpid-broker-j by apache.

the class DeliveryDelayTest method testDeliveryDelayNotSupportedByQueueViaExchange_MessageRejected.

/**
 * The client sends a messagge to a fanout exchange instance which is bound to a queue with
 * holdsOnPublish turned off. The Broker must reject the message.
 */
@Test
public void testDeliveryDelayNotSupportedByQueueViaExchange_MessageRejected() throws Exception {
    try (JMSContext context = getConnectionBuilder().buildConnectionFactory().createContext()) {
        String testQueueName = BrokerAdmin.TEST_QUEUE_NAME;
        String testExchangeName = "test_exch";
        Destination consumeDest = createQueue(context, testQueueName, false);
        Destination publishDest = createExchange(context, testExchangeName);
        bindQueueToExchange(testExchangeName, testQueueName);
        JMSConsumer consumer = context.createConsumer(consumeDest);
        JMSProducer producer = context.createProducer();
        producer.send(publishDest, "message without delivery delay");
        Message message = consumer.receive(getReceiveTimeout());
        assertNotNull("Message published without delivery delay not received", message);
        producer.setDeliveryDelay(DELIVERY_DELAY);
        try {
            producer.send(publishDest, "message with delivery delay");
            fail("Exception not thrown");
        } catch (JMSRuntimeException e) {
            assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("amqp:precondition-failed"));
        }
    }
}
Also used : Destination(javax.jms.Destination) JMSConsumer(javax.jms.JMSConsumer) Message(javax.jms.Message) JMSProducer(javax.jms.JMSProducer) JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 13 with JMSRuntimeException

use of javax.jms.JMSRuntimeException in project qpid-broker-j by apache.

the class DeliveryDelayTest method testDeliveryDelayNotSupportedByQueue_MessageRejected.

/**
 * The target queue, which is addressed directly by the client, does not have
 * holdsOnPublish turned on.  The Broker must reject the message.
 */
@Test
public void testDeliveryDelayNotSupportedByQueue_MessageRejected() throws Exception {
    try (JMSContext context = getConnectionBuilder().buildConnectionFactory().createContext()) {
        Destination queue = createQueue(context, BrokerAdmin.TEST_QUEUE_NAME, false);
        JMSProducer producer = context.createProducer().setDeliveryDelay(DELIVERY_DELAY);
        try {
            producer.send(queue, "message");
            fail("Exception not thrown");
        } catch (JMSRuntimeException e) {
            assertTrue("Unexpected exception message: " + e.getMessage(), e.getMessage().contains("amqp:precondition-failed"));
        }
    }
}
Also used : Destination(javax.jms.Destination) JMSProducer(javax.jms.JMSProducer) JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 14 with JMSRuntimeException

use of javax.jms.JMSRuntimeException in project activemq-artemis by apache.

the class ActiveMQJMSProducer method getObjectProperty.

@Override
public Object getObjectProperty(String name) {
    try {
        SimpleString key = new SimpleString(name);
        Object property = properties.getProperty(key);
        if (stringPropertyNames.contains(key)) {
            property = property.toString();
        }
        return property;
    } catch (ActiveMQPropertyConversionException ce) {
        throw new MessageFormatRuntimeException(ce.getMessage());
    } catch (RuntimeException e) {
        throw new JMSRuntimeException(e.getMessage());
    }
}
Also used : MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageFormatRuntimeException(javax.jms.MessageFormatRuntimeException) ActiveMQPropertyConversionException(org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException) JMSRuntimeException(javax.jms.JMSRuntimeException)

Example 15 with JMSRuntimeException

use of javax.jms.JMSRuntimeException in project activemq-artemis by apache.

the class ActiveMQConnection method createSessionInternal.

protected final ActiveMQSession createSessionInternal(final boolean isXA, final boolean transacted, int acknowledgeMode, final int type) throws JMSException {
    if (transacted) {
        acknowledgeMode = Session.SESSION_TRANSACTED;
    }
    try {
        ClientSession session;
        boolean isBlockOnAcknowledge = sessionFactory.getServerLocator().isBlockOnAcknowledge();
        int ackBatchSize = sessionFactory.getServerLocator().getAckBatchSize();
        if (acknowledgeMode == Session.SESSION_TRANSACTED) {
            session = sessionFactory.createSession(username, password, isXA, false, false, sessionFactory.getServerLocator().isPreAcknowledge(), transactionBatchSize);
        } else if (acknowledgeMode == Session.AUTO_ACKNOWLEDGE) {
            session = sessionFactory.createSession(username, password, isXA, true, true, sessionFactory.getServerLocator().isPreAcknowledge(), 0);
        } else if (acknowledgeMode == Session.DUPS_OK_ACKNOWLEDGE) {
            session = sessionFactory.createSession(username, password, isXA, true, true, sessionFactory.getServerLocator().isPreAcknowledge(), dupsOKBatchSize);
        } else if (acknowledgeMode == Session.CLIENT_ACKNOWLEDGE) {
            session = sessionFactory.createSession(username, password, isXA, true, false, sessionFactory.getServerLocator().isPreAcknowledge(), isBlockOnAcknowledge ? transactionBatchSize : ackBatchSize);
        } else if (acknowledgeMode == ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE) {
            session = sessionFactory.createSession(username, password, isXA, true, false, false, isBlockOnAcknowledge ? transactionBatchSize : ackBatchSize);
        } else if (acknowledgeMode == ActiveMQJMSConstants.PRE_ACKNOWLEDGE) {
            session = sessionFactory.createSession(username, password, isXA, true, false, true, transactionBatchSize);
        } else {
            throw new JMSRuntimeException("Invalid ackmode: " + acknowledgeMode);
        }
        justCreated = false;
        // Setting multiple times on different sessions doesn't matter since RemotingConnection
        // maintains
        // a set (no duplicates)
        session.addFailureListener(listener);
        session.addFailoverListener(failoverListener);
        ActiveMQSession jbs = createAMQSession(isXA, transacted, acknowledgeMode, session, type);
        sessions.add(jbs);
        if (started) {
            session.start();
        }
        this.addSessionMetaData(session);
        return jbs;
    } catch (ActiveMQException e) {
        throw JMSExceptionHelper.convertFromActiveMQException(e);
    }
}
Also used : ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) ClientSession(org.apache.activemq.artemis.api.core.client.ClientSession) JMSRuntimeException(javax.jms.JMSRuntimeException)

Aggregations

JMSRuntimeException (javax.jms.JMSRuntimeException)25 Test (org.junit.Test)13 JMSContext (javax.jms.JMSContext)12 Message (javax.jms.Message)9 JMSException (javax.jms.JMSException)8 JMSConsumer (javax.jms.JMSConsumer)5 CountDownLatch (java.util.concurrent.CountDownLatch)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)4 JMSProducer (javax.jms.JMSProducer)4 TextMessage (javax.jms.TextMessage)4 Destination (javax.jms.Destination)3 MessageFormatRuntimeException (javax.jms.MessageFormatRuntimeException)3 RequestScoped (javax.enterprise.context.RequestScoped)2 JMSSecurityException (javax.jms.JMSSecurityException)2 JMSSecurityRuntimeException (javax.jms.JMSSecurityRuntimeException)2 ActiveMQPropertyConversionException (org.apache.activemq.artemis.api.core.ActiveMQPropertyConversionException)2 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)2 ContextsService (org.apache.webbeans.spi.ContextsService)2 DateFormat (java.text.DateFormat)1 SimpleDateFormat (java.text.SimpleDateFormat)1