List of usage examples for org.springframework.integration.support MessageBuilder withPayload
public static <T> MessageBuilder<T> withPayload(T payload)
From source file:org.synyx.hera.si.PluginRegistryAwareMessageHandlerUnitTest.java
@Test(expected = MessageHandlingException.class) public void failsHandlingMessageIfDelimiterTypeDoesNotMatch() { Message<String> message = MessageBuilder.withPayload("FOO").build(); handler.handleMessage(message);//from w ww .jav a 2 s . c o m }
From source file:integration.ZipkinStreamTests.java
private Message<Spans> messageWithSpan(Span span) { return MessageBuilder .withPayload(new Spans(new Host(getAppName(), "127.0.0.1", 8080), Collections.singletonList(span))) .build();/*from w w w .j av a2s. c om*/ }
From source file:biz.c24.io.spring.integration.config.FileSplitterTests.java
@Test public void splitOnEvens() throws Exception { transformer.setInitiator("^-?\\d*[02468]$"); Boolean result = (Boolean) transformer .doTransform(MessageBuilder.withPayload((resource.getFile())).build()); Message<List<String>> message; int messageCount = 0; for (int i = 0; i < 5; i++) { message = (Message<List<String>>) feedChannel.receive(); if (i < 4) { assertThat(message.getPayload().get(0), is((i + 1) * 2 + "" + ((i + 1) * 2 + 1))); } else {/*from w ww . ja va2 s . c om*/ assertThat(message.getPayload().get(0), is("10")); } messageCount++; } assertThat(messageCount, is(5)); }
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);/*from w ww. j av a 2s .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: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:com.apress.prospringintegration.customadapters.inbound.pollerdriven.StockPollingMessageSource.java
@Override public Message<Stock> receive() { Stock stock = getStockInformationFor(this.tickerSymbol); if (stock == null) { return null; }/*ww w. j a va 2s. c o m*/ return MessageBuilder.withPayload(stock).setHeader("symbol", this.tickerSymbol) .setHeader("price", stock.getPrice()).build(); }
From source file:com.devnexus.ting.core.service.impl.MailSendingTest.java
@Test public void sendCfpEmail() throws InterruptedException { Assert.assertTrue(environment.acceptsProfiles(SpringProfile.MAIL_ENABLED)); final CfpSubmissionSpeaker cfpSubmissionSpeaker = new CfpSubmissionSpeaker(); final CfpSubmission cfpSubmission = new CfpSubmission(); cfpSubmissionSpeaker.getCfpSubmissions().add(cfpSubmission); cfpSubmissionSpeaker.setBio("This is my great **bio**."); cfpSubmissionSpeaker.setEmail("speaker@devnexus.com"); cfpSubmissionSpeaker.setFirstName("firstName"); cfpSubmissionSpeaker.setGooglePlusId("googlePlusId"); cfpSubmissionSpeaker.setLastName("Cartman"); cfpSubmissionSpeaker.setLinkedInId("linkedInId"); cfpSubmissionSpeaker.setPhone("555-555-5555"); cfpSubmissionSpeaker.setTshirtSize("XXXXL"); cfpSubmissionSpeaker.setTwitterId("twitterId"); cfpSubmissionSpeaker.setEmail("xaymaca@gmail.com"); cfpSubmission.getCfpSubmissionSpeakers().add(cfpSubmissionSpeaker); cfpSubmission.setDescription("My *abstract* rocks!"); cfpSubmission.setPresentationType(PresentationType.BREAKOUT); cfpSubmission.setSessionRecordingApproved(true); cfpSubmission.setSkillLevel(SkillLevel.INTERMEDIATE); cfpSubmission.setSlotPreference("Second day only"); cfpSubmission.setTitle("My title"); mailChannel.send(MessageBuilder.withPayload(cfpSubmission).build()); Thread.sleep(2000);/* w ww. ja v a 2s .c o m*/ }
From source file:biz.c24.io.spring.integration.selectors.ValidatingMessageSelectorTests.java
@Test public void testInvalid() { Employee employee = new Employee(); employee.setSalutation("Mr"); // Should fail due to non-capitalised first letter employee.setFirstName("andy"); employee.setLastName("Acheson"); // No job title set - should also cause a validation failure //employee.setJobTitle("Software Developer"); C24ValidatingMessageSelector selector = new C24ValidatingMessageSelector(); selector.setFailFast(true);/*from www. j ava2 s.c om*/ selector.setThrowExceptionOnRejection(false); assertThat(selector.accept(MessageBuilder.withPayload(employee).build()), is(false)); selector.setFailFast(false); assertThat(selector.accept(MessageBuilder.withPayload(employee).build()), is(false)); selector.setFailFast(true); selector.setThrowExceptionOnRejection(true); try { selector.accept(MessageBuilder.withPayload(employee).build()); fail("Selector failed to throw an exception on invalid CDO"); } catch (MessageRejectedException ex) { // Expected behaviour assertThat(ex.getCause(), is(ValidationException.class)); } selector.setFailFast(false); try { selector.accept(MessageBuilder.withPayload(employee).build()); fail("Selector failed to throw an exception on invalid CDO"); } catch (C24AggregatedMessageValidationException ex) { // Expected behaviour ListIterator<ValidationEvent> failures = ex.getFailEvents(); int failureCount = 0; while (failures.hasNext()) { failureCount++; failures.next(); } assertThat(failureCount, is(2)); } }
From source file:com.googlecode.msidor.springframework.integration.system.ShutdownHandler.java
/** * Handles application shutdown// w w w .j a v a 2 s. c o m */ public void shutdownGently() { long startTimestamp = System.currentTimeMillis(); log.info("Shuting down the application..."); if (componentsToShutDown != null) { Assert.notNull(operationChannel, "Operation channel must be set"); for (String component : componentsToShutDown) { log.info("Sending shutdown command to component: ".concat(component)); Message<String> operation = MessageBuilder.withPayload("@" + component + ".stop()").build(); operationChannel.send(operation); } } if (executorsToWatch != null) { log.info("Checking if all executor threads have been accomplished..."); boolean allDone = true; do { allDone = true; for (ThreadPoolTaskExecutor executor : executorsToWatch) { allDone = allDone && executor.getActiveCount() == 0; } } while (!allDone && !Thread.interrupted() && ((timeout > 0 && System.currentTimeMillis() - startTimestamp < timeout) || timeout <= 0)); if (allDone) log.info("No more active threads"); else log.warn("Some threads are still working"); } okToShutdown = true; if (shutodwnApplication) { System.exit(systemExitCode); } }