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:rest.json.Application.java

@Bean
public IntegrationFlow testXChannel2() {
    return IntegrationFlows.from("TestChannel2").handle(new GenericHandler<Message>() {
        @Override//  w  ww  .j a  v  a2 s  .  c o  m
        public Object handle(Message payload, Map<String, Object> headers) {
            System.out.println("TestChannel2: " + payload.getPayload() + " " + payload.getPayload().getClass());
            return payload;
        }
    }).channel("testXChannel3.input").get();
}

From source file:biz.c24.io.spring.integration.config.SelectorTests.java

@Test
public void canSelect() throws Exception {

    template.convertAndSend(loadCsvBytes());

    Message<?> message = rightChannel.receive(1);

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

}

From source file:apiserver.services.images.services.jhlabs.BumpFilterService.java

public Object doFilter(Message<?> message) throws MessageConfigException {
    BumpJob props = (BumpJob) message.getPayload();

    int edgeAction = props.getEdgeAction();
    boolean useAlpha = props.isUseAlpha();
    float[] embossMatrix = props.getMatrix();

    try {/*from   w  w  w  . j  a v  a2 s  .c  o  m*/

        // calculate
        int rows = new Double(Math.sqrt(new Integer(embossMatrix.length).doubleValue())).intValue();
        int cols = new Double(Math.sqrt(new Integer(embossMatrix.length).doubleValue())).intValue();

        //run filter
        BumpFilter filter = new BumpFilter();
        filter.setEdgeAction(edgeAction);
        filter.setUseAlpha(useAlpha);
        filter.setKernel(new Kernel(rows, cols, embossMatrix));

        BufferedImage bufferedImage = props.getBufferedImage();
        if (bufferedImage == null) {
            throw new MessageConfigException(MessageConfigException.MISSING_PROPERTY);
        }

        BufferedImage outFile = filter.filter(bufferedImage, null);

        props.setBufferedImage(outFile);
        return message;
    } catch (Throwable e) {
        //log.error(e.getMessage(), e);
        throw new RuntimeException(e);
    }
}

From source file:apiserver.services.pdf.service.ProcessPdfDDXCFService.java

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

    try {/*from   w  ww.  j  a va 2 s .c om*/
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<ByteArrayResult> future = exec
                .submit(new ProcessDDXCallable(props.getFile().getFileBytes(), props.getDdx()));

        ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:apiserver.services.pdf.service.UrlToPdfCFService.java

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

    try {//from w w  w  .j ava 2s  .  co m
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'coldfusion-worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<ByteArrayResult> future = exec.submit(new UrlToPdfCallable(props.getPath(), props.getOptions()));

        ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:it.pcan.test.integration.amqp.ErrorHandler.java

@ServiceActivator
public Message handleException(Message msg) {
    System.out.println("Exception thrown: " + msg);
    MessageHandlingException payload = (MessageHandlingException) msg.getPayload();
    MessageHeaders headers = payload.getFailedMessage().getHeaders();
    HashMap<String, Object> newHeaders = new HashMap<>(headers);

    newHeaders.putAll(msg.getHeaders());
    Throwable cause = payload.getCause();
    RuntimeException ex = (cause instanceof RuntimeException) ? (RuntimeException) cause
            : new RuntimeException(cause);

    Message m = new GenericMessage(new RuntimeExceptionHolder(ex), newHeaders);
    return m;/*from  w  w  w  . j  a v a 2  s  .  c  om*/
}

From source file:apiserver.services.images.services.drewMetadata.ImageMetadataService.java

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

    try {/*from w ww.ja v a 2s  .c o m*/
        File file = props.getDocument().getFile();
        String contentType = (String) props.getDocument().getContentType().name();

        Map metadataDirectories = new HashMap();

        Metadata metadata = ImageMetadataReader.readMetadata(file);

        for (Directory directory : metadata.getDirectories()) {
            Map metadataTags = new HashMap();
            metadataDirectories.put(directory.getName(), metadataTags);
            for (Tag tag : directory.getTags()) {
                metadataTags.put(tag.getTagName(), tag.getDescription());
            }
        }

        props.setMetadata(metadataDirectories);

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

From source file:apiserver.services.pdf.service.HtmlToPdfCFService.java

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

    try {/*ww w .  j  av  a 2  s.co  m*/
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<ByteArrayResult> future = exec.submit(new HtmlToPdfCallable(props.getHtml(),
                props.getHeaderHtml(), props.getFooterHtml(), props.getOptions()));

        ByteArrayResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}

From source file:sample.SampleTransformer.java

@ServiceActivator(inputChannel = "xform")
public String log(Message<?> message) throws InterruptedException {
    log.info("Received: " + message);
    this.background.background();
    return message.getPayload().toString().toUpperCase();
}

From source file:apiserver.services.pdf.service.GenerateThumbnailPdfCFService.java

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

    try {/*from w  ww. j av a2  s  .  c  o m*/
        long startTime = System.nanoTime();
        Grid grid = verifyGridConnection();

        // Get grid-enabled executor service for nodes where attribute 'worker' is defined.
        ExecutorService exec = getColdFusionExecutor();

        Future<CollectionResult> future = exec
                .submit(new GenerateThumbnailCallable(props.getFile().getFileBytes(), props.getOptions()));

        CollectionResult _result = future.get(defaultTimeout, TimeUnit.SECONDS);
        //props.setResult(_result.getBytes());

        long endTime = System.nanoTime();
        log.debug("execution times: CF=" + _result.getStats().getExecutionTime() + "ms -- total="
                + (endTime - startTime) + "ms");

        return props;
    } catch (Exception ge) {
        throw new RuntimeException(ge);
    }
}