我正在尝试使用mule请求程序组件进行SFTP。如何将文件名作为请求参数的一部分?这是我的流程:
<flow name="Move_Doc_To_Temp_Location" doc:name="Move_Doc_To_Temp_Location">
<jdbc-ee:inbound-endpoint queryKey="Select_Document" queryTimeout="-1" pollingFrequency="30000" connector-ref="LoanApp_Database" doc:name="Select_Doc_To_be_moved"/>
<set-variable variableName="OriginalPayload" value="#[payload]" doc:name="OriginalPayload"/>
<logger message="#[payload['DocID']] - #[payload['Location']]" level="INFO" category="Document to be moved" doc:name="Logger"/>
<!-- <mulerequester:request config-ref="Mule_Requester" resource="file:///#[payload['Location']]" doc:name="Mule Requester"/> -->
<mulerequester:request config-ref="Mule_Requester" resource="sftp://user:Pwd@Hostname#[payload['Location']]" doc:name="Mule Requester"/>
<file:outbound-endpoint path="C:\Users\jvas\Desktop\testfiles" outputPattern="#[header:originalFilename]" responseTimeout="10000" doc:name="File"/>
</flow>
位置值解析为/opt/Documents/test.txt。当我像这样指定文件名时,它会抛出一个错误:
错误2014-07-24 05:51:12,358 [[loanapp_document_flow] .Move_Doc_To_Temp_Location.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: 的 *************** ***************************** 消息:无法接收事件: DefaultInboundEndpoint {endpointUri = SFTP:// muledev:@ nylicvmmuledev /选择/文档/ test.txt的, connector = SftpConnector {name = SFTP1 lifecycle = start this = aa033b numberOfConcurrentTransactedReceivers = 4
createMultipleTransactedReceivers = true connected = true
supportedProtocols = [sftp] serviceOverrides =}, 名称=&#39; endpoint.sftp.nylicvmmuledev.opt.Documents.test.txt&#39 ;, mep = ONE_WAY,properties = {}, transactionConfig = Transaction {factory = null,action = INDIFFERENT, timeout = 0},deleteUnacceptedMessages = false,initialState = started, responseTimeout = 10000,endpointEncoding = UTF-8, disableTransportTransformer = false}(超时= 1000)代码
:MULE_ERROR-92 -------------------------------------------------- ------------------------------异常堆栈是: 1.错误&#39;没有这样的文件&#39;尝试CDW到&#39; /opt/Documents/test.txt'时发生。 (java.io.IOException的)
org.mule.transport.sftp.SftpClient:102(null) 2.无法接收事件:DefaultInboundEndpoint {endpointUri = sftp:// muledev:@nylicvmmuledev / opt / Documents / test.txt, connector = SftpConnector {name = SFTP1 lifecycle = start this = aa033b numberOfConcurrentTransactedReceivers = 4
createMultipleTransactedReceivers = true connected = true
supportedProtocols = [sftp] serviceOverrides =}, 名称=&#39; endpoint.sftp.nylicvmmuledev.opt.Documents.test.txt&#39 ;, mep = ONE_WAY,properties = {}, transactionConfig = Transaction {factory = null,action = INDIFFERENT, timeout = 0},deleteUnacceptedMessages = false,initialState = started, responseTimeout = 10000,endpointEncoding = UTF-8, disableTransportTransformer = false}(超时= 1000) (org.mule.api.transport.ReceiveException)
org.mule.transport.AbstractMessageRequester:132 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/transport/ReceiveException.html) -------------------------------------------------- ------------------------------ Root异常堆栈跟踪:java.io.IOException:错误&#39;没有这样的文件&# 39; 尝试CDW到&#39; /opt/Documents/test.txt'时发生。在 org.mule.transport.sftp.SftpClient.changeWorkingDirectory(SftpClient.java:102) 在 org.mule.transport.sftp.SftpConnector.createSftpClient(SftpConnector.java:196) 在 org.mule.transport.sftp.SftpConnector.createSftpClient(SftpConnector.java:174) + 3个以上(设置调试级别日志记录或&#39; -Dmule.verbose.exceptions = true&#39;表示所有内容)
现在我尝试从该位置删除文件名,并且SFTP成功,但它随机选择了一个文件。该文件具有SFTP的所有权限,我可以通过命令行成功执行SFTP。我已经参考了SFTP URL的文档,这是它为从URL解析文件名所提供的内容:http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04#section-4.1
从主机上的用户主目录中检索file.txt host.example.com使用用户名用户使用SFTP。这个例子 假设实现支持路径的指示 使用前导波形符相对于主目录。
sftp://user@host.example.com/~/file.txt
从主机上的绝对路径/目录/路径中检索file.txt host.example.com使用用户名用户使用SFTP。
sftp://user@host.example.com/dir/path/file.txt
答案 0 :(得分:8)
Mule SFTP连接器无法获取地址中的文件名。相反,您需要使用文件名过滤器。但是,遗憾的是,我认为请求者模块忽略了端点上配置的过滤器,如下所述:http://forum.mulesoft.org/mulesoft/topics/mule_module_requester_add_support_for_filenamefilter
但是,您可以使用脚本通过sftp mid flow读取文件。类似的东西:
<scripting:transformer>
<scripting:script engine="Groovy">
<scripting:text>
def endpointBuilder = muleContext.endpointFactory.getEndpointBuilder(
"sftp://${sftp.username}@${sftp.host}:${sftp.port}/${sftp.path}?identityFile=${app.home}/${sftp.keyPath}&passphrase=${sftp.passphrase}&connector=sftp-csv")
endpointBuilder.addMessageProcessor(new org.mule.routing.MessageFilter(new org.mule.transport.file.filters.FilenameWildcardFilter(sessionVars.expectedFilename)))
def inboundEndpoint = endpointBuilder.buildInboundEndpoint()
inboundEndpoint.request(30000L)
</scripting:text>
</scripting:script>
</scripting:transformer>