简体   繁体   English

Spring Integration DSL - 可以访问标头的出站网关

[英]Spring Integration DSL - Outbound Gateway with access to Headers

I'm having an issue with Spring Integration. 我遇到了Spring Integration的问题。 I'm using Spring Boot 1.4.0.RELEASE, Spring Integration 4.3.1.RELEASE, Spring Integration DSL 1.2.0.M1. 我正在使用Spring Boot 1.4.0.RELEASE,Spring Integration 4.3.1.RELEASE,Spring Integration DSL 1.2.0.M1。

What I'm trying to do: 我正在尝试做什么:

I'm writing an application that will read files from FTP and local file system (using inbound channel adapters), transfer the files to a local working directory (using file outbound gateways), process, then move them to a final destination (file outbound gateway/adapters). 我正在编写一个应用程序,它将从FTP和本地文件系统读取文件(使用入站通道适配器),将文件传输到本地工作目录(使用文件出站网关),处理,然后将它们移动到最终目的地(文件出站)网关/适配器)。

EDIT: The original issue stemmed from incorrect usage of the OutboundGateway . 编辑:原始问题源于OutboundGateway错误使用。 For details of what I was doing wrong, look at the edit history. 有关我做错的详细信息,请查看编辑历史记录。

I'm having a problem with wiring an OutboundGateway that needs information from the message header. 我在连接需要来自邮件头的信息的OutboundGateway遇到问题。

My basic flow is: 我的基本流程是:

@Bean
@SuppressWarnings("unchecked")
public IntegrationFlow fileSystemReadingFlow() {
    LOGGER.debug("Building fileSystemReadingFlow.");
    // Create a FileInboundChannelAdapter

        return IntegrationFlows.from(s -> s.file(new File(StringUtils.cleanPath(Paths.get(directoryProperties.getLocal() , UNKNOWN).toString())))
                        // Add a Filter to restrict which files are retrieved
                        .filter(fileListFilterBuilder.buildFileListFilter(File.class))
                // Add a poller to continually watch the directory
                , endpointConfigurer -> endpointConfigurer.poller(poller)
        )
                .enrichHeaders(h -> h.header(FOLDER_NAME, LOCAL))
                .handle((message, headers) -> Files.outboundGateway(new File( StringUtils.cleanPath(Paths.get(directoryProperties.getWorking()
                                    , (String) headers.get(FOLDER_NAME)).toString()))).deleteSourceFiles(true).autoCreateDirectory(true) )
                // Send the files to the aggregatingChannel
                .channel("aggregatingFileChannel")
                .get();
  }

The issue is the handle((message, headers) -> Files.outboundGateway(...) section. Using the lambda method above spits out this error over and over. 问题是handle((message, headers) -> Files.outboundGateway(...)部分。使用上面的lambda方法一遍又一遍地吐出这个错误。

ErrorMessage [payload=org.springframework.messaging.MessagingException: failed to resolve channel name 'org.springframework.integration.dsl.file.FileWritingMessageHandlerSpec'; nested exception is org.springframework.messaging.core.DestinationResolutionException: failed to look up MessageChannel with name 'org.springframework.integration.dsl.file.FileWritingMessageHandlerSpec' in the BeanFactory.; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No bean named 'org.springframework.integration.dsl.file.FileWritingMessageHandlerSpec' is defined, headers={id=e3f5f341-6379-0dd0-11e6-e4bff8f455b0, timestamp=1471619276894}]

The documentation and my testing show that defining it like below works. 文档和我的测试表明,定义它如下所示。 But, how do I get access to the headers? 但是,如何访问标题?

.handle(Files.outboundGateway(new File( "someDir"))).deleteSourceFiles(true).autoCreateDirectory(true) )

I've tried using a SpEl expression, which may be the right method, but I didn't get it to work. 我已经尝试使用SpEl表达式,这可能是正确的方法,但我没有让它工作。

.handle(Files.outboundGateway("StringUtils.cleanPath(Paths.get(directoryProperties.getWorking()" +
                                    ", headers[FOLDER_NAME]).toString())").deleteSourceFiles(true).autoCreateDirectory(true) )

After re-reading the SpEL reference, I was able to figure out my problem. 重新阅读SpEL参考后,我能够找出问题所在。 I needed to explicitly reference the static methods I needed to call and then escape the literals properly. 我需要显式引用我需要调用的静态方法,然后正确地转义文字。

.handle(Files.outboundGateway("T(org.springframework.util.StringUtils).cleanPath(T(java.nio.file.Paths).get('" +directoryProperties.getWorking() +"'" +
                                    ", headers['"+FOLDER_NAME+"']).toString())").deleteSourceFiles(true).autoCreateDirectory(true) )

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring集成dsl:http出站网关 - Spring integration dsl: http outbound gateway Spring Integration Java DSL - Http Outbound Gateway uri 变量表达式 - Spring Integration Java DSL - Http Outbound Gateway uri variable Expression Spring Integration Java DSL - 如何调用int-http:outbound-gateway? - Spring Integration Java DSL - How to invoke int-http:outbound-gateway? 将文件/文件从远程目录移动到另一个 Spring 集成 SFTP 出站网关 Java 配置/Java DSL - Moving file/files from remote directory to another Spring Integration SFTP Outbound Gateway Java Config/Java DSL Http 出站网关正在工作但未拨打电话 - 使用 spring 集成 DSL java - Http outbound gateway is working but not making the call - using spring integration DSL java 带有删除的SFTP Outbound的Spring Integration DSL - Spring Integration DSL for SFTP Outbound with delete 使用Spring AMQP出站网关发送消息头 - Sending Message Headers with Spring AMQP outbound gateway Spring Integration Http Outbound Gateway Header Mapper - Spring Integration Http Outbound Gateway Header Mapper 自定义spring集成出站网关实现 - custom spring integration outbound gateway implementation 在 Spring Integration 中使用 Http Outbound Gateway 进行错误处理 - Error handling with Http Outbound Gateway in Spring Integration
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM