本文整理了Java中org.springframework.messaging.MessageHandlingException.getCause()
方法的一些代码示例,展示了MessageHandlingException.getCause()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。MessageHandlingException.getCause()
方法的具体详情如下:
包路径:org.springframework.messaging.MessageHandlingException
类名称:MessageHandlingException
方法名:getCause
暂无
代码示例来源:origin: spring-projects/spring-batch
@Test
@DirtiesContext
@SuppressWarnings("unchecked")
public void testWrongPayload() {
final Message<String> stringMessage = MessageBuilder.withPayload("just text").build();
try {
requestChannel.send(stringMessage);
fail();
}
catch (MessageHandlingException e) {
String message = e.getCause().getMessage();
assertTrue("Wrong message: " + message, message.contains("The payload must be of type JobLaunchRequest."));
}
Message<JobExecution> executionMessage = (Message<JobExecution>) responseChannel.receive(1000);
assertNull("JobExecution message received when no return address set", executionMessage);
}
代码示例来源:origin: spring-projects/spring-batch
@Test
public void testExceptionRaised() throws Exception {
final Message<JobLaunchRequest> message = MessageBuilder.withPayload(new JobLaunchRequest(new JobSupport("testJob"),
new JobParameters())).build();
final JobLauncher jobLauncher = mock(JobLauncher.class);
when(jobLauncher.run(any(Job.class), any(JobParameters.class)))
.thenThrow(new JobParametersInvalidException("This is a JobExecutionException."));
JobLaunchingGateway jobLaunchingGateway = new JobLaunchingGateway(jobLauncher);
try {
jobLaunchingGateway.handleMessage(message);
}
catch (MessageHandlingException e) {
assertEquals("This is a JobExecutionException.", e.getCause().getMessage());
return;
}
fail("Expecting a MessageHandlingException to be thrown.");
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void saveToSubDirWithEmptyStringExpression() throws Exception {
try {
this.inputChannelSaveToSubDirEmptyStringExpression.send(message);
}
catch (MessageHandlingException e) {
Assert.assertEquals("Unable to resolve Destination Directory for the provided Expression '' ''.",
e.getCause().getMessage());
return;
}
Assert.fail("Was expecting a MessageHandlingException to be thrown");
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void saveToSubDirWithWrongExpression() throws Exception {
try {
this.inputChannelSaveToSubDirWrongExpression.send(message);
}
catch (MessageHandlingException e) {
Assert.assertEquals(
TestUtils.applySystemFileSeparator("Destination path [target/base-directory/sub-directory/foo.txt] does not point to a directory."),
e.getCause().getMessage());
return;
}
Assert.fail("Was expecting a MessageHandlingException to be thrown");
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void saveToSubDirAutoCreateOff() throws Exception {
try {
this.inputChannelSaveToSubDirAutoCreateOff.send(message);
}
catch (MessageHandlingException e) {
Assert.assertEquals(
TestUtils.applySystemFileSeparator("Destination directory [target/base-directory2/sub-directory2] does not exist."),
e.getCause().getMessage());
return;
}
Assert.fail("Was expecting a MessageHandlingException to be thrown");
}
代码示例来源:origin: spring-projects/spring-integration
@Test //INT-2631
public void testFailOperationOnAbstractBean() {
try {
Message<?> message = MessageBuilder.withPayload("abstractService.convert('testString')").build();
this.input.send(message);
fail("Expected BeanIsAbstractException");
}
catch (MessageHandlingException e) {
Throwable cause = e.getCause();
assertTrue("Expected BeanIsAbstractException, got " + cause.getClass() + ":" + cause.getMessage(),
cause instanceof BeanIsAbstractException);
assertTrue(cause.getMessage().contains("abstractService"));
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test //INT-2567
public void testFailOperationOnNonManagedComponent() {
try {
Message<?> message =
MessageBuilder.withPayload("def result = nonManagedService.convert('testString')")
.build();
this.input.send(message);
fail("Expected BeanCreationNotAllowedException");
}
catch (MessageHandlingException e) {
Throwable cause = e.getCause();
assertTrue("Expected BeanCreationNotAllowedException, got " + cause.getClass() + ":" + cause.getMessage(),
cause instanceof BeanCreationNotAllowedException);
assertTrue(cause.getMessage().contains("nonManagedService"));
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testNullCorrelationKey() throws Exception {
final Message<?> message1 = MessageBuilder.withPayload("foo").build();
when(correlationStrategy.getCorrelationKey(isA(Message.class))).thenReturn(null);
try {
handler.handleMessage(message1);
fail("Expected MessageHandlingException");
}
catch (MessageHandlingException e) {
Throwable cause = e.getCause();
boolean pass = cause instanceof IllegalStateException && cause.getMessage().toLowerCase().contains("null correlation");
if (!pass) {
throw e;
}
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testTargetBeanResolver() {
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
this.getClass().getSimpleName() + "-fail-context.xml", this.getClass());
MessageChannel beanResolveIn = context.getBean("beanResolveIn", MessageChannel.class);
SomeBean payload = new SomeBean("foo");
assertEquals("foo", payload.getNested().getValue());
try {
beanResolveIn.send(new GenericMessage<SomeBean>(payload));
fail("Expected SpEL Exception");
}
catch (MessageHandlingException e) {
assertTrue(e.getCause() instanceof SpelEvaluationException);
}
context.close();
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void missingOutputChannelVerifiedAtRuntime() {
Message<?> request = new GenericMessage<String>("test");
try {
handler.handleMessage(request);
fail("Expected exception");
}
catch (MessageHandlingException e) {
assertThat(e.getCause(), instanceOf(DestinationResolutionException.class));
}
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void saveToSubWithFileExpressionUnsupportedObjectType() throws Exception {
final Integer unsupportedObject = Integer.valueOf(1234);
final Message<File> messageWithFileHeader = MessageBuilder.fromMessage(message)
.setHeader("subDirectory", unsupportedObject)
.build();
try {
this.inputChannelSaveToSubDirWithFile.send(messageWithFileHeader);
}
catch (MessageHandlingException e) {
Assert.assertEquals("The provided Destination Directory expression" +
" (headers['subDirectory']) must evaluate to type " +
"java.io.File or String, not java.lang.Integer.",
e.getCause().getMessage());
return;
}
Assert.fail("Was expecting a MessageHandlingException to be thrown");
}
代码示例来源:origin: spring-projects/spring-integration
@Test
@DirtiesContext
public void testWithMissingMessageHeader() throws Exception {
User user1 = new User("First User", "my first password", "email1");
Message<User> user1Message = MessageBuilder.withPayload(user1).build();
this.channel.send(user1Message);
Message<?> receive = this.startErrorsChannel.receive(10000);
assertNotNull(receive);
assertThat(receive, instanceOf(ErrorMessage.class));
MessageHandlingException exception = (MessageHandlingException) receive.getPayload();
String expectedMessage = "Unable to resolve Stored Procedure/Function name " +
"for the provided Expression 'headers['my_stored_procedure']'.";
String actualMessage = exception.getCause().getMessage();
Assert.assertEquals(expectedMessage, actualMessage);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testSecurityContextPropagation() {
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
this.queueChannel.send(new GenericMessage<String>("test"));
Message<?> receive = this.securedChannelQueue.receive(10000);
assertNotNull(receive);
SecurityContextHolder.clearContext();
this.queueChannel.send(new GenericMessage<String>("test"));
Message<?> errorMessage = this.errorChannel.receive(10000);
assertNotNull(errorMessage);
Object payload = errorMessage.getPayload();
assertThat(payload, instanceOf(MessageHandlingException.class));
assertThat(((MessageHandlingException) payload).getCause(),
instanceOf(AuthenticationCredentialsNotFoundException.class));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testSecurityContextPropagationQueueChannel() {
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
this.queueChannel.send(new GenericMessage<String>("test"));
Message<?> receive = this.securedChannelQueue.receive(10000);
assertNotNull(receive);
SecurityContextHolder.clearContext();
this.queueChannel.send(new GenericMessage<String>("test"));
Message<?> errorMessage = this.errorChannel.receive(10000);
assertNotNull(errorMessage);
Object payload = errorMessage.getPayload();
assertThat(payload, instanceOf(MessageHandlingException.class));
assertThat(((MessageHandlingException) payload).getCause(),
instanceOf(AuthenticationCredentialsNotFoundException.class));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void saveToSubWithFileExpressionNull() throws Exception {
final File directory = null;
final Message<File> messageWithFileHeader = MessageBuilder.fromMessage(message)
.setHeader("subDirectory", directory)
.build();
try {
this.inputChannelSaveToSubDirWithFile.send(messageWithFileHeader);
}
catch (MessageHandlingException e) {
Assert.assertEquals("The provided Destination Directory expression " +
"(headers['subDirectory']) must not evaluate to null.",
e.getCause().getMessage());
return;
}
Assert.fail("Was expecting a MessageHandlingException to be thrown");
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testSecurityContextPropagationExecutorChannel() {
login("bob", "bobspassword", "ROLE_ADMIN", "ROLE_PRESIDENT");
this.executorChannel.send(new GenericMessage<String>("test"));
Message<?> receive = this.securedChannelQueue.receive(10000);
assertNotNull(receive);
SecurityContextHolder.clearContext();
this.executorChannel.send(new GenericMessage<String>("test"));
Message<?> errorMessage = this.errorChannel.receive(10000);
assertNotNull(errorMessage);
Object payload = errorMessage.getPayload();
assertThat(payload, instanceOf(MessageHandlingException.class));
assertThat(((MessageHandlingException) payload).getCause(),
instanceOf(AuthenticationCredentialsNotFoundException.class));
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void testInt2720XmppUriVariables() throws Exception {
willThrow(new WebServiceIOException("intentional"))
.given(this.xmppConnection).sendStanza(Mockito.any(Stanza.class));
Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("to", "user").build();
try {
this.inputXmpp.send(message);
}
catch (MessageHandlingException e) {
// expected
Class<?> causeType = e.getCause().getClass();
assertTrue(WebServiceIOException.class.equals(causeType)); // offline
}
ArgumentCaptor<Stanza> argument = ArgumentCaptor.forClass(Stanza.class);
Mockito.verify(this.xmppConnection).sendStanza(argument.capture());
assertEquals("user@jabber.org", argument.getValue().getTo().toString());
assertEquals("xmpp:user@jabber.org", this.interceptor.getLastUri().toString());
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void invalidServiceName() {
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://localhost:1099/noSuchService");
boolean exceptionThrown = false;
try {
gateway.handleMessage(new GenericMessage<>("test"));
}
catch (MessageHandlingException e) {
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void invalidHost() {
RmiOutboundGateway gateway = new RmiOutboundGateway("rmi://noSuchHost:1099/testRemoteHandler");
boolean exceptionThrown = false;
try {
gateway.handleMessage(new GenericMessage<>("test"));
}
catch (MessageHandlingException e) {
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
代码示例来源:origin: spring-projects/spring-integration
@Test
public void invalidUrl() {
RmiOutboundGateway gateway = new RmiOutboundGateway("invalid");
boolean exceptionThrown = false;
try {
gateway.handleMessage(new GenericMessage<>("test"));
}
catch (MessageHandlingException e) {
assertEquals(RemoteLookupFailureException.class, e.getCause().getClass());
exceptionThrown = true;
}
assertTrue(exceptionThrown);
}
内容来源于网络,如有侵权,请联系作者删除!