如何使用 WSO2 中的文件连接器解压任何 zip 文件

How to unzip any zip file using File Connector in WSO2

我正在尝试解压缩一个 zip 文件,该文件可以是任何名称。下面是我的代码:-

<proxy name="Unzip" startOnLoad="true" transports="http https" xmlns="http://ws.apache.org/ns/synapse">
<target>
    <inSequence>
        <fileconnector.unzip>
            <source>file:///D:/AfterProcess/.*\.zip</source>
            <destination>file:///D:/001/</destination>
        </fileconnector.unzip>
        <respond></respond>
    </inSequence>
    <outSequence/>
    <faultSequence/>
</target>

但是无法解压。如果我尝试给出如下文件名:-

<source>file:///D:/AfterProcess/Hello.zip</source>

那么它正在工作。如果我不知道该文件的名称,如何解压缩该文件?

解压缩时不能在源中使用正则表达式。如果可以,那么如果有多个匹配的文件会怎样?

如果您知道 zip 文件始终位于该目录中,那么您可以使用文件连接器搜索来查找文件名。

<fileconnector.search>
    <source>file:///D:/AfterProcess/</source>
    <filePattern>.*\.zip</filePattern>
    <recursiveSearch>False</recursiveSearch>
</fileconnector.search>

搜索将return以下内容,如果它是目录中唯一的 zip 文件。

<fc:result xmlns:fc="http://org.wso2.esbconnectors.FileConnector">
    <fc:file>/AfterProcess/Hello.zip</fc:file>
</fc:result>

从那里您可以将路径输入到解压缩函数中。您需要在搜索结果前加上 file:///D: 前缀,使其再次成为绝对路径。

<fileconnector.unzip>
    <source xmlns:fc="http://org.wso2.esbconnectors.FileConnector">{fn:concat('file:///D:', //fc:result/fc:file/text())}</source>
    <destination>file:///D:/001/</destination>
</fileconnector.unzip>