javax.jms.JMSRuntimeException Java Examples

The following examples show how to use javax.jms.JMSRuntimeException. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SharedConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void sharedNonDurableSubOnDifferentSelectorTargetFilterNull() throws Exception {
   context = cf.createContext();
   try {
      context.createSharedConsumer(topic1, "mySharedCon", "sel = 'sel1'");
      try {
         context.createSharedConsumer(topic1, "mySharedCon");
         fail("expected JMSRuntimeException");
      } catch (JMSRuntimeException jmse) {
         //pass
      } catch (Exception e) {
         fail("threw wrong exception expected JMSRuntimeException got " + e);
      }
   } finally {
      context.close();
   }
}
 
Example #2
Source File: ActiveMQConnectionForContextImpl.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public JMSContext createContext(int sessionMode) {
   switch (sessionMode) {
      case Session.AUTO_ACKNOWLEDGE:
      case Session.CLIENT_ACKNOWLEDGE:
      case Session.DUPS_OK_ACKNOWLEDGE:
      case Session.SESSION_TRANSACTED:
      case ActiveMQJMSConstants.INDIVIDUAL_ACKNOWLEDGE:
      case ActiveMQJMSConstants.PRE_ACKNOWLEDGE:
         break;
      default:
         throw new JMSRuntimeException("Invalid ackmode: " + sessionMode);
   }
   refCounter.increment();

   return new ActiveMQJMSContext(this, sessionMode, threadAwareContext);
}
 
Example #3
Source File: JMS2CDIExtension.java    From tomee with Apache License 2.0 6 votes vote down vote up
@PreDestroy
private void destroy() {
    if (contexts != null) {
        JMSRuntimeException jre = null;
        for (final JMSContext c : contexts.values()) {
            try {
                c.close();
            } catch (final JMSRuntimeException e) {
                jre = e;
            }
        }
        if (jre != null) {
            throw jre;
        }
    }
}
 
Example #4
Source File: JmsPoolJMSContextTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testStartStopConnection() throws JMSException {
    JmsPoolJMSContext context = (JmsPoolJMSContext) cf.createContext();
    context.setAutoStart(false);
    assertNotNull(context.createConsumer(context.createQueue(getTestName())));

    MockJMSConnection connection = (MockJMSConnection) context.getConnection();
    assertFalse(connection.isStarted());

    context.start();
    assertTrue(connection.isStarted());

    // We cannot stop a JMS Connection from the pool as it is a shared resource.
    context.stop();
    assertTrue(connection.isStarted());
    context.close();

    try {
        context.stop();
        fail("Cannot call stop on a closed context.");
    } catch (JMSRuntimeException jmsre) {}
}
 
Example #5
Source File: JmsPoolSessionTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testRun() throws Exception {
    JmsPoolConnection connection = (JmsPoolConnection) cf.createConnection();
    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

    try {
        session.run();
        fail("Session should be unable to run outside EE.");
    } catch (JMSRuntimeException jmsre) {}

    session.close();

    try {
        session.run();
        fail("Session should be closed.");
    } catch (IllegalStateRuntimeException isre) {}
}
 
Example #6
Source File: JMSReader.java    From kafka-connect-mq-source with Apache License 2.0 6 votes vote down vote up
/**
 * Internal method to close the connection.
 */
private void closeInternal() {
    log.trace("[{}] Entry {}.closeInternal", Thread.currentThread().getId(), this.getClass().getName());

    try {
        inflight = false;
        inperil = false;
        connected = false;

        if (jmsCtxt != null) {
            jmsCtxt.close();
        }
    }
    catch (JMSRuntimeException jmse) {
        ;
    }
    finally
    {
        jmsCtxt = null;
        log.debug("Connection to MQ closed");
    }

    log.trace("[{}]  Exit {}.closeInternal", Thread.currentThread().getId(), this.getClass().getName());
}
 
Example #7
Source File: JmsContextTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@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);
   c2.close(); // should close its session, but not its (shared) connection
   try {
      c2.createMessage();
      Assert.fail("session should be closed...");
   } catch (JMSRuntimeException expected) {
      // expected
   }
   Message m1 = context.createMessage();
   Assert.assertNotNull("connection must be open", m1);
}
 
Example #8
Source File: SharedConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void sharedNonDurableSubOnDifferentSelector() throws Exception {
   context = cf.createContext();
   try {
      context.createSharedConsumer(topic1, "mySharedCon", "sel = 'sel1'");
      try {
         context.createSharedConsumer(topic1, "mySharedCon", "sel = 'sel2'");
         fail("expected JMSRuntimeException");
      } catch (JMSRuntimeException jmse) {
         //pass
      } catch (Exception e) {
         fail("threw wrong exception expected JMSRuntimeException got " + e);
      }
   } finally {
      context.close();
   }
}
 
Example #9
Source File: SharedConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void sharedNonDurableSubOnDifferentSelectorSrcFilterNull() throws Exception {
   context = cf.createContext();
   try {
      context.createSharedConsumer(topic1, "mySharedCon");
      try {
         context.createSharedConsumer(topic1, "mySharedCon", "sel = 'sel2'");
         fail("expected JMSRuntimeException");
      } catch (JMSRuntimeException jmse) {
         //pass
      } catch (Exception e) {
         fail("threw wrong exception expected JMSRuntimeException got " + e);
      }
   } finally {
      context.close();
   }
}
 
Example #10
Source File: JmsPoolJMSProducerTest.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 30000)
public void testCreateJMSProducer() throws JMSException {
    JmsPoolJMSProducer producer = (JmsPoolJMSProducer) context.createProducer();
    assertNotNull(producer);
    MockJMSMessageProducer mockProducer = (MockJMSMessageProducer) producer.getMessageProducer();
    assertNotNull(mockProducer);

    // JMSProducer instances are always anonymous producers.
    assertNull(mockProducer.getDestination());

    context.close();

    try {
        producer.getMessageProducer();
        fail("should throw on closed context.");
    } catch (JMSRuntimeException jmsre) {}
}
 
Example #11
Source File: AmqpSubscriptionTrackerTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test
public void testReserveNextSubscriptionLinkNameSharedVolatileWithNonMatchingTopic() {
    String topicName = "myTopic";
    String subscriptionName1 = "mySubscription1";

    AmqpSubscriptionTracker tracker = new AmqpSubscriptionTracker();

    // For the first shared sub name with Topic
    JmsConsumerInfo sub1consumer1 = createConsumerInfo(subscriptionName1, topicName, true, false, true);
    assertEquals("Unexpected first sub link name", subscriptionName1 + SUB_NAME_DELIMITER + "volatile1", tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer1));

    // For the next shared sub name with different Topic
    JmsConsumerInfo sub1consumer2 = createConsumerInfo(subscriptionName1, topicName + "-alt", true, false, true);
    try {
        tracker.reserveNextSubscriptionLinkName(subscriptionName1, sub1consumer2);
        fail("Expected JMSRuntimeException when Topic doesn't match previous subscription");
    } catch (JMSRuntimeException jmsre) {
    }
}
 
Example #12
Source File: SharedConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void sharedDurableSubOnDifferentSelector() throws Exception {
   context = cf.createContext();
   try {
      context.createSharedDurableConsumer(topic1, "mySharedCon", "sel = 'sel1'");
      try {
         context.createSharedDurableConsumer(topic1, "mySharedCon", "sel = 'sel2'");
         fail("expected JMSRuntimeException");
      } catch (JMSRuntimeException jmse) {
         //pass
      } catch (Exception e) {
         fail("threw wrong exception expected JMSRuntimeException got " + e);
      }
   } finally {
      context.close();
   }
}
 
Example #13
Source File: AmqpSubscriptionTracker.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
private String getSharedDurableSubLinkName(String subscriptionName, JmsConsumerInfo consumerInfo) {
    JmsDestination topic = consumerInfo.getDestination();
    String selector = consumerInfo.getSelector();

    SubDetails subDetails = null;
    if(sharedDurableSubs.containsKey(subscriptionName)) {
        subDetails = sharedDurableSubs.get(subscriptionName);

        if(subDetails.matches(topic, selector)){
            subDetails.addSubscriber(consumerInfo);
        } else {
            throw new JMSRuntimeException("Subscription details dont match existing subscriber.");
        }
    } else {
        subDetails = new SubDetails(topic, selector, consumerInfo);
    }

    sharedDurableSubs.put(subscriptionName, subDetails);

    int count = subDetails.totalSubscriberCount();

    return getDurableSubscriptionLinkName(subscriptionName, consumerInfo.isExplicitClientID(), count);
}
 
Example #14
Source File: SharedConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void sharedDurableSubOnDifferentSelectorTargetFilterNull() throws Exception {
   context = cf.createContext();
   try {
      context.createSharedDurableConsumer(topic1, "mySharedCon", "sel = 'sel1'");
      try {
         context.createSharedDurableConsumer(topic1, "mySharedCon");
         fail("expected JMSRuntimeException");
      } catch (JMSRuntimeException jmse) {
         //pass
      } catch (Exception e) {
         fail("threw wrong exception expected JMSRuntimeException got " + e);
      }
   } finally {
      context.close();
   }
}
 
Example #15
Source File: JMSWriter.java    From kafka-connect-mq-sink with Apache License 2.0 6 votes vote down vote up
/**
 * Commits the current transaction.
 *
 * @throws RetriableException Operation failed, but connector should continue to retry.
 * @throws ConnectException   Operation failed and connector should stop.
 */
public void commit() throws ConnectException, RetriableException {
    log.trace("[{}] Entry {}.commit", Thread.currentThread().getId(), this.getClass().getName());

    connectInternal();
    try {
        if (inflight) {
            inflight = false;
        }

        jmsCtxt.commit();
    }
    catch (JMSRuntimeException jmse) {
        log.error("JMS exception {}", jmse);
        throw handleException(jmse);
    }

    log.trace("[{}]  Exit {}.commit", Thread.currentThread().getId(), this.getClass().getName());
}
 
Example #16
Source File: JmsPoolConnectionFactory.java    From pooled-jms with Apache License 2.0 6 votes vote down vote up
@Override
public JMSContext createContext(String username, String password, int sessionMode) {
    if (stopped.get()) {
        LOG.debug("JmsPoolConnectionFactory is stopped, skip create new connection.");
        return null;
    }

    if (!jmsContextSupported) {
        throw new JMSRuntimeException("Configured ConnectionFactory is not JMS 2+ capable");
    }

    if (isUseProviderJMSContext()) {
        return createProviderContext(username, password, sessionMode);
    } else {
        try {
            return newPooledConnectionContext(createJmsPoolConnection(username, password), sessionMode);
        } catch (JMSException e) {
            throw JMSExceptionSupport.createRuntimeException(e);
        }
    }
}
 
Example #17
Source File: JmsStreamSource.java    From pentaho-kettle with Apache License 2.0 6 votes vote down vote up
/**
 * Will receive messages from consumer.  If timeout is hit, consumer.receive(timeout)
 * will return null, and the observable will be completed.
 */
private void receiveLoop() {
  Message message;
  try {
    while ( !closed.get() && ( message = consumer.receive( receiverTimeout ) ) != null ) {
      streamStep.logDebug( message.toString() );
      Date date = new Date( message.getJMSTimestamp() );
      DateFormat formatter = new SimpleDateFormat( "MM-dd-yyyy HH:mm:ss a" );
      formatter.setTimeZone( TimeZone.getTimeZone( "UTC" ) );
      String jmsTimestamp = formatter.format( date );
      acceptRows( singletonList( Arrays.asList( message.getBody( Object.class ), jmsDelegate.destinationName, message.getJMSMessageID(), jmsTimestamp, message.getJMSRedelivered() ) ) );
    }
  } catch ( JMSRuntimeException | JMSException jmsException ) {
    error( jmsException );
  } finally {
    super.close();
    if ( !closed.get() ) {
      close();
      streamStep.logBasic( getString( PKG, "JmsStreamSource.HitReceiveTimeout" ) );
    }
  }
}
 
Example #18
Source File: ActiveMQJMSProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public String getStringProperty(String name) {
   try {
      SimpleString prop = properties.getSimpleStringProperty(new SimpleString(name));
      if (prop == null)
         return null;
      return prop.toString();
   } catch (ActiveMQPropertyConversionException ce) {
      throw new MessageFormatRuntimeException(ce.getMessage());
   } catch (RuntimeException e) {
      throw new JMSRuntimeException(e.getMessage());
   }
}
 
Example #19
Source File: ConnectivityRootActor.java    From ditto with Eclipse Public License 2.0 5 votes vote down vote up
@Override
protected PartialFunction<Throwable, SupervisorStrategy.Directive> getSupervisionDecider() {
    return DeciderBuilder.match(JMSRuntimeException.class, e -> {
        log.warning("JMSRuntimeException '{}' occurred.", e.getMessage());
        return restartChild();
    }).match(NamingException.class, e -> {
        log.warning("NamingException '{}' occurred.", e.getMessage());
        return restartChild();
    }).build().orElse(super.getSupervisionDecider());
}
 
Example #20
Source File: JMSTestBase.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
protected final void receiveMessages(JMSConsumer consumer, final int start, final int msgCount, final boolean ack) {
   try {
      for (int i = start; i < msgCount; i++) {
         Message message = consumer.receive(100);
         Assert.assertNotNull("Expecting a message " + i, message);
         final int actual = message.getIntProperty("counter");
         Assert.assertEquals("expected=" + i + ". Got: property['counter']=" + actual, i, actual);
         if (ack)
            message.acknowledge();
      }
   } catch (JMSException cause) {
      throw new JMSRuntimeException(cause.getMessage(), cause.getErrorCode(), cause);
   }
}
 
Example #21
Source File: ActiveMQJMSConsumer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void setMessageListener(MessageListener listener) throws JMSRuntimeException {
   try {
      consumer.setMessageListener(new MessageListenerWrapper(listener));
   } catch (JMSException e) {
      throw JmsExceptionUtils.convertToRuntimeException(e);
   }
}
 
Example #22
Source File: ActiveMQJMSProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public JMSProducer setPriority(int priority) {
   try {
      producer.setPriority(priority);
   } catch (JMSException e) {
      JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
      e2.initCause(e);
      throw e2;
   }
   return this;
}
 
Example #23
Source File: JmsSession.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
static void validateSessionMode(int mode) {
    switch (mode) {
        case JMSContext.AUTO_ACKNOWLEDGE:
        case JMSContext.CLIENT_ACKNOWLEDGE:
        case JMSContext.DUPS_OK_ACKNOWLEDGE:
        case JMSContext.SESSION_TRANSACTED:
        case INDIVIDUAL_ACKNOWLEDGE:
        case ARTEMIS_PRE_ACKNOWLEDGE:
        case NO_ACKNOWLEDGE:
            return;
        default:
            throw new JMSRuntimeException("Invalid Session Mode: " + mode);
    }
}
 
Example #24
Source File: JMSContextImpl.java    From tomee with Apache License 2.0 5 votes vote down vote up
@Override
public void setClientID(final String clientID) {
    if (xa) {
        throw new JMSRuntimeException("Illegal call to setClientID");
    }
    try {
        connection().setClientID(clientID);
    } catch (final JMSException e) {
        throw toRuntimeException(e);
    }
}
 
Example #25
Source File: ActiveMQMessage.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private void checkProperty(final String name) throws JMSException {
   if (propertiesReadOnly) {
      if (name != null && name.equals(ActiveMQJMSConstants.JMS_ACTIVEMQ_INPUT_STREAM)) {
         throw new MessageNotWriteableException("You cannot set the Input Stream on received messages. Did you mean " + ActiveMQJMSConstants.JMS_ACTIVEMQ_OUTPUT_STREAM +
                                                   " or " +
                                                   ActiveMQJMSConstants.JMS_ACTIVEMQ_SAVE_STREAM +
                                                   "?");
      } else {
         throw ActiveMQJMSClientBundle.BUNDLE.messageNotWritable();
      }
   }

   if (name == null) {
      throw ActiveMQJMSClientBundle.BUNDLE.nullArgumentNotAllowed("property");
   }

   if (name.equals("")) {
      throw new IllegalArgumentException("The name of a property must not be an empty String.");
   }

   if (!isValidJavaIdentifier(name)) {
      throw ActiveMQJMSClientBundle.BUNDLE.invalidJavaIdentifier(name);
   }

   if (ActiveMQMessage.reservedIdentifiers.contains(name)) {
      throw new JMSRuntimeException("The property name '" + name + "' is reserved due to selector syntax.");
   }

   if (name.startsWith("JMS_ACTIVEMQ")) {
      throw new JMSRuntimeException("The property name '" + name + "' is illegal since it starts with JMS_ACTIVEMQ");
   }
}
 
Example #26
Source File: ActiveMQJMSProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public long getTimeToLive() {
   long timeToLive = 0;
   try {
      timeToLive = producer.getTimeToLive();
      return timeToLive;
   } catch (JMSException e) {
      JMSRuntimeException e2 = new JMSRuntimeException(e.getMessage());
      e2.initCause(e);
      throw e2;
   }
}
 
Example #27
Source File: JMSConsumerIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout=20000)
public void testConsumerReceiveNoWaitThrowsIfConnectionLost() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        JMSContext context = testFixture.createJMSContext(testPeer);

        testPeer.expectBegin();

        Queue queue = context.createQueue("queue");

        testPeer.expectReceiverAttach();
        testPeer.expectLinkFlow(false, notNullValue(UnsignedInteger.class));
        testPeer.expectLinkFlow(true, notNullValue(UnsignedInteger.class));
        testPeer.dropAfterLastHandler();

        final JMSConsumer consumer = context.createConsumer(queue);

        try {
            consumer.receiveNoWait();
            fail("An exception should have been thrown");
        } catch (JMSRuntimeException jmsre) {
            // Expected
        }

        try {
            context.close();
        } catch (Throwable ignored) {
        }
    }
}
 
Example #28
Source File: JmsProducer.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
@Override
public JMSProducer setDeliveryMode(int deliveryMode) {
    switch (deliveryMode) {
        case DeliveryMode.PERSISTENT:
        case DeliveryMode.NON_PERSISTENT:
            this.deliveryMode = deliveryMode;
            return this;
        default:
            throw new JMSRuntimeException(String.format("Invalid DeliveryMode specified: %d", deliveryMode));
    }
}
 
Example #29
Source File: PooledConnectionFactoryTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testFailToCreateJMSContextWithCredentialsAndSessionMode() throws  Exception {
    JmsPoolConnectionFactory cf = createPooledConnectionFactory();

    try {
        cf.createContext("user", "pass", Session.CLIENT_ACKNOWLEDGE);
        fail("Should have thrown a JMSRuntimeException");
    } catch (JMSRuntimeException jmsre) {
        LOG.info("Caught Excepted JMSRuntimeException");
    } finally {
        cf.stop();
    }
}
 
Example #30
Source File: PooledConnectionFactoryTest.java    From pooled-jms with Apache License 2.0 5 votes vote down vote up
@Test(timeout = 60000)
public void testFailToCreateJMSContextWithCredentials() throws  Exception {
    JmsPoolConnectionFactory cf = createPooledConnectionFactory();

    try {
        cf.createContext("user", "pass");
        fail("Should have thrown a JMSRuntimeException");
    } catch (JMSRuntimeException jmsre) {
        LOG.info("Caught Excepted JMSRuntimeException");
    } finally {
        cf.stop();
    }
}