javax.jms.InvalidDestinationException Java Examples

The following examples show how to use javax.jms.InvalidDestinationException. 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: AmqpFullyQualifiedNameTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testFQQNTopicWhenQueueDoesNotExist() throws Exception {
   Exception e = null;
   String queueName = "testQueue";

   Connection connection = createConnection(false);
   try {
      connection.setClientID("FQQNconn");
      connection.start();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic topic = session.createTopic(multicastAddress.toString() + "::" + queueName);
      session.createConsumer(topic);
   } catch (InvalidDestinationException ide) {
      e = ide;
   } finally {
      connection.close();
   }
   assertNotNull(e);
   assertTrue(e.getMessage().contains("Queue: '" + queueName + "' does not exist"));
}
 
Example #2
Source File: JmsTopicPublisherTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 10000)
public void testPublishMessageOnProvidedTopicWhenNotAnonymous() throws Exception {
    Topic topic = session.createTopic(getTestName());
    TopicPublisher publisher = session.createPublisher(topic);
    Message message = session.createMessage();

    try {
        publisher.publish(session.createTopic(getTestName() + "1"), message);
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException uoe) {}

    try {
        publisher.publish((Topic) null, message);
        fail("Should throw InvalidDestinationException");
    } catch (InvalidDestinationException ide) {}
}
 
Example #3
Source File: JmsTopicPublisherTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 10000)
public void testPublishMessageWithOptionsOnProvidedTopicWhenNotAnonymous() throws Exception {
    Topic topic = session.createTopic(getTestName());
    TopicPublisher publisher = session.createPublisher(topic);
    Message message = session.createMessage();

    try {
        publisher.publish(session.createTopic(getTestName() + "1"), message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
        fail("Should throw UnsupportedOperationException");
    } catch (UnsupportedOperationException uoe) {}

    try {
        publisher.publish((Topic) null, message, Message.DEFAULT_DELIVERY_MODE, Message.DEFAULT_PRIORITY, Message.DEFAULT_TIME_TO_LIVE);
        fail("Should throw InvalidDestinationException");
    } catch (InvalidDestinationException ide) {}
}
 
Example #4
Source File: JmsDurableSubscriberTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testDurableSubscriptionUnsubscribeNoExistingSubThrowsJMSEx() throws Exception {
    connection = createAmqpConnection();
    connection.setClientID("DURABLE-AMQP");
    connection.start();

    assertEquals(0, brokerService.getAdminView().getDurableTopicSubscribers().length);
    assertEquals(0, brokerService.getAdminView().getInactiveDurableTopicSubscribers().length);

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    assertNotNull(session);

    BrokerViewMBean broker = getProxyToBroker();
    assertEquals(0, broker.getDurableTopicSubscribers().length);
    assertEquals(0, broker.getInactiveDurableTopicSubscribers().length);

    try {
        session.unsubscribe(getSubscriptionName());
        fail("Should have thrown an InvalidDestinationException");
    } catch (InvalidDestinationException ide) {
    }
}
 
Example #5
Source File: FailedConnectionsIntegrationTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 20000)
public void testConnectWithNotFoundErrorThrowsJMSEWhenInvalidContainerHintNotPresent() throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        testPeer.rejectConnect(AmqpError.NOT_FOUND, "Virtual Host does not exist", null);
        try {
            establishAnonymousConnecton(testPeer, true);
            fail("Should have thrown JMSException");
        } catch (InvalidDestinationException destEx) {
            fail("Should not convert to destination exception for this case.");
        } catch (JMSException jmsEx) {
            LOG.info("Caught expected Exception: {}", jmsEx.getMessage(), jmsEx);
            // Expected
        } catch (Exception ex) {
            fail("Should have thrown JMSException: " + ex);
        }

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #6
Source File: JmsSession.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
protected void send(JmsMessageProducer producer, Destination dest, Message msg, int deliveryMode, int priority, long timeToLive, boolean disableMsgId, boolean disableTimestamp, long deliveryDelay, CompletionListener listener) throws JMSException {
    if (dest == null) {
        throw new InvalidDestinationException("Destination must not be null");
    }

    if (msg == null) {
        throw new MessageFormatException("Message must not be null");
    }

    JmsDestination destination = JmsMessageTransformation.transformDestination(connection, dest);

    if (destination.isTemporary() && ((JmsTemporaryDestination) destination).isDeleted()) {
        throw new IllegalStateException("Temporary destination has been deleted");
    }

    send(producer, destination, msg, deliveryMode, priority, timeToLive, disableMsgId, disableTimestamp, deliveryDelay, listener);
}
 
Example #7
Source File: ActiveMQSession.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
public void deleteTemporaryQueue(final ActiveMQDestination tempQueue) throws JMSException {
   if (!tempQueue.isTemporary()) {
      throw new InvalidDestinationException("Not a temporary queue " + tempQueue);
   }
   try {
      QueueQuery response = session.queueQuery(tempQueue.getSimpleAddress());

      if (!response.isExists()) {
         throw new InvalidDestinationException("Cannot delete temporary queue " + tempQueue.getName() +
                                                  " does not exist");
      }

      if (response.getConsumerCount() > 0) {
         throw new IllegalStateException("Cannot delete temporary queue " + tempQueue.getName() +
                                            " since it has subscribers");
      }

      SimpleString address = tempQueue.getSimpleAddress();

      session.deleteQueue(address);

      connection.removeTemporaryQueue(address);
   } catch (ActiveMQException e) {
      throw JMSExceptionHelper.convertFromActiveMQException(e);
   }
}
 
Example #8
Source File: QueueSenderTest.java    From qpid-broker-j with Apache License 2.0 6 votes vote down vote up
@Test
public void anonymousSenderSendToUnknownQueue() throws Exception
{
    QueueConnection connection = ((QueueConnection) getConnectionBuilder().setSyncPublish(true).build());

    try
    {
        QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
        Queue invalidDestination = session.createQueue("unknown");

        try
        {
            QueueSender sender = session.createSender(null);
            sender.send(invalidDestination, session.createMessage());
            fail("Exception not thrown");
        }
        catch (InvalidDestinationException e)
        {
            //PASS
        }
    }
    finally
    {
        connection.close();
    }
}
 
Example #9
Source File: ActiveMQCompatibleMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
static Destination setCompatibleReplyTo(Destination dest, ClientMessage message) throws InvalidDestinationException {
   if (dest == null) {
      MessageUtil.setJMSReplyTo(message, (String) null);
      return null;
   } else {
      if (dest instanceof ActiveMQDestination == false) {
         throw new InvalidDestinationException("Foreign destination " + dest);
      }
      ActiveMQDestination jbd = (ActiveMQDestination) dest;
      final String address = jbd.getAddress();
      if (hasPrefix1X(address)) {
         MessageUtil.setJMSReplyTo(message, jbd.getAddress());
      } else {
         String prefix = prefixOf(dest);
         MessageUtil.setJMSReplyTo(message, prefix + jbd.getAddress());
      }
      return jbd;
   }
}
 
Example #10
Source File: ActiveMQSession.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public TopicSubscriber createDurableSubscriber(final Topic topic,
                                               final String name,
                                               String messageSelector,
                                               final boolean noLocal) throws JMSException {
   // As per spec. section 4.11
   if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
      throw new IllegalStateException("Cannot create a durable subscriber on a QueueSession");
   }
   checkTopic(topic);
   if (!(topic instanceof ActiveMQDestination)) {
      throw new InvalidDestinationException("Not an ActiveMQTopic:" + topic);
   }
   if ("".equals(messageSelector)) {
      messageSelector = null;
   }

   ActiveMQDestination jbdest = (ActiveMQDestination) topic;

   if (jbdest.isQueue()) {
      throw new InvalidDestinationException("Cannot create a subscriber on a queue");
   }

   return createConsumer(jbdest, name, messageSelector, noLocal, ConsumerDurability.DURABLE);
}
 
Example #11
Source File: JmsTemporaryQueueTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testCantConsumeFromTemporaryQueueCreatedOnAnotherConnection() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryQueue tempQueue = session.createTemporaryQueue();
    session.createConsumer(tempQueue);

    Connection connection2 = createAmqpConnection();
    try {
        Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        try {
            session2.createConsumer(tempQueue);
            fail("should not be able to consumer from temporary queue from another connection");
        } catch (InvalidDestinationException ide) {
            // expected
        }
    } finally {
        connection2.close();
    }
}
 
Example #12
Source File: AmqpFullyQualifiedNameTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
/**
 * Broker should return exception if no address is passed in FQQN.
 * @throws Exception
 */
@Test
public void testQueueSpecial() throws Exception {
   server.createQueue(new QueueConfiguration(anycastQ1).setAddress(anycastAddress).setRoutingType(RoutingType.ANYCAST));

   Connection connection = createConnection();
   Exception expectedException = null;
   try {
      connection.start();
      Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

      //::queue ok!
      String specialName = CompositeAddress.toFullyQualified(new SimpleString(""), anycastQ1).toString();
      javax.jms.Queue q1 = session.createQueue(specialName);
      session.createConsumer(q1);
   } catch (InvalidDestinationException e) {
      expectedException = e;
   }
   assertNotNull(expectedException);
   assertTrue(expectedException.getMessage().contains("Queue: 'q1' does not exist for address ''"));
}
 
Example #13
Source File: ActiveMQMessage.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Override
public void setJMSReplyTo(final Destination dest) throws JMSException {

   if (dest == null) {
      MessageUtil.setJMSReplyTo(message, (String) null);
      replyTo = null;
   } else {
      if (dest instanceof ActiveMQDestination == false) {
         throw new InvalidDestinationException("Foreign destination " + dest);
      }

      String prefix = prefixOf(dest);
      ActiveMQDestination jbd = (ActiveMQDestination) dest;

      MessageUtil.setJMSReplyTo(message, prefix + jbd.getAddress());

      replyTo = jbd;
   }
}
 
Example #14
Source File: MessageConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConsumerOnNonExistentTopic() throws Exception {
   Connection pconn = null;

   try {
      pconn = createConnection();

      Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      try {
         ps.createConsumer(new Topic() {
            @Override
            public String getTopicName() throws JMSException {
               return "NoSuchTopic";
            }
         });
         ProxyAssertSupport.fail("should throw exception");
      } catch (InvalidDestinationException e) {
         // OK
      }
   } finally {
      if (pconn != null) {
         pconn.close();
      }
   }
}
 
Example #15
Source File: MessageConsumerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateConsumerOnNonExistentQueue() throws Exception {
   Connection pconn = null;

   try {
      pconn = createConnection();

      Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      try {
         ps.createConsumer(new Queue() {
            @Override
            public String getQueueName() throws JMSException {
               return "NoSuchQueue";
            }
         });
         ProxyAssertSupport.fail("should throw exception");
      } catch (InvalidDestinationException e) {
         // OK
      }
   } finally {
      if (pconn != null) {
         pconn.close();
      }
   }
}
 
Example #16
Source File: DurableSubscriptionTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testDurableSubscriptionOnTemporaryTopic() throws Exception {
   Connection conn = null;

   conn = createConnection();

   try {
      conn.setClientID("doesn't actually matter");
      Session s = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      Topic temporaryTopic = s.createTemporaryTopic();

      try {
         s.createDurableSubscriber(temporaryTopic, "mySubscription");
         ProxyAssertSupport.fail("this should throw exception");
      } catch (InvalidDestinationException e) {
         // OK
      }
   } finally {
      if (conn != null) {
         conn.close();
      }
   }
}
 
Example #17
Source File: MessageProducerTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateProducerOnInexistentDestination() throws Exception {
   getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateQueues(false));
   getJmsServer().getAddressSettingsRepository().addMatch("#", new AddressSettings().setAutoCreateAddresses(false));
   Connection pconn = createConnection();
   try {
      Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
      try {
         ps.createProducer(ActiveMQJMSClient.createTopic("NoSuchTopic"));
         ProxyAssertSupport.fail("should throw exception");
      } catch (InvalidDestinationException e) {
         // OK
      }
   } finally {
      pconn.close();
   }
}
 
Example #18
Source File: BrowserTest.java    From activemq-artemis with Apache License 2.0 6 votes vote down vote up
@Test
public void testCreateBrowserOnNonExistentQueue() throws Exception {
   Connection pconn = getConnectionFactory().createConnection();

   try {
      Session ps = pconn.createSession(false, Session.AUTO_ACKNOWLEDGE);

      try {
         ps.createBrowser(new Queue() {
            @Override
            public String getQueueName() throws JMSException {
               return "NoSuchQueue";
            }
         });
         ProxyAssertSupport.fail("should throw exception");
      } catch (InvalidDestinationException e) {
         // OK
      }
   } finally {
      if (pconn != null) {
         pconn.close();
      }
   }
}
 
Example #19
Source File: JmsTemporaryTopicTest.java    From qpid-jms with Apache License 2.0 6 votes vote down vote up
@Test(timeout = 60000)
public void testCantConsumeFromTemporaryTopicCreatedOnAnotherConnection() throws Exception {
    connection = createAmqpConnection();
    connection.start();

    Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
    TemporaryTopic tempTopic = session.createTemporaryTopic();
    session.createConsumer(tempTopic);

    Connection connection2 = createAmqpConnection();
    try {
        Session session2 = connection2.createSession(false, Session.AUTO_ACKNOWLEDGE);
        try {
            session2.createConsumer(tempTopic);
            fail("should not be able to consumer from temporary topic from another connection");
        } catch (InvalidDestinationException ide) {
            // expected
        }
    } finally {
        connection2.close();
    }
}
 
Example #20
Source File: JmsEventTransportImpl.java    From cougar with Apache License 2.0 6 votes vote down vote up
private Destination createDestination(Session session, String destinationName) throws JMSException {
    try {
        Destination destination = null;
        switch (destinationType) {
            case DurableTopic:
            case Topic:
                destination = session.createTopic(destinationName);
                break;
            case Queue:
                destination = session.createQueue(destinationName);
                break;
        }
        return destination;
    }
    catch (InvalidDestinationException ide) {
        throw new CougarFrameworkException("Error creating "+destinationType+" for destination name '"+destinationName+"'",ide);
    }
}
 
Example #21
Source File: ActiveMQSession.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
@Override
public void unsubscribe(final String name) throws JMSException {
   // As per spec. section 4.11
   if (sessionType == ActiveMQSession.TYPE_QUEUE_SESSION) {
      throw new IllegalStateException("Cannot unsubscribe using a QueueSession");
   }

   SimpleString queueName = ActiveMQDestination.createQueueNameForSubscription(true, connection.getClientID(), name);

   try {
      QueueQuery response = session.queueQuery(queueName);

      if (!response.isExists()) {
         throw new InvalidDestinationException("Cannot unsubscribe, subscription with name " + name +
                                                  " does not exist");
      }

      if (response.getConsumerCount() != 0) {
         throw new IllegalStateException("Cannot unsubscribe durable subscription " + name +
                                            " since it has active subscribers");
      }

      session.deleteQueue(queueName);
   } catch (ActiveMQException e) {
      throw JMSExceptionHelper.convertFromActiveMQException(e);
   }
}
 
Example #22
Source File: ActiveMQSession.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public void deleteTemporaryTopic(final ActiveMQDestination tempTopic) throws JMSException {
   if (!tempTopic.isTemporary()) {
      throw new InvalidDestinationException("Not a temporary topic " + tempTopic);
   }

   try {
      AddressQuery response = session.addressQuery(tempTopic.getSimpleAddress());

      if (!response.isExists()) {
         throw new InvalidDestinationException("Cannot delete temporary topic " + tempTopic.getName() +
                                                  " does not exist");
      }

      if (response.getQueueNames().size() > 1) {
         throw new IllegalStateException("Cannot delete temporary topic " + tempTopic.getName() +
                                            " since it has subscribers");
      }

      SimpleString address = tempTopic.getSimpleAddress();

      session.deleteQueue(address);

      connection.removeTemporaryQueue(address);
   } catch (ActiveMQException e) {
      throw JMSExceptionHelper.convertFromActiveMQException(e);
   }
}
 
Example #23
Source File: ActiveMQMessageProducer.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Check if the destination is sent correctly
 */
private void checkDestination(Destination destination) throws InvalidDestinationException {
   if (destination != null && !(destination instanceof ActiveMQDestination)) {
      throw new InvalidDestinationException("Foreign destination:" + destination);
   }
   if (destination != null && defaultDestination != null) {
      throw new UnsupportedOperationException("Cannot specify destination if producer has a default destination");
   }
   if (destination == null) {
      throw ActiveMQJMSClientBundle.BUNDLE.nullTopic();
   }
}
 
Example #24
Source File: SessionIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void doCreateProducerFailsWhenLinkRefusedTestImpl(boolean deferAttachResponseWrite) throws JMSException, InterruptedException, Exception, IOException {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection = testFixture.establishConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String topicName = "myTopic";
        Topic dest = session.createTopic(topicName);

        //Expect a link to a topic node, which we will then refuse
        TargetMatcher targetMatcher = new TargetMatcher();
        targetMatcher.withAddress(equalTo(topicName));
        targetMatcher.withDynamic(equalTo(false));
        targetMatcher.withDurable(equalTo(TerminusDurability.NONE));

        testPeer.expectSenderAttach(targetMatcher, true, deferAttachResponseWrite);
        //Expect the detach response to the test peer closing the producer link after refusal.
        testPeer.expectDetach(true, false, false);
        testPeer.expectClose();

        try {
            //Create a producer, expect it to throw exception due to the link-refusal
            session.createProducer(dest);
            fail("Producer creation should have failed when link was refused");
        } catch(InvalidDestinationException ide) {
            //Expected
        }

        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #25
Source File: SubscriptionsIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void doUnsubscribeNonExistingSubscriptionTestImpl(boolean hasClientID) throws JMSException, InterruptedException, Exception, IOException {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        Connection connection;
        if(hasClientID) {
            connection = testFixture.establishConnecton(testPeer);
        } else {
            connection = testFixture.establishConnectonWithoutClientID(testPeer, null);
        }
        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String subscriptionName = "myInvalidSubscriptionName";
        // Try to unsubscribe non-existing subscription
        testPeer.expectDurableSubUnsubscribeNullSourceLookup(true, false, subscriptionName, null, hasClientID);
        testPeer.expectDetach(true, true, true);

        try {
            session.unsubscribe(subscriptionName);
            fail("Should have thrown a InvalidDestinationException");
        } catch (InvalidDestinationException ide) {
            // Expected
        }

        testPeer.waitForAllHandlersToComplete(1000);

        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #26
Source File: JmsExceptionUtils.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
/**
 * Converts instances of sub-classes of {@link JMSException} into the corresponding sub-class of
 * {@link JMSRuntimeException}.
 *
 * @param e
 * @return
 */
public static JMSRuntimeException convertToRuntimeException(JMSException e) {
   if (e instanceof javax.jms.IllegalStateException) {
      return new IllegalStateRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidClientIDException) {
      return new InvalidClientIDRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidDestinationException) {
      return new InvalidDestinationRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof InvalidSelectorException) {
      return new InvalidSelectorRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof JMSSecurityException) {
      return new JMSSecurityRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof MessageFormatException) {
      return new MessageFormatRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof MessageNotWriteableException) {
      return new MessageNotWriteableRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof ResourceAllocationException) {
      return new ResourceAllocationRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof TransactionInProgressException) {
      return new TransactionInProgressRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   if (e instanceof TransactionRolledBackException) {
      return new TransactionRolledBackRuntimeException(e.getMessage(), e.getErrorCode(), e);
   }
   return new JMSRuntimeException(e.getMessage(), e.getErrorCode(), e);
}
 
Example #27
Source File: FailoverIntegrationTest.java    From qpid-jms with Apache License 2.0 5 votes vote down vote up
private void doCreateConsumerFailsWhenLinkRefusedTestImpl(boolean deferAttachResponseWrite) throws Exception {
    try (TestAmqpPeer testPeer = new TestAmqpPeer();) {
        testPeer.expectSaslAnonymous();
        testPeer.expectOpen();
        testPeer.expectBegin();

        Connection connection = establishAnonymousConnecton(testPeer);
        connection.start();

        testPeer.expectBegin();
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);

        String topicName = "myTopic";
        Topic dest = session.createTopic(topicName);

        //Expect a link to a topic node, which we will then refuse
        SourceMatcher sourceMatcher = new SourceMatcher();
        sourceMatcher.withAddress(equalTo(topicName));
        sourceMatcher.withDynamic(equalTo(false));
        sourceMatcher.withDurable(equalTo(TerminusDurability.NONE));

        testPeer.expectReceiverAttach(notNullValue(), sourceMatcher, true, deferAttachResponseWrite);
        //Expect the detach response to the test peer closing the consumer link after refusal.
        testPeer.expectDetach(true, false, false);

        try {
            //Create a consumer, expect it to throw exception due to the link-refusal
            session.createConsumer(dest);
            fail("Consumer creation should have failed when link was refused");
        } catch(InvalidDestinationException ide) {
            LOG.info("Test caught expected error: {}", ide.getMessage());
        }

        // Shut it down
        testPeer.expectClose();
        connection.close();

        testPeer.waitForAllHandlersToComplete(1000);
    }
}
 
Example #28
Source File: AMQSession.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
public List<AMQConsumer> createConsumer(ConsumerInfo info,
                                        SlowConsumerDetectionListener slowConsumerDetectionListener) throws Exception {
   //check destination
   ActiveMQDestination dest = info.getDestination();
   ActiveMQDestination[] dests = null;
   if (dest.isComposite()) {
      dests = dest.getCompositeDestinations();
   } else {
      dests = new ActiveMQDestination[]{dest};
   }

   List<AMQConsumer> consumersList = new java.util.LinkedList<>();

   for (ActiveMQDestination openWireDest : dests) {
      boolean isInternalAddress = false;
      if (AdvisorySupport.isAdvisoryTopic(dest)) {
         if (!connection.isSuppportAdvisory()) {
            continue;
         }
         isInternalAddress = connection.isSuppressInternalManagementObjects();
      }
      if (openWireDest.isQueue()) {
         openWireDest = protocolManager.virtualTopicConsumerToFQQN(openWireDest);
         SimpleString queueName = new SimpleString(convertWildcard(openWireDest));

         if (!checkAutoCreateQueue(queueName, openWireDest.isTemporary())) {
            throw new InvalidDestinationException("Destination doesn't exist: " + queueName);
         }
      }
      AMQConsumer consumer = new AMQConsumer(this, openWireDest, info, scheduledPool, isInternalAddress);

      long nativeID = consumerIDGenerator.generateID();
      consumer.init(slowConsumerDetectionListener, nativeID);
      consumersList.add(consumer);
   }

   return consumersList;
}
 
Example #29
Source File: OpenWireConnection.java    From activemq-artemis with Apache License 2.0 5 votes vote down vote up
private Response convertException(Exception e) {
   Response resp;
   if (e instanceof ActiveMQSecurityException) {
      resp = new ExceptionResponse(new JMSSecurityException(e.getMessage()));
   } else if (e instanceof ActiveMQNonExistentQueueException) {
      resp = new ExceptionResponse(new InvalidDestinationException(e.getMessage()));
   } else {
      resp = new ExceptionResponse(e);
   }
   return resp;
}
 
Example #30
Source File: AmazonSQSMessagingClientWrapperTest.java    From amazon-sqs-java-messaging-lib with Apache License 2.0 5 votes vote down vote up
@Test(expected = InvalidDestinationException.class)
public void testGetQueueUrlQueueNameThrowQueueDoesNotExistException() throws JMSException {

    GetQueueUrlRequest getQueueUrlRequest = new GetQueueUrlRequest(QUEUE_NAME);
    doThrow(new QueueDoesNotExistException("qdnee"))
            .when(amazonSQSClient).getQueueUrl(eq(getQueueUrlRequest));

    wrapper.getQueueUrl(QUEUE_NAME);
}