Example usage for org.springframework.integration.handler MethodInvokingMessageProcessor processMessage

List of usage examples for org.springframework.integration.handler MethodInvokingMessageProcessor processMessage

Introduction

In this page you can find the example usage for org.springframework.integration.handler MethodInvokingMessageProcessor processMessage.

Prototype

@Override
    @Nullable
    @SuppressWarnings("unchecked")
    public T processMessage(Message<?> message) 

Source Link

Usage

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test(expected = MessageHandlingException.class)
public void conversionFailureWithAnnotatedMethod() throws Exception {
    AnnotatedTestService service = new AnnotatedTestService();
    Method method = service.getClass().getMethod("integerMethod", Integer.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
    processor.processMessage(new GenericMessage<String>("foo"));
}

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test
public void filterSelectsAnnotationMethodsOnly() {
    OverloadedMethodBean bean = new OverloadedMethodBean();
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, ServiceActivator.class);
    processor.processMessage(MessageBuilder.withPayload(123).build());
    assertNotNull(bean.lastArg);//from  ww w .ja va  2 s  . c o m
    assertEquals(String.class, bean.lastArg.getClass());
    assertEquals("123", bean.lastArg);
}

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test
public void testProcessMessageBadExpression() throws Exception {
    // TODO: should this be MessageHandlingException or NumberFormatException?
    expected.expect(new ExceptionCauseMatcher(Exception.class));
    AnnotatedTestService service = new AnnotatedTestService();
    Method method = service.getClass().getMethod("integerMethod", Integer.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
    assertEquals("foo", processor.processMessage(new GenericMessage<String>("foo")));
}

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test
public void testProcessMessageRuntimeException() throws Exception {
    expected.expect(new ExceptionCauseMatcher(UnsupportedOperationException.class));
    TestErrorService service = new TestErrorService();
    Method method = service.getClass().getMethod("error", String.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
    assertEquals("foo", processor.processMessage(new GenericMessage<String>("foo")));
}

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test
public void testProcessMessageCheckedException() throws Exception {
    expected.expect(new ExceptionCauseMatcher(CheckedException.class));
    TestErrorService service = new TestErrorService();
    Method method = service.getClass().getMethod("checked", String.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
    assertEquals("foo", processor.processMessage(new GenericMessage<String>("foo")));
}

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test
public void testProcessMessageMethodNotFound() throws Exception {
    expected.expect(new ExceptionCauseMatcher(SpelEvaluationException.class));
    TestDifferentErrorService service = new TestDifferentErrorService();
    Method method = TestErrorService.class.getMethod("checked", String.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
    processor.processMessage(new GenericMessage<String>("foo"));
}

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test
public void messageAndHeaderWithAnnotatedMethod() throws Exception {
    AnnotatedTestService service = new AnnotatedTestService();
    Method method = service.getClass().getMethod("messageAndHeader", Message.class, Integer.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
    Message<String> message = MessageBuilder.withPayload("foo").setHeader("number", 42).build();
    Object result = processor.processMessage(message);
    assertEquals("foo-42", result);
}

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test
public void multipleHeadersWithAnnotatedMethod() throws Exception {
    AnnotatedTestService service = new AnnotatedTestService();
    Method method = service.getClass().getMethod("twoHeaders", String.class, Integer.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(service, method);
    Message<String> message = MessageBuilder.withPayload("foo").setHeader("prop", "bar").setHeader("number", 42)
            .build();//  w w  w  .  j av  a  2s.c  o  m
    Object result = processor.processMessage(message);
    assertEquals("bar-42", result);
}

From source file:org.springframework.integration.handler.MethodInvokingMessageProcessorTests.java

@Test
public void testOverloadedNonVoidReturningMethodsWithExactMatchForType() {
    AmbiguousMethodBean bean = new AmbiguousMethodBean();
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(bean, "foo");
    processor.processMessage(MessageBuilder.withPayload("true").build());
    assertNotNull(bean.lastArg);/*from w  w w. java 2s  . c om*/
    assertEquals(String.class, bean.lastArg.getClass());
    assertEquals("true", bean.lastArg);
}