org.springframework.messaging.MessageHandlingException.getCause()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(12.6k)|赞(0)|评价(0)|浏览(160)

本文整理了Java中org.springframework.messaging.MessageHandlingException.getCause()方法的一些代码示例,展示了MessageHandlingException.getCause()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MessageHandlingException.getCause()方法的具体详情如下:
包路径:org.springframework.messaging.MessageHandlingException
类名称:MessageHandlingException
方法名:getCause

MessageHandlingException.getCause介绍

暂无

代码示例

代码示例来源:origin: spring-projects/spring-batch

  1. @Test
  2. @DirtiesContext
  3. @SuppressWarnings("unchecked")
  4. public void testWrongPayload() {
  5. final Message<String> stringMessage = MessageBuilder.withPayload("just text").build();
  6. try {
  7. requestChannel.send(stringMessage);
  8. fail();
  9. }
  10. catch (MessageHandlingException e) {
  11. String message = e.getCause().getMessage();
  12. assertTrue("Wrong message: " + message, message.contains("The payload must be of type JobLaunchRequest."));
  13. }
  14. Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);
  15. assertNull("JobExecution message received when no return address set", executionMessage);
  16. }

代码示例来源:origin: spring-projects/spring-batch

  1. @Test
  2. public void testExceptionRaised() throws Exception {
  3. final Message<JobLaunchRequest> message = MessageBuilder.withPayload(new JobLaunchRequest(new JobSupport("testJob"),
  4. new JobParameters())).build();
  5. final JobLauncher jobLauncher = mock(JobLauncher.class);
  6. when(jobLauncher.run(any(Job.class), any(JobParameters.class)))
  7. .thenThrow(new JobParametersInvalidException("This is a JobExecutionException."));
  8. JobLaunchingGateway jobLaunchingGateway = new JobLaunchingGateway(jobLauncher);
  9. try {
  10. jobLaunchingGateway.handleMessage(message);
  11. }
  12. catch (MessageHandlingException e) {
  13. assertEquals("This is a JobExecutionException.", e.getCause().getMessage());
  14. return;
  15. }
  16. fail("Expecting a MessageHandlingException to be thrown.");
  17. }
  18. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void saveToSubDirWithEmptyStringExpression() throws Exception {
  3. try {
  4. this.inputChannelSaveToSubDirEmptyStringExpression.send(message);
  5. }
  6. catch (MessageHandlingException e) {
  7. Assert.assertEquals("Unable to resolve Destination Directory for the provided Expression '' ''.",
  8. e.getCause().getMessage());
  9. return;
  10. }
  11. Assert.fail("Was expecting a MessageHandlingException to be thrown");
  12. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void saveToSubDirWithWrongExpression() throws Exception {
  3. try {
  4. this.inputChannelSaveToSubDirWrongExpression.send(message);
  5. }
  6. catch (MessageHandlingException e) {
  7. Assert.assertEquals(
  8. TestUtils.applySystemFileSeparator("Destination path [target/base-directory/sub-directory/foo.txt] does not point to a directory."),
  9. e.getCause().getMessage());
  10. return;
  11. }
  12. Assert.fail("Was expecting a MessageHandlingException to be thrown");
  13. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void saveToSubDirAutoCreateOff() throws Exception {
  3. try {
  4. this.inputChannelSaveToSubDirAutoCreateOff.send(message);
  5. }
  6. catch (MessageHandlingException e) {
  7. Assert.assertEquals(
  8. TestUtils.applySystemFileSeparator("Destination directory [target/base-directory2/sub-directory2] does not exist."),
  9. e.getCause().getMessage());
  10. return;
  11. }
  12. Assert.fail("Was expecting a MessageHandlingException to be thrown");
  13. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test //INT-2631
  2. public void testFailOperationOnAbstractBean() {
  3. try {
  4. Message<?> message = MessageBuilder.withPayload("abstractService.convert('testString')").build();
  5. this.input.send(message);
  6. fail("Expected BeanIsAbstractException");
  7. }
  8. catch (MessageHandlingException e) {
  9. Throwable cause = e.getCause();
  10. assertTrue("Expected BeanIsAbstractException, got " + cause.getClass() + ":" + cause.getMessage(),
  11. cause instanceof BeanIsAbstractException);
  12. assertTrue(cause.getMessage().contains("abstractService"));
  13. }
  14. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test //INT-2567
  2. public void testFailOperationOnNonManagedComponent() {
  3. try {
  4. Message<?> message =
  5. MessageBuilder.withPayload("def result = nonManagedService.convert('testString')")
  6. .build();
  7. this.input.send(message);
  8. fail("Expected BeanCreationNotAllowedException");
  9. }
  10. catch (MessageHandlingException e) {
  11. Throwable cause = e.getCause();
  12. assertTrue("Expected BeanCreationNotAllowedException, got " + cause.getClass() + ":" + cause.getMessage(),
  13. cause instanceof BeanCreationNotAllowedException);
  14. assertTrue(cause.getMessage().contains("nonManagedService"));
  15. }
  16. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testNullCorrelationKey() throws Exception {
  3. final Message<?> message1 = MessageBuilder.withPayload("foo").build();
  4. when(correlationStrategy.getCorrelationKey(isA(Message.class))).thenReturn(null);
  5. try {
  6. handler.handleMessage(message1);
  7. fail("Expected MessageHandlingException");
  8. }
  9. catch (MessageHandlingException e) {
  10. Throwable cause = e.getCause();
  11. boolean pass = cause instanceof IllegalStateException && cause.getMessage().toLowerCase().contains("null correlation");
  12. if (!pass) {
  13. throw e;
  14. }
  15. }
  16. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testTargetBeanResolver() {
  3. ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
  4. this.getClass().getSimpleName() + "-fail-context.xml", this.getClass());
  5. MessageChannel beanResolveIn = context.getBean("beanResolveIn", MessageChannel.class);
  6. SomeBean payload = new SomeBean("foo");
  7. assertEquals("foo", payload.getNested().getValue());
  8. try {
  9. beanResolveIn.send(new GenericMessage<SomeBean>(payload));
  10. fail("Expected SpEL Exception");
  11. }
  12. catch (MessageHandlingException e) {
  13. assertTrue(e.getCause() instanceof SpelEvaluationException);
  14. }
  15. context.close();
  16. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void missingOutputChannelVerifiedAtRuntime() {
  3. Message<?> request = new GenericMessage<String>("test");
  4. try {
  5. handler.handleMessage(request);
  6. fail("Expected exception");
  7. }
  8. catch (MessageHandlingException e) {
  9. assertThat(e.getCause(), instanceOf(DestinationResolutionException.class));
  10. }
  11. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void saveToSubWithFileExpressionUnsupportedObjectType() throws Exception {
  3. final Integer unsupportedObject = Integer.valueOf(1234);
  4. final Message<File> messageWithFileHeader = MessageBuilder.fromMessage(message)
  5. .setHeader("subDirectory", unsupportedObject)
  6. .build();
  7. try {
  8. this.inputChannelSaveToSubDirWithFile.send(messageWithFileHeader);
  9. }
  10. catch (MessageHandlingException e) {
  11. Assert.assertEquals("The provided Destination Directory expression" +
  12. " (headers['subDirectory']) must evaluate to type " +
  13. "java.io.File or String, not java.lang.Integer.",
  14. e.getCause().getMessage());
  15. return;
  16. }
  17. Assert.fail("Was expecting a MessageHandlingException to be thrown");
  18. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. @DirtiesContext
  3. public void testWithMissingMessageHeader() throws Exception {
  4. User user1 = new User("First User", "my first password", "email1");
  5. Message<User> user1Message = MessageBuilder.withPayload(user1).build();
  6. this.channel.send(user1Message);
  7. Message<?> receive = this.startErrorsChannel.receive(10000);
  8. assertNotNull(receive);
  9. assertThat(receive, instanceOf(ErrorMessage.class));
  10. MessageHandlingException exception = (MessageHandlingException) receive.getPayload();
  11. String expectedMessage = "Unable to resolve Stored Procedure/Function name " +
  12. "for the provided Expression 'headers['my_stored_procedure']'.";
  13. String actualMessage = exception.getCause().getMessage();
  14. Assert.assertEquals(expectedMessage, actualMessage);
  15. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testSecurityContextPropagation() {
  3. login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
  4. this.queueChannel.send(new GenericMessage<String>("test"));
  5. Message<?> receive = this.securedChannelQueue.receive(10000);
  6. assertNotNull(receive);
  7. SecurityContextHolder.clearContext();
  8. this.queueChannel.send(new GenericMessage<String>("test"));
  9. Message<?> errorMessage = this.errorChannel.receive(10000);
  10. assertNotNull(errorMessage);
  11. Object payload = errorMessage.getPayload();
  12. assertThat(payload, instanceOf(MessageHandlingException.class));
  13. assertThat(((MessageHandlingException) payload).getCause(),
  14. instanceOf(AuthenticationCredentialsNotFoundException.class));
  15. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testSecurityContextPropagationQueueChannel() {
  3. login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
  4. this.queueChannel.send(new GenericMessage<String>("test"));
  5. Message<?> receive = this.securedChannelQueue.receive(10000);
  6. assertNotNull(receive);
  7. SecurityContextHolder.clearContext();
  8. this.queueChannel.send(new GenericMessage<String>("test"));
  9. Message<?> errorMessage = this.errorChannel.receive(10000);
  10. assertNotNull(errorMessage);
  11. Object payload = errorMessage.getPayload();
  12. assertThat(payload, instanceOf(MessageHandlingException.class));
  13. assertThat(((MessageHandlingException) payload).getCause(),
  14. instanceOf(AuthenticationCredentialsNotFoundException.class));
  15. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void saveToSubWithFileExpressionNull() throws Exception {
  3. final File directory = null;
  4. final Message<File> messageWithFileHeader = MessageBuilder.fromMessage(message)
  5. .setHeader("subDirectory", directory)
  6. .build();
  7. try {
  8. this.inputChannelSaveToSubDirWithFile.send(messageWithFileHeader);
  9. }
  10. catch (MessageHandlingException e) {
  11. Assert.assertEquals("The provided Destination Directory expression " +
  12. "(headers['subDirectory']) must not evaluate to null.",
  13. e.getCause().getMessage());
  14. return;
  15. }
  16. Assert.fail("Was expecting a MessageHandlingException to be thrown");
  17. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testSecurityContextPropagationExecutorChannel() {
  3. login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
  4. this.executorChannel.send(new GenericMessage<String>("test"));
  5. Message<?> receive = this.securedChannelQueue.receive(10000);
  6. assertNotNull(receive);
  7. SecurityContextHolder.clearContext();
  8. this.executorChannel.send(new GenericMessage<String>("test"));
  9. Message<?> errorMessage = this.errorChannel.receive(10000);
  10. assertNotNull(errorMessage);
  11. Object payload = errorMessage.getPayload();
  12. assertThat(payload, instanceOf(MessageHandlingException.class));
  13. assertThat(((MessageHandlingException) payload).getCause(),
  14. instanceOf(AuthenticationCredentialsNotFoundException.class));
  15. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void testInt2720XmppUriVariables() throws Exception {
  3. willThrow(new WebServiceIOException("intentional"))
  4. .given(this.xmppConnection).sendStanza(Mockito.any(Stanza.class));
  5. Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("to", "user").build();
  6. try {
  7. this.inputXmpp.send(message);
  8. }
  9. catch (MessageHandlingException e) {
  10. // expected
  11. Class<?> causeType = e.getCause().getClass();
  12. assertTrue(WebServiceIOException.class.equals(causeType)); // offline
  13. }
  14. ArgumentCaptor<Stanza> argument = ArgumentCaptor.forClass(Stanza.class);
  15. Mockito.verify(this.xmppConnection).sendStanza(argument.capture());
  16. assertEquals("user@jabber.org", argument.getValue().getTo().toString());
  17. assertEquals("xmpp:user@jabber.org", this.interceptor.getLastUri().toString());
  18. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void invalidServiceName() {
  3. RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:1099/noSuchService");
  4. boolean exceptionThrown = false;
  5. try {
  6. gateway.handleMessage(new GenericMessage<>("test"));
  7. }
  8. catch (MessageHandlingException e) {
  9. assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
  10. exceptionThrown = true;
  11. }
  12. assertTrue(exceptionThrown);
  13. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void invalidHost() {
  3. RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://noSuchHost:1099/testRemoteHandler");
  4. boolean exceptionThrown = false;
  5. try {
  6. gateway.handleMessage(new GenericMessage<>("test"));
  7. }
  8. catch (MessageHandlingException e) {
  9. assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
  10. exceptionThrown = true;
  11. }
  12. assertTrue(exceptionThrown);
  13. }

代码示例来源:origin: spring-projects/spring-integration

  1. @Test
  2. public void invalidUrl() {
  3. RmiOutboundGateway gateway = new RmiOutboundGateway("invalid");
  4. boolean exceptionThrown = false;
  5. try {
  6. gateway.handleMessage(new GenericMessage<>("test"));
  7. }
  8. catch (MessageHandlingException e) {
  9. assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
  10. exceptionThrown = true;
  11. }
  12. assertTrue(exceptionThrown);
  13. }

相关文章