List of usage examples for org.springframework.messaging Message getPayload
T getPayload();
From source file:apiserver.services.images.services.ImageInfoService.java
public Object execute(Message<?> message) throws IOException { FileInfoJob props = (FileInfoJob) message.getPayload(); Map result = new HashMap(); result.put(ApiServerConstants.WIDTH, props.getBufferedImage().getWidth()); result.put(ApiServerConstants.HEIGHT, props.getBufferedImage().getHeight()); // return results MessageBuilder mb = MessageBuilder.withPayload(result); mb.copyHeaders(message.getHeaders()); return mb.build(); }
From source file:io.pivotal.example.order.status.OrderStatusController.java
@StreamListener(Sink.INPUT) public void receive(Message<?> message) { String payload = message.getPayload().toString(); Matcher matcher = PATTERN.matcher(payload.replace('\n', ' ')); if (matcher.matches()) { String id = matcher.group(1); String price = matcher.group(2); log.info("updating order status for order ID '{}' with price: {}", id, price); statusMap.putIfAbsent(id, new ArrayList<String>()); if (price.contains(".")) { statusMap.get(id).add("taxed"); } else {/*w ww.jav a 2 s. com*/ statusMap.get(id).add("priced"); } } else { Matcher idMatcher = ID_ONLY_PATTERN.matcher(payload.replace('\n', ' ')); if (idMatcher.matches()) { String id = idMatcher.group(1); log.info("updating order status to 'accepted' for order ID '{}'", id); statusMap.putIfAbsent(id, new ArrayList<String>()); statusMap.get(id).add("accepted"); } } }
From source file:com.consol.citrus.samples.flightbooking.FlightRouter.java
@Router public Collection<MessageChannel> determineTargetChannels(Message<?> message) { FlightBookingRequestMessage request = (FlightBookingRequestMessage) message.getPayload(); return Collections.singletonList(airlineMappings.get(request.getFlight().getAirline())); }
From source file:apiserver.services.images.services.jhlabs.BlurFilterService.java
public Object doFilter(Message<?> message) { ImageDocumentJob props = (ImageDocumentJob) message.getPayload(); //Map headers = (Map) message.getHeaders(); try {/*from w ww .ja va2 s .c o m*/ //run filter BlurFilter filter = new BlurFilter(); BufferedImage bufferedImage = props.getBufferedImage(); if (bufferedImage == null) { throw new MessageConfigException(MessageConfigException.MISSING_PROPERTY); } BufferedImage outFile = filter.filter(bufferedImage, null); // add image into the payload, and return props.setBufferedImage(outFile); return message; } catch (Throwable e) { e.printStackTrace(); //log.error(e.getMessage(), e); throw new RuntimeException(e); } }
From source file:com.foo.bar.si.file.demo.starter.TransformationHandler.java
/** * Actual Spring Integration transformation handler. * * @param inputMessage Spring Integration input message * @return New Spring Integration message with updated headers *//* ww w.ja va 2 s . co m*/ @Transformer public Message<String> handleFile(final Message<File> inputMessage) { final File inputFile = inputMessage.getPayload(); final String filename = inputFile.getName(); final String fileExtension = FilenameUtils.getExtension(filename); final String inputAsString; try { inputAsString = FileUtils.readFileToString(inputFile); } catch (IOException e) { throw new IllegalStateException(e); } final Message<String> message = MessageBuilder.withPayload(inputAsString.toUpperCase(Locale.ENGLISH)) .setHeader(FileHeaders.FILENAME, filename).setHeader(FileHeaders.ORIGINAL_FILE, inputFile) .setHeader("file_size", inputFile.length()).setHeader("file_extension", fileExtension).build(); return message; }
From source file:com.acme.FeedConfigurationTest.java
@Test public void test() { applicationContext.start();//from w ww . ja v a2 s. co m Message message = output.receive(10000); assertNotNull(message); assertTrue(message.getPayload() instanceof String); }
From source file:org.opencredo.couchdb.transformer.CouchDbUrlToDocumentTransformer.java
@Override protected Object doTransform(Message<?> message) throws Exception { Object payload = message.getPayload(); URI uri = null;//from w w w . j a va 2s . c om if (payload instanceof String) { uri = new URI((String) payload); } else if (payload instanceof URI) { uri = (URI) payload; } else { throw new MessageTransformationException(message, "Cannot transform payload [" + payload + "] to a CouchDB document"); } return couchDbDocumentOperations.readDocument(uri, documentType); }
From source file:org.opencredo.couchdb.transformer.CouchDbIdToDocumentTransformer.java
@Override protected Object doTransform(Message<?> message) throws Exception { Object payload = message.getPayload(); String id = null;/*w ww . j ava 2s. c o m*/ if (payload instanceof String) { id = (String) payload; } else if (payload instanceof UUID) { id = payload.toString(); } else { throw new MessageTransformationException(message, "Cannot transform payload [" + payload + "] to a CouchDB document"); } return couchDbDocumentOperations.readDocument(id, documentType); }
From source file:com.consol.citrus.samples.greeting.AbstractMarshallingMessageService.java
/** * Unmarshal message payload.//from w w w. j a v a 2 s. co m * * @param message * @return */ @SuppressWarnings("unchecked") private Message<T> unmarshalMessage(Message<?> message) { T payload = (T) unmarshallingTransformer.transformPayload(message.getPayload()); MessageBuilder<T> builder = MessageBuilder.withPayload(payload).copyHeaders(message.getHeaders()); return builder.build(); }
From source file:org.thingsplode.server.bus.executors.AbstractRequestResponseExecutor.java
public Message<?> execute(Message<?> msg) { AbstractRequest req = (AbstractRequest) msg.getPayload(); try {//from w w w. j a v a 2s .c om RSP response = executeImpl((REQ) msg.getPayload(), msg.getHeaders(), getDeviceRepo().findByIdentification(req.getDeviceId())); if (response != null) { return MessageBuilder.withPayload(configureCommonFields(req, response)).build(); } else { return MessageBuilder .withPayload(configureCommonFields(req, new Response<>(req.getMessageId(), ExecutionStatus.DECLINED, ResponseCode.REQUIRED_RESPONSE_IS_MISSING, "return payload value is null"))) .build(); } } catch (SrvExecutionException ex) { logger.error(ex.getMessage(), ex); //msgTemplate.send(MessageBuilder.withPayload(new ErrorMessage(ex.getExecutionStatus(), ex.getResponseCode(), ex)).build()); return MessageBuilder.withPayload(configureCommonFields(req, new Response<>(req.getMessageId(), ex.getExecutionStatus(), ex.getResponseCode(), ex.getMessage()))).build(); } catch (Exception ex) { logger.error(ex.getMessage(), ex); //msgTemplate.send(MessageBuilder.withPayload(new ErrorMessage(ExecutionStatus.DECLINED, ResponseCode.INTERNAL_SYSTEM_ERROR, ex)).build()); return MessageBuilder .withPayload(configureCommonFields(req, new Response<>(req.getMessageId(), ExecutionStatus.DECLINED, determineResponseCode(ex), determineExceptionMessage(ex)))) .build(); } }