Example usage for javax.jms JMSRuntimeException getMessage

List of usage examples for javax.jms JMSRuntimeException getMessage

Introduction

In this page you can find the example usage for javax.jms JMSRuntimeException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.apache.openejb.activemq.JMS2AMQTest.java

@Test
public void cdi() throws InterruptedException {
    final String text = TEXT + "3";

    final AtomicReference<Throwable> error = new AtomicReference<>();
    final CountDownLatch ready = new CountDownLatch(1);
    final CountDownLatch over = new CountDownLatch(1);
    new Thread() {
        {//from  w  ww. j a  va  2  s.c o m
            setName(JMS2AMQTest.class.getName() + ".cdi#receiver");
        }

        @Override
        public void run() {
            final ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
            contextsService.startContext(RequestScoped.class, null); // spec defines it for request scope an transaction scope
            try {
                ready.countDown();
                assertEquals(text, context.createConsumer(destination3).receiveBody(String.class,
                        TimeUnit.MINUTES.toMillis(1)));

                // ensure we dont do a NPE if there is nothing to read
                assertNull(context.createConsumer(destination3).receiveBody(String.class, 100));
            } catch (final Throwable t) {
                error.set(t);
            } finally {
                contextsService.endContext(RequestScoped.class, null);
                over.countDown();
            }
        }
    }.start();

    ready.await(1, TimeUnit.MINUTES);
    sleep(150); // just to ensure we called receive already

    // now send the message
    try (final JMSContext context = cf.createContext()) {
        context.createProducer().send(destination3, 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);
}

From source file:org.apache.openejb.activemq.JMS2AMQTest.java

@Test
public void cdiListenerAPI() throws InterruptedException {
    final String text = TEXT + "4";

    final AtomicReference<Throwable> error = new AtomicReference<>();
    final CountDownLatch ready = new CountDownLatch(1);
    final CountDownLatch over = new CountDownLatch(1);
    new Thread() {
        {/*from w w w  . j a  v a  2  s. co m*/
            setName(JMS2AMQTest.class.getName() + ".cdiListenerAPI#receiver");
        }

        @Override
        public void run() {
            final ContextsService contextsService = WebBeansContext.currentInstance().getContextsService();
            contextsService.startContext(RequestScoped.class, null);
            try {
                final JMSConsumer consumer = context.createConsumer(destination3);
                consumer.setMessageListener(new MessageListener() {
                    @Override
                    public void onMessage(final Message message) {
                        try {
                            assertEquals(text, message.getBody(String.class));
                        } catch (final Throwable e) {
                            error.set(e);
                        } finally {
                            over.countDown();
                            consumer.close();
                        }
                    }
                });
                ready.countDown();
            } catch (final Throwable t) {
                error.set(t);
            } finally {
                try {
                    over.await(1, TimeUnit.MINUTES);
                } catch (final InterruptedException e) {
                    Thread.interrupted();
                }
                contextsService.endContext(RequestScoped.class, null);
            }
        }
    }.start();

    ready.await(1, TimeUnit.MINUTES);

    // now send the message
    try (final JMSContext context = cf.createContext()) {
        context.createProducer().send(destination3, 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);
}

From source file:org.apache.openejb.activemq.JMS2AMQTest.java

@Test
public void sendToMdb() throws Exception {
    try (final JMSContext context = cf.createContext()) {
        context.createProducer().send(destination, TEXT);
        assertTrue(Listener.sync());/*from   w  ww. ja v  a  2s .  c o m*/
    } catch (final JMSRuntimeException ex) {
        fail(ex.getMessage());
    }
}

From source file:org.apache.openejb.activemq.JMS2AMQTest.java

@Test
public void sendMessageToMdb() throws Exception {
    try (final JMSContext context = cf.createContext()) {
        Message message = context.createMessage();
        message.setStringProperty("text", TEXT);
        context.createProducer().send(destination, message);
        assertTrue(Listener.sync());//from ww  w  .j a va  2 s  .c  o  m
    } catch (final JMSRuntimeException ex) {
        fail(ex.getMessage());
    }
}