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.MethodInvokingMessageProcessorAnnotationTests.java

@Test
public void fromMessageWithMapAndObjectMethod() throws Exception {
    Method method = TestService.class.getMethod("mapHeadersAndPayload", Map.class, Object.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Message<String> message = MessageBuilder.withPayload("test").setHeader("prop1", "foo")
            .setHeader("prop2", "bar").build();
    Map<?, ?> result = (Map<?, ?>) processor.processMessage(message);
    assertEquals(5, result.size());/*from   w w  w  .j a va  2  s  .co m*/
    assertTrue(result.containsKey(MessageHeaders.ID));
    assertTrue(result.containsKey(MessageHeaders.TIMESTAMP));
    assertEquals("foo", result.get("prop1"));
    assertEquals("bar", result.get("prop2"));
    assertEquals("test", result.get("payload"));
}

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

@Test
public void fromMessageWithPropertiesMethodAndPropertiesPayload() throws Exception {
    Method method = TestService.class.getMethod("propertiesPayload", Properties.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Properties payload = new Properties();
    payload.setProperty("prop1", "foo");
    payload.setProperty("prop2", "bar");
    Message<Properties> message = MessageBuilder.withPayload(payload).setHeader("prop1", "not")
            .setHeader("prop2", "these").build();
    Properties result = (Properties) processor.processMessage(message);
    assertEquals(2, result.size());/*from  w w w.j a  va2  s.  co m*/
    assertEquals("foo", result.getProperty("prop1"));
    assertEquals("bar", result.getProperty("prop2"));
}

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

@Test
public void fromMessageWithMapMethodAndHeadersAnnotation() throws Exception {
    Method method = TestService.class.getMethod("mapHeaders", Map.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Message<String> message = MessageBuilder.withPayload("test").setHeader("attrib1", new Integer(123))
            .setHeader("attrib2", new Integer(456)).build();
    Map<String, Object> result = (Map<String, Object>) processor.processMessage(message);
    assertEquals(new Integer(123), result.get("attrib1"));
    assertEquals(new Integer(456), result.get("attrib2"));
}

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

@Test
public void fromMessageWithMapMethodAndMapPayload() throws Exception {
    Method method = TestService.class.getMethod("mapPayload", Map.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Map<String, Integer> payload = new HashMap<String, Integer>();
    payload.put("attrib1", new Integer(88));
    payload.put("attrib2", new Integer(99));
    Message<Map<String, Integer>> message = MessageBuilder.withPayload(payload)
            .setHeader("attrib1", new Integer(123)).setHeader("attrib2", new Integer(456)).build();
    Map<String, Integer> result = (Map<String, Integer>) processor.processMessage(message);
    assertEquals(2, result.size());/* w  ww.  j  a va2s  .  c  o  m*/
    assertEquals(new Integer(88), result.get("attrib1"));
    assertEquals(new Integer(99), result.get("attrib2"));
}

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

@Test
public void headerAnnotationWithExpression() throws Exception {
    Message<?> message = this.getMessage();
    Method method = TestService.class.getMethod("headerAnnotationWithExpression", String.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Object result = processor.processMessage(message);
    Assert.assertEquals("monday", result);
}

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

@Test
public void irrelevantAnnotation() throws Exception {
    Message<?> message = MessageBuilder.withPayload("foo").build();
    Method method = TestService.class.getMethod("irrelevantAnnotation", String.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Object result = processor.processMessage(message);
    assertEquals("foo", result);
}

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

@Test
public void multipleAnnotatedArgs() throws Exception {
    Message<?> message = this.getMessage();
    Method method = TestService.class.getMethod("multipleAnnotatedArguments", String.class, String.class,
            Employee.class, String.class, Map.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Object[] parameters = (Object[]) processor.processMessage(message);
    Assert.assertNotNull(parameters);/* w  w  w  . jav  a  2  s . c o  m*/
    Assert.assertTrue(parameters.length == 5);
    Assert.assertTrue(parameters[0].equals("monday"));
    Assert.assertTrue(parameters[1].equals("September"));
    Assert.assertTrue(parameters[2].equals(employee));
    Assert.assertTrue(parameters[3].equals("oleg"));
    Assert.assertTrue(parameters[4] instanceof Map);
}

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

@Test
public void fromMessageToPayload() throws Exception {
    Method method = TestService.class.getMethod("mapOnly", Map.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Message<Employee> message = MessageBuilder.withPayload(employee).setHeader("number", "jkl").build();
    Object result = processor.processMessage(message);
    Assert.assertTrue(result instanceof Map);
    Assert.assertEquals("jkl", ((Map<?, ?>) result).get("number"));
}

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

@Test
public void fromMessageToPayloadArg() throws Exception {
    Method method = TestService.class.getMethod("payloadAnnotationFirstName", String.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Message<Employee> message = MessageBuilder.withPayload(employee).setHeader("number", "jkl").build();
    Object result = processor.processMessage(message);
    Assert.assertTrue(result instanceof String);
    Assert.assertEquals("oleg", result);
}

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

@Test
public void fromMessageToPayloadArgs() throws Exception {
    Method method = TestService.class.getMethod("payloadAnnotationFullName", String.class, String.class);
    MethodInvokingMessageProcessor processor = new MethodInvokingMessageProcessor(testService, method);
    Message<Employee> message = MessageBuilder.withPayload(employee).setHeader("number", "jkl").build();
    Object result = processor.processMessage(message);
    Assert.assertEquals("oleg zhurakousky", result);
}