我的目标是找到一个匹配给定模式的文件列表(在我的例子中为D [MMDDYYYY]到[MMDDYYYY] .zip),然后通过返回的文件名列表进行迭代并将它们复制到目的地。我不知道如何正确解析fileconnector.search操作的结果。解析fileconnector.search返回的文件名的正确XPath表达式是什么?我的代码和输出如下所示。
提前谢谢。
<sequence name="TestFTPDownloadSeq" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
<fileconnector.search>
<source>ftp://username:pwd@ftphost/data/</source>
<filePattern>D08082016/.+/.csv</filePattern>
<recursiveSearch>false</recursiveSearch>
</fileconnector.search>
<iterate expression="//file" xmlns:ns2="http://org.apache.synapse/xsd" xmlns:sec="http://secservice.samples.esb.wso2.org">
<target>
<sequence>
<property expression="//file" name="fileName"
scope="default" type="STRING"/>
<fileconnector.copy>
<source>ftp://username:pwd@ftphost/data/</destination>
<destination>C:/MyApps/data/in</destination>
<filePattern>{$ctx:fileName}</filePattern>
</fileconnector.copy>
<drop/>
</sequence>
</target>
</iterate>
</sequence>
日志文件
[2016-08-10 13:00:08,519] DEBUG - TemplateMediator Start : EIP Sequence paramNames : [source, filePattern, recursiveSearch, setTimeout, setPassiveMode, setSoTimeout, setStrictHostKeyChecking, setUserDirIsRoot]
[2016-08-10 13:00:08,519] DEBUG - TemplateMediator Sequence <TemplateMediator> :: mediate()
[2016-08-10 13:00:08,519] DEBUG - TemplateMediator Mediation started from mediator position : 0
[2016-08-10 13:00:08,519] DEBUG - TemplateMediator Building message. Sequence <TemplateMediator> is content aware
[2016-08-10 13:00:08,519] DEBUG - PropertyMediator Start : Property mediator
[2016-08-10 13:00:08,519] DEBUG - PropertyMediator Setting property : source at scope : default to : ftp://username:pwd@ftphost/data/ (i.e. result of expression : $func:source)
[2016-08-10 13:00:08,519] DEBUG - PropertyMediator End : Property mediator
[2016-08-10 13:00:08,519] DEBUG - PropertyMediator Start : Property mediator
[2016-08-10 13:00:08,519] DEBUG - PropertyMediator Setting property : filePattern at scope : default to : D08082016/.+/.csv (i.e. result of expression : $func:filePattern)
[2016-08-10 13:00:08,519] DEBUG - PropertyMediator End : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Start : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Setting property : recursiveSearch at scope : default to : false (i.e. result of expression : $func:recursiveSearch)
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator End : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Start : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Setting property : setTimeout at scope : default to : null (i.e. result of expression : $func:setTimeout)
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator End : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Start : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Setting property : setPassiveMode at scope : default to : null (i.e. result of expression : $func:setPassiveMode)
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator End : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Start : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Setting property : setSoTimeout at scope : default to : null (i.e. result of expression : $func:setSoTimeout)
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator End : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Start : Property mediator
[2016-08-10 13:00:08,520] DEBUG - PropertyMediator Setting property : setStrictHostKeyChecking at scope : default to : null (i.e. result of expression : $func:setStrictHostKeyChecking)
[2016-08-10 13:00:08,521] DEBUG - PropertyMediator End : Property mediator
[2016-08-10 13:00:08,521] DEBUG - PropertyMediator Start : Property mediator
[2016-08-10 13:00:08,521] DEBUG - PropertyMediator Setting property : setUserDirIsRoot at scope : default to : null (i.e. result of expression : $func:setUserDirIsRoot)
[2016-08-10 13:00:08,521] DEBUG - PropertyMediator End : Property mediator
[2016-08-10 13:00:08,521] DEBUG - ClassMediator Start : Class mediator
[2016-08-10 13:00:08,521] DEBUG - ClassMediator invoking : class org.wso2.carbon.connector.FileSearch.mediate()
[2016-08-10 13:00:08,547] DEBUG - ClassMediator End : Class mediator
[2016-08-10 13:00:08,547] DEBUG - IterateMediator Start : Iterate mediator
[2016-08-10 13:00:08,550] DEBUG - IterateMediator Splitting with XPath : //file resulted in 0 elements
答案 0 :(得分:1)
示例代理按模式搜索并移动到该位置。更多here
<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
name="SampleProxy"
transports="https,http"
statistics="disable"
trace="disable"
startOnLoad="true">
<target>
<inSequence>
<property name="fileLocation" expression="//fileLocation"/>
<property name="fileName" expression="//fileName"/>
<property name="newfilelocation" expression="//newfilelocation"/>
<property name="filebeforeprocess" expression="//filebeforeprocess"/>
<property name="fileafterprocess" expression="//fileafterprocess"/>
<property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
<fileconnector.search>
<filelocation>{$ctx:fileLocation}</filelocation>
<filepattern>([^\s]+(\.(?i)(txt|png|gif|bmp))$)</filepattern>
<searchinlocal>false</searchinlocal>
</fileconnector.search>
<property name="sequence" value="after-smooks"/>
</log>
<iterate xmlns:ns2="http://org.apache.synapse/xsd"
xmlns:sec="http://secservice.samples.esb.wso2.org"
expression="//file">
<target>
<sequence>
<log level="full"/>
<fileconnector.move>
<filelocation>{$ctx:fileLocation}</filelocation>
<file>fileSample.txt</file>
<newfilelocation>{$ctx:newfilelocation}</newfilelocation>
<filebeforeprocess>{$ctx:filebeforeprocess}</filebeforeprocess>
<fileafterprocess>{$ctx:fileafterprocess}</fileafterprocess>
</fileconnector.move>
<drop/>
</sequence>
</target>
</iterate>
</inSequence>
</target>
<description/>
</proxy>
答案 1 :(得分:0)
请关注此博文https://medium.com/@lmanohara99/wso2-esb-file-connector-version-2-f789ad389d7d#.2ivi97d9x
此外,检查您的正则表达式模式是否得到结果。您可以从此处https://regex101.com/
验证您的正则表达式模式