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;
}
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);
}
}
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);
}
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 }
}
}
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);
}
Aggregations