List of usage examples for org.springframework.integration.file FileHeaders FILENAME
String FILENAME
To view the source code for org.springframework.integration.file FileHeaders FILENAME.
Click Source Link
From source file:org.works.message.gateway.VoidGateway.java
public void process(String thing, @Header(FileHeaders.FILENAME) String fileName);
From source file:mx.uaq.facturacion.enlace.EmailSplitter.java
@Splitter public List<Message<?>> splitIntoMessages(final List<EmailFragment> emailFragments) { final List<Message<?>> messages = new ArrayList<Message<?>>(); for (EmailFragment emailFragment : emailFragments) { Message<?> message = MessageBuilder.withPayload(emailFragment.getData()) .setHeader(FileHeaders.FILENAME, emailFragment.getFilename()) .setHeader("directory", emailFragment.getDirectory()).build(); messages.add(message);/*from w w w . j av a 2 s .c o m*/ } return messages; }
From source file:com.japp.FileCompressor.java
/** * Actual Spring Integration transformation handler. * * @param inputMessage Spring Integration input message * @return New Spring Integration message with updated headers *//* ww w .jav a2s .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.excelsiorsoft.transformer.TransformationHandler.java
/** * Actual Spring Integration transformation handler. * * @param inputMessage Spring Integration input message * @return New Spring Integration message with updated headers *//* w w w . j a v a2 s . c o m*/ @Transformer public Message<byte[]> handleFile(final Message<File> inputMessage) { final File inputFile = inputMessage.getPayload(); final String filename = inputFile.getName(); final String inputAsString; try { inputAsString = FileUtils.readFileToString(inputFile); } catch (IOException e) { throw new IllegalStateException(e); } ByteArrayOutputStream bout = new ByteArrayOutputStream(); Workbook wb = new HSSFWorkbook(); Sheet sheet = wb.createSheet("Sample Sheet"); // Create a row and put some cells in it. Rows are 0 based. Row row = sheet.createRow((short) 0); // Create a cell and put a value in it. Cell cell = row.createCell(0); cell.setCellValue(inputAsString); try { wb.write(bout); } catch (IOException e) { throw new IllegalStateException(e); } final Message<byte[]> message = MessageBuilder.withPayload(bout.toByteArray()) .setHeader(FileHeaders.FILENAME, filename + ".xls").setHeader(FileHeaders.ORIGINAL_FILE, inputFile) .setHeader("file_size", inputFile.length()).build(); return message; }
From source file:au.edu.uws.eresearch.cr8it.TransformationHandler.java
/** * Actual Spring Integration transformation handler. * * @param inputMessage Spring Integration input message * @return New Spring Integration message with updated headers *///from w ww .j av a 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); //populate this with json-ld data final String inputAsString; String finalString = ""; if ("zip".equals(fileExtension)) { inputAsString = getJsonData(inputFile, FilenameUtils.getName(filename)); try { finalString = getJsonMapping(inputAsString); } catch (IOException | ParseException e) { e.printStackTrace(); } if (finalString.length() > 0) { final Message<String> message = MessageBuilder.withPayload(finalString) .setHeader(FileHeaders.FILENAME, FilenameUtils.getBaseName(filename) + ".json") .setHeader(FileHeaders.ORIGINAL_FILE, inputFile) .setHeader("file_size", finalString.length()).setHeader("file_extension", "json").build(); return message; } else { System.out.println("Empty json string."); return null; } } else { System.out.println("Invalid file format"); return null; } }
From source file:org.springintegration.demo.service.EmailTransformer.java
public void handleMultipart(Multipart multipart, javax.mail.Message mailMessage, List<Message<?>> messages) { final int count; try {//ww w .j ava 2 s. c o m count = multipart.getCount(); } catch (MessagingException e) { throw new IllegalStateException("Error while retrieving the number of enclosed BodyPart objects.", e); } for (int i = 0; i < count; i++) { final BodyPart bp; try { bp = multipart.getBodyPart(i); } catch (MessagingException e) { throw new IllegalStateException("Error while retrieving body part.", e); } final String contentType; final String filename; final String disposition; final String subject; try { contentType = bp.getContentType(); filename = bp.getFileName(); disposition = bp.getDisposition(); subject = mailMessage.getSubject(); } catch (MessagingException e) { throw new IllegalStateException("Unable to retrieve body part meta data.", e); } if (Part.ATTACHMENT.equalsIgnoreCase(disposition)) { LOGGER.info("Handdling attachment '{}', type: '{}'", filename, contentType); } final Object content; try { content = bp.getContent(); } catch (IOException e) { throw new IllegalStateException("Error while retrieving the email contents.", e); } catch (MessagingException e) { throw new IllegalStateException("Error while retrieving the email contents.", e); } if (content instanceof String) { final Message<String> message = MessageBuilder.withPayload((String) content) .setHeader(FileHeaders.FILENAME, subject + ".txt").build(); messages.add(message); } else if (content instanceof InputStream) { InputStream inputStream = (InputStream) content; ByteArrayOutputStream bis = new ByteArrayOutputStream(); try { IOUtils.copy(inputStream, bis); } catch (IOException e) { throw new IllegalStateException( "Error while copying input stream to the ByteArrayOutputStream.", e); } Message<byte[]> message = MessageBuilder.withPayload((bis.toByteArray())) .setHeader(FileHeaders.FILENAME, filename).build(); messages.add(message); } else if (content instanceof javax.mail.Message) { handleMessage((javax.mail.Message) content, messages); } else if (content instanceof Multipart) { Multipart mp2 = (Multipart) content; handleMultipart(mp2, mailMessage, messages); } else { throw new IllegalStateException("Content type not handled: " + content.getClass().getSimpleName()); } } }
From source file:org.springframework.integration.dsl.test.ftp.FtpTests.java
@Test public void testFtpOutboundFlow() { String fileName = "foo.file"; this.toFtpChannel.send(MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, fileName).build()); RemoteFileTemplate<FTPFile> template = new RemoteFileTemplate<>(this.ftpSessionFactory); FTPFile[] files = template.execute(//from w ww . j a v a2 s.c o m session -> session.list(this.ftpServer.getTargetFtpDirectory().getName() + "/" + fileName)); assertEquals(1, files.length); assertEquals(3, files[0].getSize()); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testFileHandler() throws Exception { Message<?> message = MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, "foo").build(); try {// w ww . java2s . c o m this.fileFlow1Input.send(message); fail("NullPointerException expected"); } catch (Exception e) { assertThat(e, instanceOf(MessageHandlingException.class)); assertThat(e.getCause(), instanceOf(NullPointerException.class)); } DefaultFileNameGenerator fileNameGenerator = new DefaultFileNameGenerator(); fileNameGenerator.setBeanFactory(this.beanFactory); Object targetFileWritingMessageHandler = this.fileWritingMessageHandler; if (this.fileWritingMessageHandler instanceof Advised) { TargetSource targetSource = ((Advised) this.fileWritingMessageHandler).getTargetSource(); if (targetSource != null) { targetFileWritingMessageHandler = targetSource.getTarget(); } } DirectFieldAccessor dfa = new DirectFieldAccessor(targetFileWritingMessageHandler); dfa.setPropertyValue("fileNameGenerator", fileNameGenerator); this.fileFlow1Input.send(message); assertTrue(new java.io.File(tmpDir, "foo").exists()); }
From source file:org.springframework.integration.dsl.test.IntegrationFlowTests.java
@Test public void testSftpOutboundFlow() { String fileName = "foo.file"; this.toSftpChannel .send(MessageBuilder.withPayload("foo").setHeader(FileHeaders.FILENAME, fileName).build()); RemoteFileTemplate<ChannelSftp.LsEntry> template = new RemoteFileTemplate<>(this.sftpSessionFactory); ChannelSftp.LsEntry[] files = template.execute( session -> session.list(this.sftpServer.getTargetSftpDirectory().getName() + "/" + fileName)); assertEquals(1, files.length);// w w w . j a v a 2 s . c o m assertEquals(3, files[0].getAttrs().getSize()); }
From source file:org.springframework.integration.file.FileWritingMessageHandlerTests.java
@Test public void testFileNameHeader() throws Exception { Message<?> message = MessageBuilder.withPayload(SAMPLE_CONTENT) .setHeader(FileHeaders.FILENAME, "dir1" + File.separator + "dir2/test").build(); QueueChannel output = new QueueChannel(); handler.setCharset(DEFAULT_ENCODING); handler.setOutputChannel(output);//from ww w . jav a 2s. c o m handler.handleMessage(message); Message<?> result = output.receive(0); assertFileContentIsMatching(result); File destFile = (File) result.getPayload(); assertThat(destFile.getAbsolutePath(), containsString(TestUtils.applySystemFileSeparator("/dir1/dir2/test"))); }