List of usage examples for org.springframework.integration.support MessageBuilder withPayload
public static <T> MessageBuilder<T> withPayload(T payload)
From source file:com.devnexus.ting.core.service.impl.BusinessServiceImpl.java
@Override public void resendRegistrationEmail(RegistrationDetails registerForm) { if (mailSettings.isEmailEnabled()) { registrationMailChannel.send(MessageBuilder.withPayload(registerForm).build()); }//from w w w . jav a2 s. c o m }
From source file:org.eclipse.hawkbit.repository.event.remote.AbstractRemoteEventTest.java
private Message<String> createJsonMessage(final Object event) { final Map<String, MimeType> headers = Maps.newLinkedHashMap(); headers.put(MessageHeaders.CONTENT_TYPE, MimeTypeUtils.APPLICATION_JSON); try {/*from w w w . j a va 2 s . c o m*/ final String json = new ObjectMapper().writeValueAsString(event); final Message<String> message = MessageBuilder.withPayload(json).copyHeaders(headers).build(); return message; } catch (final JsonProcessingException e) { fail(e.getMessage()); } return null; }
From source file:org.edgexfoundry.serviceactivator.IotCoreMQTTOutboundServiceActivatorTest.java
@Before public void setup() { activator = new IotCoreMQTTOutboundServiceActivator(); string = ExportStringData.newTestInstance(); string.setEventString(TEST_STRING);//from w ww . j a v a 2s . co m string.setEventId(TEST_ID); Addressable addressable = new Addressable(TEST_STRING, Protocol.OTHER, TEST_ADDRESS, TEST_PORT, TEST_PUBLISHER, TEST_USER, TEST_PASSWORD, TEST_TOPIC); ExportRegistration er = new ExportRegistration(); er.setAddressable(addressable); string.setRegistration(er, TEST_ID); message = MessageBuilder.withPayload(string).build(); try { FieldUtils.writeField(activator, "privateKeyFile", "rsa_private_pkcs8", true); FieldUtils.writeField(activator, "algorithm", "RS256", true); } catch (IllegalAccessException e) { e.printStackTrace(); } }
From source file:org.encuestame.core.rss.EnMeRssReader.java
public Message<String> receive() { log.debug("readRssFeed method is called"); return MessageBuilder.withPayload("test").setHeader("feedid", "thefeed").build(); }
From source file:org.opentestsystem.delivery.testreg.transformer.TarBundler.java
/** * Bundles the inputs into a tar which is returned as a byte stream. The input is an array of byte arrays in which * the first element is a filename and the second element is the actual file. Subsequent files follow this same * pattern. If there is an uneven number of elements then the last file will be ignored. * /*from ww w .j ava 2s.c om*/ * @param inputs * @return */ @Transformer public Message<File> bundleToTar(final String[] inputs, final @Header("dwBatchUuid") String dwBatchUuid, final @Header("fileSuffix") String fileSuffix, final @Header("recordsSent") int recordsSent, final @Header("tempPaths") List<Path> tempPaths, final @Header("dwConfigType") DwConfigType dwConfigType) { String debugPrefix = dwConfigType + " DW Config: "; long curTime = System.currentTimeMillis(); File tmpTarFile; FileOutputStream tmpTarOutStream; FileInputStream tmpCsvInStream; FileInputStream tmpJsonInStream; try { Path tmpTarPath = Files.createTempFile(DwBatchHandler.DW_TAR_TMP_PREFIX, (dwConfigType == DwConfigType.SBAC ? DwBatchHandler.SBAC_DW_NAME : DwBatchHandler.LOCAL_DW_NAME) + fileSuffix); tempPaths.add(tmpTarPath); tmpTarFile = tmpTarPath.toFile(); LOGGER.debug(debugPrefix + "Created temp TAR file " + tmpTarFile.getAbsolutePath()); tmpTarOutStream = new FileOutputStream(tmpTarFile); tmpCsvInStream = new FileInputStream(inputs[1]); tmpJsonInStream = new FileInputStream(inputs[4]); TarArchiveOutputStream tarOutput = new TarArchiveOutputStream(tmpTarOutStream); String csvFilename = inputs[0]; String jsonFilename = inputs[3]; // tar archive entry for the csv file TarArchiveEntry entry = new TarArchiveEntry(csvFilename); entry.setSize(Integer.valueOf(inputs[2])); tarOutput.putArchiveEntry(entry); byte[] buf = new byte[BUFFER_SIZE]; int len; while ((len = tmpCsvInStream.read(buf)) > 0) { tarOutput.write(buf, 0, len); } tarOutput.closeArchiveEntry(); // tar archive entry for the json file entry = new TarArchiveEntry(jsonFilename); entry.setSize(Integer.valueOf(inputs[5])); tarOutput.putArchiveEntry(entry); buf = new byte[BUFFER_SIZE]; while ((len = tmpJsonInStream.read(buf)) > 0) { tarOutput.write(buf, 0, len); } tarOutput.closeArchiveEntry(); tarOutput.close(); tmpCsvInStream.close(); tmpJsonInStream.close(); } catch (IOException e) { throw new TarBundlerException(debugPrefix + "failure to tar output streams", e); } LOGGER.debug(debugPrefix + "Created TAR output in " + (System.currentTimeMillis() - curTime)); return MessageBuilder.withPayload(tmpTarFile).setHeader("dwBatchUuid", dwBatchUuid) .setHeader("fileSuffix", fileSuffix).setHeader("recordsSent", recordsSent) .setHeader("tempPaths", tempPaths).setHeader("dwConfigType", dwConfigType).build(); }
From source file:org.springframework.batch.integration.samples.payments.PaymentChunkListener.java
@Override public void onReadError(Exception ex) { if (ex instanceof FlatFileParseException) { FlatFileParseException ffpe = (FlatFileParseException) ex; logger.error(String.format("Error reading data on line '%s' - data: '%s'", ffpe.getLineNumber(), ffpe.getInput()));/* w w w.jav a 2 s . c o m*/ } chunkNotificationsChannel.send(MessageBuilder.withPayload(new Notification(ex.getMessage(), true)).build()); }
From source file:org.springframework.cloud.stream.app.image.recognition.processor.ImageRecognitionOutputMessageBuilder.java
@Override public MessageBuilder<?> createOutputMessageBuilder(Message<?> inputMessage, Object computedScore) { Message<?> annotatedInput = inputMessage; if (this.drawLabels) { byte[] annotatedImage = drawLabels((byte[]) inputMessage.getPayload(), computedScore); annotatedInput = MessageBuilder.withPayload(annotatedImage).build(); }//w ww.j av a2 s . c o m return super.createOutputMessageBuilder(annotatedInput, computedScore); }
From source file:org.springframework.cloud.stream.app.object.detection.processor.ObjectDetectionOutputMessageBuilder.java
@Override public MessageBuilder<?> createOutputMessageBuilder(Message<?> inputMessage, Object computedScore) { Message<?> annotatedInput = inputMessage; List<ObjectDetection> objectDetections = (List<ObjectDetection>) computedScore; if (this.drawBoundingBox) { byte[] annotatedImage = drawBoundingBox((byte[]) inputMessage.getPayload(), objectDetections); annotatedInput = MessageBuilder.withPayload(annotatedImage).build(); }//w w w .ja va 2 s.c o m return super.createOutputMessageBuilder(annotatedInput, toJson(objectDetections)); }
From source file:org.springframework.cloud.stream.app.pose.estimation.processor.PoseEstimateOutputMessageBuilder.java
@Override public MessageBuilder<?> createOutputMessageBuilder(Message<?> inputMessage, Object computedScore) { Message<?> annotatedInput = inputMessage; List<Body> bodies = (List<Body>) computedScore; if (this.poseProperties.isDrawPoses()) { try {//from w w w.j a v a 2 s . co m byte[] annotatedImage = drawPoses((byte[]) inputMessage.getPayload(), bodies); annotatedInput = MessageBuilder.withPayload(annotatedImage).build(); } catch (IOException e) { logger.error("Failed to draw the poses", e); } } return super.createOutputMessageBuilder(annotatedInput, toJson(bodies)); }
From source file:org.springframework.cloud.stream.app.tensorflow.processor.TensorflowProcessorConfiguration.java
@ServiceActivator(inputChannel = Processor.INPUT, outputChannel = Processor.OUTPUT) public Message<?> evaluate(Message<?> input) { Map<String, Object> processorContext = new ConcurrentHashMap<>(); Map<String, Object> inputData = tensorflowInputConverter.convert(input, processorContext); Tensor outputTensor = tensorFlowService.evaluate(inputData, properties.getOutputName(), properties.getOutputIndex()); Object outputData = tensorflowOutputConverter.convert(outputTensor, processorContext); if (properties.isSaveOutputInHeader()) { // Add the result to the message header return MessageBuilder.withPayload(input.getPayload()).copyHeadersIfAbsent(input.getHeaders()) .setHeaderIfAbsent(TF_OUTPUT_HEADER, outputData).build(); }/*from www . j a va 2 s .c o m*/ // Add the outputData as part of the message payload Message<?> outputMessage = MessageBuilder.withPayload(outputData).copyHeadersIfAbsent(input.getHeaders()) .build(); return outputMessage; }