Search in sources :

Example 16 with JMSRuntimeException

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

the class ActiveMQMessage method createMessage.

public static ActiveMQMessage createMessage(final ClientMessage message, final ClientSession session, final ConnectionFactoryOptions options) {
    int type = message.getType();
    ActiveMQMessage msg;
    switch(type) {
        case // 0
        ActiveMQMessage.TYPE:
            {
                msg = new ActiveMQMessage(message, session);
                break;
            }
        case // 4
        ActiveMQBytesMessage.TYPE:
            {
                msg = new ActiveMQBytesMessage(message, session);
                break;
            }
        case // 5
        ActiveMQMapMessage.TYPE:
            {
                msg = new ActiveMQMapMessage(message, session);
                break;
            }
        case ActiveMQObjectMessage.TYPE:
            {
                msg = new ActiveMQObjectMessage(message, session, options);
                break;
            }
        case // 6
        ActiveMQStreamMessage.TYPE:
            {
                msg = new ActiveMQStreamMessage(message, session);
                break;
            }
        case // 3
        ActiveMQTextMessage.TYPE:
            {
                msg = new ActiveMQTextMessage(message, session);
                break;
            }
        default:
            {
                throw new JMSRuntimeException("Invalid message type " + type);
            }
    }
    return msg;
}
Also used : JMSRuntimeException(javax.jms.JMSRuntimeException)

Example 17 with JMSRuntimeException

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

the class JMSContextTest method testCreateContextThrowsException.

@Test
public void testCreateContextThrowsException() throws Exception {
    JMSContext jmsctx = qraConnectionFactory.createContext();
    try {
        jmsctx.createContext(JMSContext.AUTO_ACKNOWLEDGE);
        fail("expected JMSRuntimeException");
    } catch (JMSRuntimeException e) {
    // pass
    } catch (Exception e) {
        fail("wrong exception thrown: " + e);
    }
}
Also used : JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 18 with JMSRuntimeException

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

the class JmsContextTest method testGetAnotherContextFromIt.

@Test
public void testGetAnotherContextFromIt() {
    JMSContext c2 = context.createContext(Session.DUPS_OK_ACKNOWLEDGE);
    Assert.assertNotNull(c2);
    Assert.assertEquals(Session.DUPS_OK_ACKNOWLEDGE, c2.getSessionMode());
    Message m2 = c2.createMessage();
    Assert.assertNotNull(m2);
    // should close its session, but not its (shared) connection
    c2.close();
    try {
        c2.createMessage();
        Assert.fail("session should be closed...");
    } catch (JMSRuntimeException expected) {
    // expected
    }
    Message m1 = context.createMessage();
    Assert.assertNotNull("connection must be open", m1);
}
Also used : Message(javax.jms.Message) TextMessage(javax.jms.TextMessage) StreamMessage(javax.jms.StreamMessage) BytesMessage(javax.jms.BytesMessage) JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 19 with JMSRuntimeException

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

the class NonExistentQueueTest method sendToNonExistentDestination.

@Test
public void sendToNonExistentDestination() throws Exception {
    server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false));
    server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false));
    Destination destination = ActiveMQJMSClient.createTopic("DoesNotExist");
    TransportConfiguration transportConfiguration = new TransportConfiguration(InVMConnectorFactory.class.getName());
    ConnectionFactory localConnectionFactory = ActiveMQJMSClient.createConnectionFactoryWithoutHA(JMSFactoryType.CF, transportConfiguration);
    // Using JMS 1 API
    Connection connection = localConnectionFactory.createConnection();
    Session session = connection.createSession();
    try {
        MessageProducer messageProducer = session.createProducer(null);
        messageProducer.send(destination, session.createMessage());
        Assert.fail("Succeeded in sending message to a non-existent destination using JMS 1 API!");
    } catch (JMSException e) {
    // Expected }
    }
    // Using JMS 2 API
    JMSContext context = localConnectionFactory.createContext();
    JMSProducer jmsProducer = context.createProducer().setDeliveryMode(DeliveryMode.PERSISTENT);
    try {
        jmsProducer.send(destination, context.createMessage());
        Assert.fail("Succeeded in sending message to a non-existent destination using JMS 2 API!");
    } catch (JMSRuntimeException e) {
    // Expected }
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) Destination(javax.jms.Destination) ConnectionFactory(javax.jms.ConnectionFactory) Connection(javax.jms.Connection) TransportConfiguration(org.apache.activemq.artemis.api.core.TransportConfiguration) InVMConnectorFactory(org.apache.activemq.artemis.core.remoting.impl.invm.InVMConnectorFactory) JMSException(javax.jms.JMSException) JMSProducer(javax.jms.JMSProducer) MessageProducer(javax.jms.MessageProducer) JMSContext(javax.jms.JMSContext) Session(javax.jms.Session) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

Example 20 with JMSRuntimeException

use of javax.jms.JMSRuntimeException in project tomee by apache.

the class JMS2AMQTest method receive.

@Test
public void receive() throws InterruptedException {
    final String text = TEXT + "2";
    final AtomicReference<Throwable> error = new AtomicReference<>();
    final CountDownLatch ready = new CountDownLatch(1);
    final CountDownLatch over = new CountDownLatch(1);
    new Thread() {

        @Override
        public void run() {
            {
                setName(JMS2AMQTest.class.getName() + ".receive#receiver");
            }
            try (final JMSContext context = cf.createContext()) {
                try (final JMSConsumer consumer = context.createConsumer(destination2)) {
                    ready.countDown();
                    assertEquals(text, consumer.receiveBody(String.class, TimeUnit.MINUTES.toMillis(1)));
                }
            } catch (final Throwable ex) {
                error.set(ex);
            } finally {
                over.countDown();
            }
        }
    }.start();
    ready.await(1, TimeUnit.MINUTES);
    // just to ensure we called receive already
    sleep(150);
    // now send the message
    try (final JMSContext context = cf.createContext()) {
        context.createProducer().send(destination2, text);
    } catch (final JMSRuntimeException ex) {
        fail(ex.getMessage());
    }
    over.await(1, TimeUnit.MINUTES);
    // ensure we got the message and no exception
    final Throwable exception = error.get();
    if (exception != null) {
        exception.printStackTrace();
    }
    assertNull(exception == null ? "ok" : exception.getMessage(), exception);
}
Also used : JMSConsumer(javax.jms.JMSConsumer) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) JMSContext(javax.jms.JMSContext) JMSRuntimeException(javax.jms.JMSRuntimeException) Test(org.junit.Test)

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