org.springframework.messaging.core.DestinationResolutionException Java Examples
The following examples show how to use
org.springframework.messaging.core.DestinationResolutionException.
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: DynamicTopicDestinationResolver.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Override public String resolveDestination(String name) throws DestinationResolutionException { if (this.autoCreate) { return this.amazonSns.createTopic(new CreateTopicRequest(name)).getTopicArn(); } else { String physicalTopicName = name; if (this.resourceIdResolver != null) { physicalTopicName = this.resourceIdResolver .resolveToPhysicalResourceId(name); } if (physicalTopicName != null && AmazonResourceName.isValidAmazonResourceName(physicalTopicName)) { return physicalTopicName; } String topicArn = getTopicResourceName(null, physicalTopicName); if (topicArn == null) { throw new IllegalArgumentException("No Topic with name: '" + name + "' found. Please use " + "the right topic name or enable auto creation of topics for this DestinationResolver"); } return topicArn; } }
Example #2
Source File: DynamicQueueUrlDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void testInvalidDestinationName() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); AmazonServiceException exception = new QueueDoesNotExistException( "AWS.SimpleQueueService.NonExistentQueue"); exception.setErrorCode("AWS.SimpleQueueService.NonExistentQueue"); String queueUrl = "invalidName"; when(amazonSqs.getQueueUrl(new GetQueueUrlRequest(queueUrl))) .thenThrow(exception); DynamicQueueUrlDestinationResolver dynamicQueueDestinationResolver = new DynamicQueueUrlDestinationResolver( amazonSqs); try { dynamicQueueDestinationResolver.resolveDestination(queueUrl); } catch (DestinationResolutionException e) { assertThat(e.getMessage()).startsWith("The queue does not exist."); } }
Example #3
Source File: DynamicQueueUrlDestinationResolverTest.java From spring-cloud-aws with Apache License 2.0 | 6 votes |
@Test void testPotentiallyNoAccessToPerformGetQueueUrl() throws Exception { AmazonSQS amazonSqs = mock(AmazonSQS.class); AmazonServiceException exception = new QueueDoesNotExistException( "AWS.SimpleQueueService.NonExistentQueue"); exception.setErrorCode("AWS.SimpleQueueService.NonExistentQueue"); exception.setErrorMessage( "The specified queue does not exist or you do not have access to it."); String queueUrl = "noAccessGetQueueUrlName"; when(amazonSqs.getQueueUrl(new GetQueueUrlRequest(queueUrl))) .thenThrow(exception); DynamicQueueUrlDestinationResolver dynamicQueueDestinationResolver = new DynamicQueueUrlDestinationResolver( amazonSqs); try { dynamicQueueDestinationResolver.resolveDestination(queueUrl); } catch (DestinationResolutionException e) { assertThat(e.getMessage()).startsWith( "The queue does not exist or no access to perform action sqs:GetQueueUrl."); } }
Example #4
Source File: JmsMessagingTemplate.java From spring-analysis-note with MIT License | 5 votes |
protected MessagingException convertJmsException(JmsException ex) { if (ex instanceof org.springframework.jms.support.destination.DestinationResolutionException || ex instanceof InvalidDestinationException) { return new DestinationResolutionException(ex.getMessage(), ex); } if (ex instanceof org.springframework.jms.support.converter.MessageConversionException) { return new MessageConversionException(ex.getMessage(), ex); } // Fallback return new MessagingException(ex.getMessage(), ex); }
Example #5
Source File: JmsMessagingTemplate.java From java-technology-stack with MIT License | 5 votes |
protected MessagingException convertJmsException(JmsException ex) { if (ex instanceof org.springframework.jms.support.destination.DestinationResolutionException || ex instanceof InvalidDestinationException) { return new DestinationResolutionException(ex.getMessage(), ex); } if (ex instanceof org.springframework.jms.support.converter.MessageConversionException) { return new MessageConversionException(ex.getMessage(), ex); } // Fallback return new MessagingException(ex.getMessage(), ex); }
Example #6
Source File: JmsMessagingTemplate.java From spring4-understanding with Apache License 2.0 | 5 votes |
protected MessagingException convertJmsException(JmsException ex) { if (ex instanceof org.springframework.jms.support.destination.DestinationResolutionException || ex instanceof InvalidDestinationException) { return new DestinationResolutionException(ex.getMessage(), ex); } if (ex instanceof org.springframework.jms.support.converter.MessageConversionException) { return new MessageConversionException(ex.getMessage(), ex); } // Fallback return new MessagingException(ex.getMessage(), ex); }
Example #7
Source File: DynamicQueueUrlDestinationResolver.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
@Override public String resolveDestination(String name) throws DestinationResolutionException { String queueName = name; if (this.resourceIdResolver != null) { queueName = this.resourceIdResolver.resolveToPhysicalResourceId(name); } if (isValidQueueUrl(queueName)) { return queueName; } if (this.autoCreate) { // Auto-create is fine to be called even if the queue exists. CreateQueueResult createQueueResult = this.amazonSqs .createQueue(new CreateQueueRequest(queueName)); return createQueueResult.getQueueUrl(); } else { try { GetQueueUrlResult getQueueUrlResult = this.amazonSqs .getQueueUrl(new GetQueueUrlRequest(queueName)); return getQueueUrlResult.getQueueUrl(); } catch (QueueDoesNotExistException e) { throw toDestinationResolutionException(e); } } }
Example #8
Source File: DynamicQueueUrlDestinationResolver.java From spring-cloud-aws with Apache License 2.0 | 5 votes |
private DestinationResolutionException toDestinationResolutionException( QueueDoesNotExistException e) { if (e.getMessage() != null && e.getMessage().contains("access")) { return new DestinationResolutionException( "The queue does not exist or no access to perform action sqs:GetQueueUrl.", e); } else { return new DestinationResolutionException("The queue does not exist.", e); } }
Example #9
Source File: MessageListenerContainerTest.java From spring-cloud-aws with Apache License 2.0 | 4 votes |
@Test void receiveMessageRequests_withDestinationResolverThrowingException_shouldLogWarningAndNotCreateRequest() throws Exception { // Arrange AbstractMessageListenerContainer container = new StubAbstractMessageListenerContainer(); Logger loggerMock = container.getLogger(); AmazonSQSAsync mock = mock(AmazonSQSAsync.class, withSettings().stubOnly()); container.setAmazonSqs(mock); StaticApplicationContext applicationContext = new StaticApplicationContext(); QueueMessageHandler messageHandler = new QueueMessageHandler(); messageHandler.setApplicationContext(applicationContext); container.setMessageHandler(messageHandler); applicationContext.registerSingleton("messageListener", MessageListener.class); applicationContext.registerSingleton("anotherMessageListener", AnotherMessageListener.class); String destinationResolutionExceptionMessage = "Queue not found"; when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("testQueue"))) .thenThrow(new DestinationResolutionException( destinationResolutionExceptionMessage)); when(mock.getQueueUrl(new GetQueueUrlRequest().withQueueName("anotherTestQueue"))) .thenReturn(new GetQueueUrlResult() .withQueueUrl("https://anotherTestQueue.amazonaws.com")); when(mock.getQueueAttributes(any(GetQueueAttributesRequest.class))) .thenReturn(new GetQueueAttributesResult()); messageHandler.afterPropertiesSet(); container.afterPropertiesSet(); // Act container.start(); // Assert ArgumentCaptor<String> logMsgArgCaptor = ArgumentCaptor.forClass(String.class); verify(loggerMock).warn(logMsgArgCaptor.capture()); Map<String, QueueAttributes> registeredQueues = container.getRegisteredQueues(); assertThat(registeredQueues.containsKey("testQueue")).isFalse(); assertThat(logMsgArgCaptor.getValue()) .isEqualTo("Ignoring queue with name 'testQueue': " + destinationResolutionExceptionMessage); assertThat(registeredQueues.get("anotherTestQueue").getReceiveMessageRequest() .getQueueUrl()).isEqualTo("https://anotherTestQueue.amazonaws.com"); }