Example usage for org.springframework.messaging Message getPayload

List of usage examples for org.springframework.messaging Message getPayload

Introduction

In this page you can find the example usage for org.springframework.messaging Message getPayload.

Prototype

T getPayload();

Source Link

Document

Return the message payload.

Usage

From source file:org.opencredo.couchdb.inbound.CouchDbAllDocumentsMessageSourceTest.java

private JsonNode receiveJson() {
    Message<URI> msg = (Message<URI>) messagingTemplate.receive();
    if (msg == null)
        return null;
    msg.getPayload();
    return messageSource.couchDbDocumentOperations.readDocument(msg.getPayload(), JsonNode.class);
}

From source file:biz.c24.io.spring.integration.transformer.IoUnmarshallingTransformerIUTests.java

@Test
public void canUnmarshalTextFromString() throws Exception {

    String validString = loadCsvString();

    C24UnmarshallingTransformer transformer = new C24UnmarshallingTransformer(model,
            new TextualSourceFactory());

    Message message = MessageBuilder.withPayload(validString).build();

    Message<?> outputMessage = transformer.transform(message);

    assertThat(outputMessage.getPayload(), notNullValue());
    assertThat(outputMessage.getPayload(), is(Employees.class));

    Employees employees = (Employees) outputMessage.getPayload();

}

From source file:apiserver.services.images.services.coldfusion.ImageDrawingCFService.java

public Object imageBorderHandler(Message<?> message) throws ColdFusionException {
    FileBorderJob props = (FileBorderJob) message.getPayload();

    try {//w  ww  .  ja va  2  s. c o m
        cfcPath = imageConfigMBean.getImageBorderPath();
        String method = imageConfigMBean.getImageBorderMethod();
        Map<String, Object> methodArgs = props.toMap();

        Object cfcResult = coldFusionBridge.invoke(cfcPath, method, methodArgs);

        if (cfcResult instanceof byte[]) {
            // convert base64 back to buffered image
            byte[] bytes = Base64.decodeBase64(new String((byte[]) cfcResult));
            BufferedImage bi = ImageIO.read(new ByteArrayInputStream(bytes));
            //BufferedImage bi = ImageIO.read(new ByteArrayInputStream( (byte[])cfcResult ));
            props.setBufferedImage(bi);
        } else {
            throw new NotImplementedException();
        }

        return props;
    } catch (Throwable e) {
        e.printStackTrace(); //todo use logging library
        throw new RuntimeException(e);
    }
}

From source file:biz.c24.io.spring.integration.transformer.IoMarshallingTransformerIUTests.java

@Test
public void canMarshalXmlToString() throws Exception {

    C24MarshallingTransformer ioMarshallingTransformer = new C24MarshallingTransformer();
    ioMarshallingTransformer.setOutputType(OutputType.STRING);
    XmlSinkFactory xmlSinkFactory = new XmlSinkFactory();
    ioMarshallingTransformer.setSinkFactory(xmlSinkFactory);

    Message message = MessageBuilder.withPayload(loadObject()).build();

    Message<?> outputMessage = ioMarshallingTransformer.transform(message);

    assertThat(outputMessage.getPayload(), notNullValue());
    assertThat(outputMessage.getPayload(), is(String.class));

    // TODO: XML equivalence match

}

From source file:biz.c24.io.spring.integration.transformer.IoUnmarshallingTransformerIUTests.java

@Test
public void canUnmarshalTextFromMultipartFile() throws Exception {

    byte[] valid1 = loadCsvBytes();
    MultipartFile file = mock(MultipartFile.class);
    when(file.getInputStream()).thenReturn(new ByteArrayInputStream(valid1));

    C24UnmarshallingTransformer transformer = new C24UnmarshallingTransformer(model,
            new TextualSourceFactory());

    Message message = MessageBuilder.withPayload(file).build();

    Message<?> outputMessage = transformer.transform(message);

    assertThat(outputMessage.getPayload(), notNullValue());
    assertThat(outputMessage.getPayload(), is(Employees.class));

    Employees employees = (Employees) outputMessage.getPayload();
}

From source file:biz.c24.io.spring.integration.transformer.IoMarshallingTransformerIUTests.java

@Test
public void canMarshalXmlToBytearray() throws Exception {

    C24MarshallingTransformer ioMarshallingTransformer = new C24MarshallingTransformer();
    ioMarshallingTransformer.setOutputType(OutputType.BYTE_ARRAY);
    XmlSinkFactory xmlSinkFactory = new XmlSinkFactory();
    ioMarshallingTransformer.setSinkFactory(xmlSinkFactory);

    Message<?> message = MessageBuilder.withPayload(loadObject()).build();

    Message<?> outputMessage = ioMarshallingTransformer.transform(message);

    assertThat(outputMessage.getPayload(), notNullValue());
    assertThat(outputMessage.getPayload(), is(byte[].class));

    String xml = new String((byte[]) outputMessage.getPayload(), "UTF-8");

    // TODO: XML equivalence match

}

From source file:biz.c24.io.spring.integration.transformer.IoMarshallingTransformerIUTests.java

@Test
public void canMarshalTextToString() throws Exception {

    C24MarshallingTransformer ioMarshallingTransformer = new C24MarshallingTransformer();
    ioMarshallingTransformer.setOutputType(OutputType.STRING);
    ioMarshallingTransformer.setSinkFactory(new TextualSinkFactory());

    Message message = MessageBuilder.withPayload(loadObject()).build();

    Message<?> outputMessage = ioMarshallingTransformer.transform(message);

    assertThat((String) outputMessage.getPayload(), is(loadCsvString()));

}

From source file:biz.c24.io.spring.integration.transformer.IoMarshallingTransformerIUTests.java

@Test
public void canMarshalTextToByteArray() throws Exception {

    C24MarshallingTransformer ioMarshallingTransformer = new C24MarshallingTransformer();
    ioMarshallingTransformer.setOutputType(OutputType.BYTE_ARRAY);
    ioMarshallingTransformer.setSinkFactory(new TextualSinkFactory());

    Message message = MessageBuilder.withPayload(loadObject()).build();

    Message<?> outputMessage = ioMarshallingTransformer.transform(message);

    assertThat((byte[]) outputMessage.getPayload(), is(loadCsvBytes()));

}

From source file:biz.c24.io.spring.integration.router.C24XPathRouter.java

@Override
protected List<Object> getChannelKeys(Message<?> message) {

    ComplexDataObject cdo;/*  www  .  j a  v a2 s  .c  o  m*/
    try {
        cdo = (ComplexDataObject) message.getPayload();
    } catch (ClassCastException e) {

        Object payload = message.getPayload();

        throw new MessagingException("Cannot route based on payloads of type [" + payload == null ? "<null>"
                : payload.getClass().getName() + "]. Only ComplexDataObject is supported.", e);
    }

    IOXPath xPath = createXPath();

    String channel;
    try {
        channel = xPath.getString(cdo);
    } catch (IOXPathException e) {
        throw new MessagingException("Exception when trying to evaluate the Xpath statement [" + statement
                + "] on the object [" + cdo + "] to a String.", e);
    }

    return Collections.singletonList((Object) channel);

}

From source file:biz.c24.io.spring.integration.transformer.IoMarshallingTransformerIUTests.java

@Test
public void canMarshalTextToJsonString() throws Exception {

    C24MarshallingTransformer ioMarshallingTransformer = new C24MarshallingTransformer();
    ioMarshallingTransformer.setOutputType(OutputType.STRING);
    ioMarshallingTransformer.setSinkFactory(new JsonSinkFactory());

    Message message = MessageBuilder.withPayload(loadObject()).build();
    Message<?> outputMessage = ioMarshallingTransformer.transform(message);

    String result = ((String) outputMessage.getPayload()).replaceAll("\n", "").replaceAll("\t", "");
    String expected = loadJsonString().replaceAll("\n", "").replaceAll("\t", "");
    assertThat(result, is(expected));/*from   w  w  w.  j a  va2 s. co m*/
}