List of usage examples for org.springframework.integration.support MessageBuilder withPayload
public static <T> MessageBuilder<T> withPayload(T payload)
From source file:net.nan21.dnet.core.business.service.AbstractBusinessBaseService.java
protected void sendMessage(String to, Object content) { Message<Object> message = MessageBuilder.withPayload(content).build(); this.getApplicationContext().getBean(to, MessageChannel.class).send(message); }
From source file:com.devnexus.ting.web.controller.admin.AcceptCfpController.java
@RequestMapping(value = "/s/admin/{eventKey}/cfps/{cfpId}/accept", method = RequestMethod.POST) public String acceptCfp(@PathVariable("eventKey") String eventKey, @PathVariable("cfpId") Long cfpId, CfpSubmission cfpSubmission, BindingResult result, HttpServletRequest request) { if (request.getParameter("cancel") != null) { return "redirect:/s/admin/{eventKey}/cfps#cfp_{cfpId}"; }//from www .ja v a 2s .c om if (result.hasErrors()) { return "/admin/accept-cfp"; } final Long cfpSubmissionId = cfpSubmission.getId(); final CfpSubmission cfpSubmissionFromDb = businessService.getCfpSubmission(cfpSubmissionId); final Event currentEvent = businessService.getCurrentEvent(); LOGGER.info("Setting up CFP Submission " + cfpSubmissionId); //First we need to setup the speaker (s) final List<Speaker> updatedSpeakers = new ArrayList<Speaker>(1); for (CfpSubmissionSpeaker cfpSubmissionSpeaker : cfpSubmissionFromDb.getCfpSubmissionSpeakers()) { final Long existingSpeakerId = cfpSubmission.getSpeakerIdForCfpSpeakerId(cfpSubmissionSpeaker.getId()); Assert.notNull(existingSpeakerId, "Speaker ID Must not be null."); final Speaker speaker; if (Long.valueOf(-1L).equals(existingSpeakerId)) { LOGGER.info(String.format("Adding new speaker for CFP Submission ID '%s'", cfpSubmissionId)); speaker = new Speaker(); speaker.setFirstName(cfpSubmissionSpeaker.getFirstName()); speaker.setLastName(cfpSubmissionSpeaker.getLastName()); } else { LOGGER.info(String.format("Reusing existing speaker id '%s' " + "for CFP Submission ID '%s'", existingSpeakerId, cfpSubmissionId)); speaker = businessService.getSpeaker(existingSpeakerId); LOGGER.info(String.format("Updating existing speaker '%s'.", speaker.getFirstLastName())); } speaker.setCompany(cfpSubmissionSpeaker.getCompany()); speaker.setBio(cfpSubmissionSpeaker.getBio()); speaker.setGithubId(cfpSubmissionSpeaker.getGithubId()); speaker.setGooglePlusId(cfpSubmissionSpeaker.getGooglePlusId()); speaker.setLanyrdId(cfpSubmissionSpeaker.getLanyrdId()); speaker.setLinkedInId(cfpSubmissionSpeaker.getLinkedInId()); speaker.setTwitterId(cfpSubmissionSpeaker.getTwitterId()); speaker.setCfpSpeakerId(cfpSubmissionSpeaker.getId()); final Speaker updatedSpeaker = businessService.saveSpeakerAndAddToEventIfNecessary(speaker); updatedSpeakers.add(updatedSpeaker); } LOGGER.info(String.format("Adding Presentation '%s'.", cfpSubmissionFromDb.getTitle())); final Presentation presentation = new Presentation(); presentation.setCfpId(cfpSubmissionFromDb.getId()); presentation.setDescription(cfpSubmissionFromDb.getDescription()); presentation.setEvent(currentEvent); final Set<PresentationTag> presentationTags = businessService .processPresentationTags(cfpSubmissionFromDb.getTopic()); presentation.setPresentationTags(presentationTags); presentation.setPresentationType(cfpSubmissionFromDb.getPresentationType()); presentation.setSkillLevel(cfpSubmissionFromDb.getSkillLevel()); presentation.setTitle(cfpSubmissionFromDb.getTitle()); presentation.setSpeakers(updatedSpeakers); final Presentation savedPresentation = businessService.savePresentation(presentation); LOGGER.info(String.format("Presentation added with id '%s'.", savedPresentation.getId())); cfpSubmissionFromDb.setStatus(CfpSubmissionStatusType.ACCEPTED); final CfpSubmission acceptedCfpSubmission = businessService.saveCfpSubmission(cfpSubmissionFromDb); if (mailSettings.isEmailEnabled()) { acceptedSessionMailChannel.send(MessageBuilder.withPayload(acceptedCfpSubmission).build()); } //FlashMap.setSuccessMessage("The speaker was edited successfully."); return "redirect:/s/admin/{eventKey}/cfps"; }
From source file:com.opensourceagility.springintegration.alerts.AlertsIntegrationTest.java
/** * Creates 100 alerts with ids 1..100 in order...incrementing the persist time by 1 second for each * Each Alert with an odd id is given an urgency of (id + 1)/2... so urgency of 1 through 50 * Each Alert with an even id is given an urgency of (50 + id/2)..so urgency of 51 through 100 * // w w w . j a va 2 s.c o m * @param createAlertChannel The alert channel responsible for persisting alerts * @param thisMinute Date representing the start of the current minute * @throws ParseException */ private void createAlertTestData(MessageChannel createAlertChannel, Date thisMinute) throws ParseException { LOGGER.debug("Creating 100 Alerts in database for this test"); Calendar insertTime = Calendar.getInstance(); insertTime.setTime(thisMinute); for (int id = 1; id <= 100; id++) { int urgency = id % 2 == 1 ? (id + 1) / 2 : (50 + id / 2); Alert alert = createTestAlert(id, urgency, insertTime.getTime()); createAlertChannel.send(MessageBuilder.withPayload(alert).build()); String csvDate = csvDateFormat.format(alert.getPersistDate()); expectedXmlTimeStringsByAlertId.put(id, xmlDateFormat.format(alert.getPersistDate())); expectedCsvTimeStringsByAlertId.put(id, csvDate); insertTime.add(Calendar.SECOND, 1); } }
From source file:org.springframework.integration.aws.outbound.S3MessageHandlerTests.java
@Test public void testUploadInputStream() throws IOException { InputStream payload = new StringInputStream("a"); Message<?> message = MessageBuilder.withPayload(payload) .setHeader("s3Command", S3MessageHandler.Command.UPLOAD.name()).setHeader("key", "myStream") .build();// w w w . java2 s. co m this.s3SendChannel.send(message); ArgumentCaptor<PutObjectRequest> putObjectRequestArgumentCaptor = ArgumentCaptor .forClass(PutObjectRequest.class); verify(this.amazonS3, atLeastOnce()).putObject(putObjectRequestArgumentCaptor.capture()); PutObjectRequest putObjectRequest = putObjectRequestArgumentCaptor.getValue(); assertThat(putObjectRequest.getBucketName()).isEqualTo("myBucket"); assertThat(putObjectRequest.getKey()).isEqualTo("myStream"); assertThat(putObjectRequest.getFile()).isNull(); assertThat(putObjectRequest.getInputStream()).isNotNull(); ObjectMetadata metadata = putObjectRequest.getMetadata(); assertThat(metadata.getContentMD5()).isEqualTo(Md5Utils.md5AsBase64(payload)); assertThat(metadata.getContentLength()).isEqualTo(1); assertThat(metadata.getContentType()).isEqualTo(MediaType.APPLICATION_JSON_VALUE); assertThat(metadata.getContentDisposition()).isEqualTo("test.json"); }
From source file:org.springframework.integration.aws.outbound.S3MessageHandlerTests.java
@Test public void testDownloadDirectory() throws IOException { File directoryForDownload = this.temporaryFolder.newFolder("myFolder"); Message<?> message = MessageBuilder.withPayload(directoryForDownload) .setHeader("s3Command", S3MessageHandler.Command.DOWNLOAD).build(); this.s3SendChannel.send(message); File[] fileArray = directoryForDownload.listFiles(); assertThat(fileArray).isNotNull();/*from ww w . ja va 2s .co m*/ assertThat(fileArray.length).isEqualTo(2); List<File> files = Arrays.asList(fileArray); Collections.sort(files, (o1, o2) -> o1.getName().compareTo(o2.getName())); File file1 = files.get(0); assertThat(file1.getName()).isEqualTo("bar"); assertThat(FileCopyUtils.copyToString(new FileReader(file1))).isEqualTo("bb"); File file2 = files.get(1); assertThat(file2.getName()).isEqualTo("foo"); assertThat(FileCopyUtils.copyToString(new FileReader(file2))).isEqualTo("f"); }
From source file:net.nan21.dnet.core.business.service.entity.AbstractEntityWriteService.java
/** * Fire an entity specific event/*www . j av a 2s. co m*/ * * @param eventData */ protected void fireEvent(IMessageData eventData) { Message<IMessageData> message = MessageBuilder.withPayload(eventData).build(); this.getApplicationContext() .getBean(this.getEntityClass().getSimpleName() + "EventChannel", MessageChannel.class) .send(message); }
From source file:net.nan21.dnet.core.business.service.entity.AbstractEntityWriteService.java
/** * Fire an event with the specified action and data-map. * // w w w. ja va 2 s . co m * @param action * @param data */ protected void fireEvent(String action, Map<String, Object> data) { IMessageData eventData = new MessageData(this.getEntityClass().getCanonicalName(), action, data); Message<IMessageData> message = MessageBuilder.withPayload(eventData).build(); this.getApplicationContext() .getBean(this.getEntityClass().getSimpleName() + "EventChannel", MessageChannel.class) .send(message); }
From source file:com.acmemotors.filter.DataFilterTests.java
private void testScript(String payload, boolean result) throws IOException { assertEquals(result, processor.processMessage(MessageBuilder.withPayload(payload).build())); }
From source file:com.devnexus.ting.core.service.impl.BusinessServiceImpl.java
@Override public CfpSubmission saveAndNotifyCfpSubmission(final CfpSubmission cfpSubmission) { final BusinessService businessService = this; final CfpSubmission savedCfpSubmission = transactionTemplate .execute(new TransactionCallback<CfpSubmission>() { public CfpSubmission doInTransaction(TransactionStatus status) { return businessService.saveCfpSubmission(cfpSubmission); }//from ww w . j a va2 s.c o m }); if (mailSettings.isEmailEnabled()) { mailChannel.send(MessageBuilder.withPayload(cfpSubmission).build()); } return savedCfpSubmission; }
From source file:com.devnexus.ting.core.service.impl.BusinessServiceImpl.java
@Override @Transactional/*from ww w . ja v a 2 s .co m*/ public void saveAndEmailPaidRegistration(RegistrationDetails registerForm, PayPalPayment payment) { registrationDao.saveAndFlush(registerForm); payPalDao.saveAndFlush(payment); if (mailSettings.isEmailEnabled()) { registrationMailChannel.send(MessageBuilder.withPayload(registerForm).build()); } }