如何使用Mule Requester进行SFTP-动态文件名和路径 [英] How to use mule requester for SFTP - Dynamic file name and path

查看:105
本文介绍了如何使用Mule Requester进行SFTP-动态文件名和路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试将Mule请求者组件用于SFTP.如何在请求参数中指定文件名?这是我的流程:

I am trying to use a mule requester component for SFTP. How do I give the file name as part of the request argument? This is my flow:

<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.当我这样指定文件名时,它会抛出一个错误:

The location value resolves to /opt/Documents/test.txt. When I specify the filename like this, it throws me an error:

错误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/opt/Documents/test.txt, connector = SftpConnector {name = SFTP1 lifecycle = start this = aa033b numberOfConcurrentTransactedReceivers = 4
createMultipleTransactedReceivers = true已连接= true
supportedProtocols = [sftp] serviceOverrides =}, name ='endpoint.sftp.nylicvmmuledev.opt.Documents.test.txt', mep = ONE_WAY,属性= {}, transactionConfig = Transaction {factory = null,action = INDIFFERENT, timeout = 0},deleteUnacceptedMessages = false,initialState = started, responseTimeout = 10000,endpointEncoding = UTF-8, disableTransportTransformer = false}(超时= 1000)代码
:MULE_ERROR-92 -------------------------------------------------- ------------------------------异常堆栈为: 1.尝试CDW到'/opt/Documents/test.txt'时,发生错误'No such file'. (java.io.IOException)
org.mule.transport.sftp.SftpClient:102(空) 2.无法通过以下方式接收事件:DefaultInboundEndpoint {endpointUri = sftp://muledev:@ nylicvmmuledev/opt/Documents/test.txt, connector = SftpConnector {name = SFTP1 lifecycle = start this = aa033b numberOfConcurrentTransactedReceivers = 4
createMultipleTransactedReceivers = true已连接= true
supportedProtocols = [sftp] serviceOverrides =}, name ='endpoint.sftp.nylicvmmuledev.opt.Documents.test.txt', mep = ONE_WAY,属性= {}, 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 ) -------------------------------------------------- ------------------------------根异常堆栈跟踪:java.io.IOException:错误无此文件" 尝试CDW到'/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个以上(为所有内容设置调试级别日志记录或'-Dmule.verbose.exceptions = true')

ERROR 2014-07-24 05:51:12,358 [[loanapp_document_flow].Move_Doc_To_Temp_Location.stage1.02] org.mule.exception.DefaultMessagingExceptionStrategy: **************************************************************************** Message : Failed to receive event over: 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= } , name='endpoint.sftp.nylicvmmuledev.opt.Documents.test.txt', mep=ONE_WAY, properties={}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false} (timeout=1000) Code
: MULE_ERROR-92 -------------------------------------------------------------------------------- Exception stack is: 1. Error 'No such file' occurred when trying to CDW to '/opt/Documents/test.txt'. (java.io.IOException)
org.mule.transport.sftp.SftpClient:102 (null) 2. Failed to receive event over: 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= } , name='endpoint.sftp.nylicvmmuledev.opt.Documents.test.txt', mep=ONE_WAY, properties={}, transactionConfig=Transaction{factory=null, action=INDIFFERENT, timeout=0}, deleteUnacceptedMessages=false, initialState=started, responseTimeout=10000, endpointEncoding=UTF-8, disableTransportTransformer=false} (timeout=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 Exception stack trace: java.io.IOException: Error 'No such file' occurred when trying to CDW to '/opt/Documents/test.txt'. at org.mule.transport.sftp.SftpClient.changeWorkingDirectory(SftpClient.java:102) at org.mule.transport.sftp.SftpConnector.createSftpClient(SftpConnector.java:196) at org.mule.transport.sftp.SftpConnector.createSftpClient(SftpConnector.java:174) + 3 more (set debug level logging or '-Dmule.verbose.exceptions=true' for everything)

现在,我尝试从该位置删除文件名,并且SFTP成功,但是它随机选择了一个文件.该文件具有SFTP的所有权限,我能够通过命令行成功执行SFTP.我已经参考了SFTP URL的文档,这是从URL解析文件名所提供的:

Now I tried removing the file name from the location, and the SFTP was successful, but it has randomly chosen a file. The file has all permissions for SFTP and I am able to do the SFTP via command line successfully. I have referred to the documentation for the SFTP URL and this is what it provides for resolving the file name from the URL : http://tools.ietf.org/html/draft-ietf-secsh-scp-sftp-ssh-uri-04#section-4.1

从主机上用户的主目录中检索file.txt,该主机位于 使用用户名用户的SFTP使用host.example.com.这个例子 假设实现支持路径指示 相对于使用前导波浪号的主目录.

Retrieve file.txt from the user's home directory on the host at host.example.com using SFTP using username user. This example assumes that the implementation supports the indication of a path relative to the home directory using a leading tilde.

    sftp://user@host.example.com/~/file.txt

从主机上的绝对路径/dir/path检索file.txt,位于 使用SFTP(使用用户名用户)访问host.example.com.

Retrieve file.txt from the absolute path /dir/path on the host at host.example.com using SFTP using username user.

    sftp://user@host.example.com/dir/path/file.txt

推荐答案

Mule SFTP连接器无法在地址中获取文件名.相反,您需要使用文件名过滤器.但是,不幸的是,我认为请求者模块忽略了在端点上配置的过滤器,如下所述: http://forum.mulesoft.org /mulesoft/topics/mule_module_requester_add_support_for_filenamefilter

The Mule SFTP connector can not take the filename in the address. Instead you need to use a filename filter. However, unfortunately I think the requestor module ignores the filters configured on the endpoint as mentioned here: http://forum.mulesoft.org/mulesoft/topics/mule_module_requester_add_support_for_filenamefilter

但是,您可以使用脚本通过sftp中流读取文件.像这样:

You could however use a script to read a file over sftp mid flow. Something like:

<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}&amp;passphrase=${sftp.passphrase}&amp;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>

这篇关于如何使用Mule Requester进行SFTP-动态文件名和路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆