org.springframework.integration.file.FileHeaders Java Examples
The following examples show how to use
org.springframework.integration.file.FileHeaders.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: GcsStreamingMessageSourceTests.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
@Test public void testInboundStreamingChannelAdapter() { Message<?> message = this.unsortedChannel.receive(5000); assertThat(message).isNotNull(); assertThat(message.getPayload()).isInstanceOf(InputStream.class); assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("gamma"); message = this.unsortedChannel.receive(5000); assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("beta"); assertThat(message.getPayload()).isInstanceOf(InputStream.class); message = this.unsortedChannel.receive(5000); assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("alpha/alpha"); assertThat(message.getPayload()).isInstanceOf(InputStream.class); message = this.unsortedChannel.receive(10); assertThat(message).isNull(); }
Example #2
Source File: GcsStreamingMessageSourceTests.java From spring-cloud-gcp with Apache License 2.0 | 6 votes |
@Test public void testSortedInboundChannelAdapter() { // This uses the channel adapter with a custom comparator. // Files will be processed in ascending order by name: alpha/alpha, beta, gamma Message<?> message = this.sortedChannel.receive(5000); assertThat(message).isNotNull(); assertThat(message.getPayload()).isInstanceOf(InputStream.class); assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("alpha/alpha"); message = this.sortedChannel.receive(5000); assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("beta"); assertThat(message.getPayload()).isInstanceOf(InputStream.class); message = this.sortedChannel.receive(5000); assertThat(message.getHeaders().get(FileHeaders.REMOTE_FILE)).isEqualTo("gamma"); assertThat(message.getPayload()).isInstanceOf(InputStream.class); message = this.sortedChannel.receive(10); assertThat(message).isNull(); }
Example #3
Source File: FinishedFileFlowConfiguration.java From messaging with Apache License 2.0 | 6 votes |
@Bean IntegrationFlow finishedJobsFlow(BatchChannels channels, @Value("${completed-directory:${HOME}/Desktop/completed}") File finished, JdbcTemplate jdbcTemplate) { return IntegrationFlows .from(channels.completed()) .handle(JobExecution.class, (je, headers) -> { String ogFileName = String.class.cast(headers .get(FileHeaders.ORIGINAL_FILE)); File file = new File(ogFileName); mv(file, finished); List<Contact> contacts = jdbcTemplate.query( "select * from CONTACT", (rs, i) -> new Contact( rs.getBoolean("valid_email"), rs.getString("full_name"), rs.getString("email"), rs.getLong("id"))); contacts.forEach(log::info); return null; }).get(); }
Example #4
Source File: AmazonS3SourceMockTests.java From spring-cloud-stream-app-starters with Apache License 2.0 | 6 votes |
@Test @Override public void test() throws Exception { BlockingQueue<Message<?>> messages = this.messageCollector.forChannel(this.channels.output()); Message<?> received = messages.poll(10, TimeUnit.SECONDS); assertNotNull(received); assertThat(received, hasPayload("Other")); assertThat(received, hasHeader(FileHeaders.ORIGINAL_FILE, new File(this.config.getLocalDir(), "otherFile"))); received = messages.poll(10, TimeUnit.SECONDS); assertNotNull(received); assertThat(received, hasPayload("Other2")); assertNull(messages.poll(10, TimeUnit.MILLISECONDS)); assertEquals(1, this.config.getLocalDir().list().length); }
Example #5
Source File: InvalidFileFlowConfiguration.java From messaging with Apache License 2.0 | 5 votes |
@Bean IntegrationFlow invalidFileFlow(BatchChannels channels, @Value("${error-directory:${HOME}/Desktop/errors}") File errors) { return IntegrationFlows .from(channels.invalid()) .handle(JobExecution.class, (je, headers) -> { String ogFileName = String.class.cast(headers .get(FileHeaders.ORIGINAL_FILE)); File file = new File(ogFileName); mv(file, errors); return null; }).get(); }
Example #6
Source File: SpringCloudStreamAwsApplicationsITCase.java From spring-cloud-stream-app-starters with Apache License 2.0 | 5 votes |
@Test public void testS3Source() throws IOException, InterruptedException { String bucket = "TestBucket"; String key = "foo"; String content = "Spring Cloud Stream AWS S3 Source test"; this.applicationContext = SpringApplication.run(S3SourceBootConfiguration.class, "--s3.remoteDir=" + bucket, "--file.consumer.mode=lines", "--file.consumer.with-markers=false"); ResourceIdResolver resourceIdResolver = this.applicationContext.getBean(ResourceIdResolver.class); AmazonS3 amazonS3 = this.applicationContext.getBean(AmazonS3.class); ObjectMetadata objectMetadata = new ObjectMetadata(); objectMetadata.setContentLength(content.length()); String bucketName = resourceIdResolver.resolveToPhysicalResourceId(bucket); amazonS3.putObject(bucketName, key, new ByteArrayInputStream(content.getBytes("UTF-8")), objectMetadata); try { Source source = this.applicationContext.getBean(Source.class); MessageCollector messageCollector = this.applicationContext.getBean(MessageCollector.class); Message<?> received = messageCollector.forChannel(source.output()).poll(10, TimeUnit.SECONDS); assertNotNull(received); assertThat(received, hasHeader(FileHeaders.FILENAME, key)); assertThat(received, hasPayload("Spring Cloud Stream AWS S3 Source test")); } finally { amazonS3.deleteObject(bucketName, key); } }
Example #7
Source File: FileWriterGateway.java From spring-in-action-5-samples with Apache License 2.0 | 4 votes |
void writeToFile( @Header(FileHeaders.FILENAME) String filename, String data);