Search in sources :

Example 1 with FileWritingMessageHandler

use of org.springframework.integration.file.FileWritingMessageHandler in project spring-integration by spring-projects.

the class FileOutboundGatewayParserTests method checkOrderedGateway.

@Test
public void checkOrderedGateway() throws Exception {
    DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(ordered);
    FileWritingMessageHandler handler = (FileWritingMessageHandler) gatewayAccessor.getPropertyValue("handler");
    assertEquals(Boolean.FALSE, gatewayAccessor.getPropertyValue("autoStartup"));
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    assertEquals(777, handlerAccessor.getPropertyValue("order"));
    assertEquals(Boolean.TRUE, handlerAccessor.getPropertyValue("requiresReply"));
    DefaultFileNameGenerator fileNameGenerator = (DefaultFileNameGenerator) handlerAccessor.getPropertyValue("fileNameGenerator");
    assertNotNull(fileNameGenerator);
    Expression expression = TestUtils.getPropertyValue(fileNameGenerator, "expression", Expression.class);
    assertNotNull(expression);
    assertEquals("'foo.txt'", expression.getExpressionString());
    Long sendTimeout = TestUtils.getPropertyValue(handler, "messagingTemplate.sendTimeout", Long.class);
    assertEquals(Long.valueOf(777), sendTimeout);
}
Also used : Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) FileWritingMessageHandler(org.springframework.integration.file.FileWritingMessageHandler) DefaultFileNameGenerator(org.springframework.integration.file.DefaultFileNameGenerator) Test(org.junit.Test)

Example 2 with FileWritingMessageHandler

use of org.springframework.integration.file.FileWritingMessageHandler in project spring-integration by spring-projects.

the class FileOutboundGatewayParserTests method testOutboundGatewayWithDirectoryExpression.

@Test
public void testOutboundGatewayWithDirectoryExpression() throws Exception {
    FileWritingMessageHandler handler = TestUtils.getPropertyValue(gatewayWithDirectoryExpression, "handler", FileWritingMessageHandler.class);
    assertEquals("'build/foo'", TestUtils.getPropertyValue(handler, "destinationDirectoryExpression", Expression.class).getExpressionString());
    handler.handleMessage(new GenericMessage<String>("foo"));
    assertEquals(1, adviceCalled);
}
Also used : FileWritingMessageHandler(org.springframework.integration.file.FileWritingMessageHandler) Test(org.junit.Test)

Example 3 with FileWritingMessageHandler

use of org.springframework.integration.file.FileWritingMessageHandler in project spring-boot by spring-projects.

the class SampleIntegrationApplication method fileWriter.

@Bean
public FileWritingMessageHandler fileWriter() {
    FileWritingMessageHandler writer = new FileWritingMessageHandler(new File("target/output"));
    writer.setExpectReply(false);
    return writer;
}
Also used : FileWritingMessageHandler(org.springframework.integration.file.FileWritingMessageHandler) File(java.io.File) Bean(org.springframework.context.annotation.Bean)

Example 4 with FileWritingMessageHandler

use of org.springframework.integration.file.FileWritingMessageHandler in project spring-integration by spring-projects.

the class FileWritingMessageHandlerFactoryBean method createHandler.

@Override
protected FileWritingMessageHandler createHandler() {
    final FileWritingMessageHandler handler;
    if (this.directory != null && this.directoryExpression != null) {
        throw new IllegalStateException("Cannot set both directory and directoryExpression");
    } else if (this.directory != null) {
        handler = new FileWritingMessageHandler(this.directory);
    } else if (this.directoryExpression != null) {
        handler = new FileWritingMessageHandler(this.directoryExpression);
    } else {
        throw new IllegalStateException("Either directory or directoryExpression must not be null");
    }
    if (this.charset != null) {
        handler.setCharset(this.charset);
    }
    if (this.fileNameGenerator != null) {
        handler.setFileNameGenerator(this.fileNameGenerator);
    }
    if (this.deleteSourceFiles != null) {
        handler.setDeleteSourceFiles(this.deleteSourceFiles);
    }
    if (this.autoCreateDirectory != null) {
        handler.setAutoCreateDirectory(this.autoCreateDirectory);
    }
    if (this.requiresReply != null) {
        handler.setRequiresReply(this.requiresReply);
    }
    if (this.sendTimeout != null) {
        handler.setSendTimeout(this.sendTimeout);
    }
    if (this.temporaryFileSuffix != null) {
        handler.setTemporaryFileSuffix(this.temporaryFileSuffix);
    }
    handler.setExpectReply(this.expectReply);
    if (this.appendNewLine != null) {
        handler.setAppendNewLine(this.appendNewLine);
    }
    if (this.fileExistsMode != null) {
        handler.setFileExistsMode(this.fileExistsMode);
    }
    if (this.bufferSize != null) {
        handler.setBufferSize(this.bufferSize);
    }
    if (this.flushInterval != null) {
        handler.setFlushInterval(this.flushInterval);
    }
    if (this.flushWhenIdle != null) {
        handler.setFlushWhenIdle(this.flushWhenIdle);
    }
    if (this.flushPredicate != null) {
        handler.setFlushPredicate(this.flushPredicate);
    }
    if (this.chmod != null) {
        handler.setChmodOctal(this.chmod);
    }
    if (this.preserveTimestamp != null) {
        handler.setPreserveTimestamp(this.preserveTimestamp);
    }
    return handler;
}
Also used : FileWritingMessageHandler(org.springframework.integration.file.FileWritingMessageHandler)

Example 5 with FileWritingMessageHandler

use of org.springframework.integration.file.FileWritingMessageHandler in project spring-integration by spring-projects.

the class AutoCreateDirectoryIntegrationTests method defaultOutboundGateway.

@Test
public void defaultOutboundGateway() throws Exception {
    Object gateway = context.getBean("defaultOutboundGateway");
    DirectFieldAccessor gatewayAccessor = new DirectFieldAccessor(gateway);
    FileWritingMessageHandler handler = (FileWritingMessageHandler) gatewayAccessor.getPropertyValue("handler");
    assertEquals(Boolean.TRUE, new DirectFieldAccessor(handler).getPropertyValue("autoCreateDirectory"));
    assertTrue(new File(BASE_PATH + File.separator + "defaultOutboundGateway").exists());
}
Also used : DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) FileWritingMessageHandler(org.springframework.integration.file.FileWritingMessageHandler) File(java.io.File) Test(org.junit.Test)

Aggregations

FileWritingMessageHandler (org.springframework.integration.file.FileWritingMessageHandler)17 Test (org.junit.Test)13 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)11 File (java.io.File)8 Expression (org.springframework.expression.Expression)4 Bean (org.springframework.context.annotation.Bean)3 DefaultFileNameGenerator (org.springframework.integration.file.DefaultFileNameGenerator)2 Method (java.lang.reflect.Method)1 ServiceActivator (org.springframework.integration.annotation.ServiceActivator)1