List of usage examples for org.springframework.messaging Message getPayload
T getPayload();
From source file:biz.c24.io.spring.integration.transformer.XPathTransformerIUTests.java
@Test public void canTransformToListOfString() throws Exception { C24XPathTransformer transformer = new C24XPathTransformer("//FirstName"); transformer.setEvaluationType(XPathEvaluationType.LIST_RESULT); Message<?> message = MessageBuilder.withPayload(loadObject()).build(); Message<?> outputMessage = transformer.transform(message); @SuppressWarnings("unchecked") List<String> payload = (List<String>) outputMessage.getPayload(); assertThat(payload, notNullValue()); assertThat(payload, hasItems("Andy", "Joe", "Greg")); }
From source file:biz.c24.io.spring.integration.transformer.IoTransformerIUTests.java
@Test public void canTransformToPojo() throws Exception { Employee employee = new Employee(); employee.setFirstName("Tom"); employee.setLastName("Smith"); employee.setJobTitle("Porter"); C24Transformer transformer = new C24Transformer(); transformer.setTransformClass(EmployeeToEmailTransform.class); Message<?> message = MessageBuilder.withPayload(employee).build(); Message<?> result = transformer.transform(message); assertNotNull(result);/* w w w. jav a 2 s. co m*/ assertThat(result.getPayload(), is(Email.class)); transformer.setTargetClass(MyEmail.class); result = transformer.transform(message); assertNotNull(result); assertThat(result.getPayload(), is(MyEmail.class)); MyEmail email = (MyEmail) result.getPayload(); assertThat(email.getFirstNameInitial(), is("T.")); assertThat(email.getSurname(), is("Smith")); assertThat(email.getDomainName(), is("@company.com")); }
From source file:apiserver.services.images.services.jhlabs.RaysFilterService.java
public Object doFilter(Message<?> message) throws MessageConfigException { RaysJob props = (RaysJob) message.getPayload(); //todo replace with real Model class float opacity = props.getOpacity(); float strength = props.getStrength(); float threshold = props.getThreshold(); float angle = props.getAngle(); float centerX = props.getCenterX(); float centerY = props.getCenterY(); float distance = props.getDistance(); float rotation = props.getRotation(); float zoom = props.getZoom(); boolean raysOnly = props.getRaysOnly(); String colorMapType = props.getColorMapType(); //gradient,grayscale,array,linear,spectrum,spline int[] gradientColors = props.getGradientColors(); int[] xKnots = props.getxKnots(); int[] yKnots = props.getyKnots(); int[] arrayColors = props.getArrayColors(); int linearColor1 = props.getLinearColor1(); int linearColor2 = props.getLinearColor2(); try {/*from w ww . java 2s . com*/ Colormap colorMap = null; if (colorMapType.equalsIgnoreCase("gradient")) { colorMap = new Gradient(gradientColors); } else if (colorMapType.equalsIgnoreCase("grayscale")) { colorMap = new GrayscaleColormap(); } else if (colorMapType.equalsIgnoreCase("array")) { colorMap = new ArrayColormap(arrayColors); } else if (colorMapType.equalsIgnoreCase("linear")) { colorMap = new LinearColormap(linearColor1, linearColor2); } else if (colorMapType.equalsIgnoreCase("spectrum")) { colorMap = new SpectrumColormap(); } else if (colorMapType.equalsIgnoreCase("spline")) { colorMap = new SplineColormap(xKnots, yKnots); } //run filter RaysFilter filter = new RaysFilter(); filter.setOpacity(opacity); filter.setRaysOnly(raysOnly); filter.setStrength(strength); filter.setThreshold(threshold); filter.setAngle(angle); filter.setCentreX(centerX); filter.setCentreY(centerY); filter.setDistance(distance); filter.setRotation(rotation); filter.setZoom(zoom); filter.setColormap(colorMap); BufferedImage bufferedImage = props.getBufferedImage(); BufferedImage outFile = filter.filter(bufferedImage, null); props.setBufferedImage(outFile); return props; } catch (Throwable e) { //log.error(e.getMessage(), e); throw new RuntimeException(e); } }
From source file:org.opencredo.couchdb.outbound.CouchDbSendingMessageHandler.java
@Override protected final void handleMessageInternal(Message<?> message) throws Exception { System.out.println(message.getHeaders().toString()); System.out.println(message.getPayload().toString()); String documentId = createDocumentId(message); if (logger.isDebugEnabled()) { logger.debug("sending message to CouchDB [" + message + "]"); }//from w ww . jav a 2 s. c o m couchDbDocumentOperations.writeDocument(documentId, message.getPayload(), message.getHeaders(), counter); }
From source file:apiserver.services.images.services.exiftool.ImageMetadataService.java
public Object metadataInfo(Message<?> message) { FileMetadataJob props = (FileMetadataJob) message.getPayload(); try {/*from ww w .j a v a 2s . co m*/ File CachedFile = props.getDocument().getFile(); Map metadataDirectories = new HashMap(); ETOperation op = new ETOperation(); //op.getTags("Filename","ImageWidth","ImageHeight","FNumber","ExposureTime","iso"); //op.addRawArgs( "-a", "-u", "-g" ); op.addRawArgs("-a", "-u", "-G1", "-t"); op.addImage(); // setup command and execute it (capture output) ArrayListOutputConsumer output = new ArrayListOutputConsumer(); ExiftoolCmd et = new ExiftoolCmd(); et.setOutputConsumer(output); et.run(op, CachedFile.getAbsolutePath()); ArrayList<String> cmdOutput = output.getOutput(); for (String tag : cmdOutput) { String[] _tag = tag.trim().split("\t"); //todo , not going to work. need to count spaces String _group = _tag[0].trim(); String _key = _tag[1].trim(); String _value = _tag[2].trim(); if (!metadataDirectories.containsKey(_group)) { metadataDirectories.put(_group, new HashMap()); } Map subMap = (Map) metadataDirectories.get(_group); subMap.put(_key, _value); } props.setMetadata(metadataDirectories); return message; } catch (Throwable e) { //URL location = coldfusion.runtime.NeoPageContext.class.getProtectionDomain().getCodeSource().getLocation(); //System.out.print(location); e.printStackTrace(); //todo use logging library throw new RuntimeException(e); } }
From source file:com.create.batch.integration.FileMessageToJobRequestTest.java
@Test public void testMessageFileToJobLaunchRequestConversion() { // given/*w w w .jav a 2 s . c o m*/ final Message<File> message = mock(Message.class); final File file = mock(File.class); when(file.getAbsolutePath()).thenReturn(PATH); when(message.getPayload()).thenReturn(file); final Instant timestamp = Instant.ofEpochSecond(TIMESTAMP); when(clock.instant()).thenReturn(timestamp); // when final JobLaunchRequest jobLaunchRequest = transformer.toRequest(message); // then assertThat(jobLaunchRequest.getJob(), is(job)); assertThat(jobLaunchRequest.getJobParameters().getLong(FileMessageToJobRequest.TIMESTAMP_PARAMETER), equalTo(TIMESTAMP)); assertThat(jobLaunchRequest.getJobParameters().getString(PARAMETER), equalTo(PATH)); }
From source file:com.example.common.MoneyJacksonAutoConfiguration.java
@Override public Object convertFromInternal(Message<?> message, Class<?> targetClass, Object conversionHint) { try {/*from w w w .j av a2 s .co m*/ Object payload = message.getPayload(); return mapper.writeValueAsString(payload); } catch (Exception e) { logger.error(e.getMessage(), e); return null; } }
From source file:apiserver.services.images.services.exiftool.ImageMetadataService.java
public Object metadataClear(Message<?> message) { FileMetadataJob props = (FileMetadataJob) message.getPayload(); try {/*from w ww. ja v a 2 s .co m*/ File file = props.getDocument().getFile(); Map metadataDirectories = new HashMap(); ETOperation op = new ETOperation(); //op.getTags("Filename","ImageWidth","ImageHeight","FNumber","ExposureTime","iso"); //op.addRawArgs( "-a", "-u", "-g" ); op.addRawArgs("-all= dst.jpg"); op.addImage(); // setup command and execute it (capture output) ArrayListOutputConsumer output = new ArrayListOutputConsumer(); ExiftoolCmd et = new ExiftoolCmd(); et.setOutputConsumer(output); et.run(op, file.getAbsolutePath()); ArrayList<String> cmdOutput = output.getOutput(); for (String tag : cmdOutput) { String[] _tag = tag.trim().split("\t"); //todo , not going to work. need to count spaces String _group = _tag[0].trim(); String _key = _tag[1].trim(); String _value = _tag[2].trim(); if (!metadataDirectories.containsKey(_group)) { metadataDirectories.put(_group, new HashMap()); } Map subMap = (Map) metadataDirectories.get(_group); subMap.put(_key, _value); } // send back // Could be a HashMap or a MultiValueMap Map payload = (Map) message.getPayload(); payload.putAll(metadataDirectories); Map cfData = new HashMap(); payload.put("ExifTool", cfData); return payload; } catch (Throwable e) { //URL location = coldfusion.runtime.NeoPageContext.class.getProtectionDomain().getCodeSource().getLocation(); //System.out.print(location); e.printStackTrace(); //todo use logging library throw new RuntimeException(e); } }
From source file:com.consol.citrus.samples.bookstore.BookStore.java
/** * Adds a book to the registry.// w w w. ja v a2s . c o m * @param request * @return */ public Message<AddBookResponseMessage> addBook(Message<AddBookRequestMessage> request) { AddBookResponseMessage response = new AddBookResponseMessage(); Book book = request.getPayload().getBook(); if (!bookStore.containsKey(book.getIsbn())) { book.setId(ids.incrementAndGet()); book.setRegistrationDate(Calendar.getInstance()); bookStore.put(book.getIsbn(), book); response.setSuccess(true); } else { throw new DuplicateIsbnException(request); } return MessageBuilder.withPayload(response).build(); }
From source file:multibinder.RabbitAndKafkaBinderApplicationTests.java
@Test public void messagingWorks() throws Exception { // passing connection arguments arguments to the embedded Kafka instance ConfigurableApplicationContext context = SpringApplication.run(MultibinderApplication.class, "--spring.cloud.stream.kafka.binder.brokers=" + kafkaEmbedded.getBrokersAsString(), "--spring.cloud.stream.kafka.binder.zkNodes=" + kafkaEmbedded.getZookeeperConnectionString(), "--spring.cloud.stream.bindings.output.producer.requiredGroups=" + this.randomGroup); DirectChannel dataProducer = new DirectChannel(); BinderFactory<?> binderFactory = context.getBean(BinderFactory.class); QueueChannel dataConsumer = new QueueChannel(); ((RabbitMessageChannelBinder) binderFactory.getBinder("rabbit")).bindConsumer("dataOut", this.randomGroup, dataConsumer, new ExtendedConsumerProperties<>(new RabbitConsumerProperties())); ((KafkaMessageChannelBinder) binderFactory.getBinder("kafka")).bindProducer("dataIn", dataProducer, new ExtendedProducerProperties<>(new KafkaProducerProperties())); String testPayload = "testFoo" + this.randomGroup; dataProducer.send(MessageBuilder.withPayload(testPayload).build()); Message<?> receive = dataConsumer.receive(10000); Assert.assertThat(receive, Matchers.notNullValue()); Assert.assertThat(receive.getPayload(), CoreMatchers.equalTo(testPayload)); context.close();/*from w ww .jav a2 s.c om*/ }