【问题标题】:WSO2 Api Manager sequence to write to a file is not working写入文件的 WSO2 Api Manager 序列不起作用
【发布时间】:2017-03-16 00:14:33
【问题描述】:

最近我们开始研究 WSO2 Api Manager 并希望创建一个故障流序列,它将有关故障的一些信息写入位于文件系统中的文件中。 WSO2 API Manager 安装适用于 Windows

我按照this dock page 中的文档步骤启用了 VFS 传输。然后我按照这个例子from the docks创建了一个文件代理和文件写入序列(我跳过了数据库和文件阅读器,因为我不需要它们):

<sequence xmlns="http://ws.apache.org/ns/synapse" name="fileWriteSequence">
<log level="custom">
    <property name="sequence" value="fileWriteSequence"/>
</log>
<property xmlns:ns2="http://org.apache.synapse/xsd" name="transport.vfs.ReplyFileName" expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.txt')" scope="transport"/>
<property xmlns:ns2="http://org.apache.synapse/xsd" name="transport.vfs.Locking" value="disable" scope="transport"/>
<property name="OUT_ONLY" value="true"/>
<send>
    <endpoint name="FileEpr">
        <address uri="vfs:file:///C:/home/username/test/out"/>
    </endpoint>
</send>

我已经创建了 API 和上传的序列就好了,看起来它正在按预期触发,但文件没有被创建 - 这是来自进程的日志:

[2017-03-10 08:27:02,525]  INFO - LogMediator sequence = fileWriteSequence
[2017-03-10 08:27:03,384] ERROR - VFSUtils Cannot get the lock for the file : file:///C:/home/username/test/out/* before processing
[2017-03-10 08:27:03,385]  WARN - VFSTransportSender Couldn't get the lock for the file : file:///C:/home/username/test/out/*, retry : 1 scheduled after : 30000

首先我认为这是权限问题,但我授予匿名用户对此位置的完全控制权并以管理员身份运行 WSO2 AM 进程 - 仍然没有运气。

更新

我通过在全局配置 (axis2) 中禁用文件锁定来解决问题

<transportSender name="vfs" class="org.apache.synapse.transport.vfs.VFSTransportSender">
<parameter name="transport.vfs.Locking">disable</parameter>
</transportSender>

还是不行,只是报错略有不同(还是报错路径)。

Caused by: java.io.FileNotFoundException: C:\home\username\test\out\* (The filename, directory name, or volume label syntax is incorrect)
    at java.io.FileOutputStream.open(Native Method)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:221)
    at java.io.FileOutputStream.<init>(FileOutputStream.java:142)
    at org.apache.commons.vfs2.provider.local.LocalFile.doGetOutputStream(LocalFile.java:251)
    at org.apache.commons.vfs2.provider.AbstractFileObject.getOutputStream(AbstractFileObject.java:1399)

您可能会注意到,末尾有"*",我并不惊讶找不到整个文件路径,但它是由lib添加的,因此可能是预期的。

是否有人对 WSO2 ESB/AM 有任何经验并知道如何解决这个问题?这可能是微不足道的,但经过多次尝试后我找不到解决方案。

【问题讨论】:

  • 我认为你的地址 uri 是错误的。尝试使用 vfs:file://C:/home/username/test/out 而不是 vfs:file:///C:/home/username/test/out(删除一个斜线,因为它是 Windows)
  • 嗯,我在调查时检查过它并没有改变任何东西。事实上,引擎自己添加了这个斜线。我为此锁做了一个解决方法(通过禁用),更新了我的消息。

标签: wso2 wso2esb wso2-am


【解决方案1】:

你的配置对我有用,看看:

<?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="writeFile"
       transports="http https"
       startOnLoad="true">
   <target>
      <inSequence>
         <payloadFactory media-type="xml">
            <format>
               <moc:QRY_SELECT_SRH_PERSONA xmlns:moc="http://www.example.org/mockWS/">
                  <INT_ID xmlns="">1</INT_ID>
               </moc:QRY_SELECT_SRH_PERSONA>
            </format>
            <args/>
         </payloadFactory>
         <log level="custom">
            <property name="sequence" value="fileWriteSequence"/>
         </log>
         <property xmlns:ns2="http://org.apache.synapse/xsd"
                   name="transport.vfs.ReplyFileName"
                   expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.txt')"
                   scope="transport"/>
         <property name="transport.vfs.Locking" value="disable" scope="transport"/>
         <property name="OUT_ONLY" value="true"/>
         <send>
            <endpoint name="FileEpr">
               <address uri="vfs:file:///C:/home/username/test/out"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence/>
      <faultSequence>
         <log level="custom">
            <property name="text" value="Error Sequence FAIL"/>
            <property name="message" expression="get-property('ERROR_MESSAGE')"/>
            <property name="code" expression="get-property('ERROR_CODE')"/>
            <property name="detail" expression="get-property('ERROR_DETAIL')"/>
            <property name="exception" expression="get-property('ERROR_EXCEPTION')"/>
         </log>
      </faultSequence>
   </target>
</proxy>

我的文件在 C:\home\username\test\out\8a11314c-4c22-4ad3-bbfc-4fb56ba415a0.txt 包含以下内容:

<?xml version='1.0' encoding='UTF-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body><moc:QRY_SELECT_SRH_PERSONA xmlns:moc="http://www.example.org/mockWS/"><INT_ID>1</INT_ID></moc:QRY_SELECT_SRH_PERSONA></soapenv:Body></soapenv:Envelope>

更新 1:

代理配置之外的序列:

<sequence name="faultSEQ" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
         <payloadFactory media-type="xml">
            <format>
               <moc:QRY_SELECT_SRH_PERSONA xmlns:moc="http://www.example.org/mockWS/">
                  <INT_ID xmlns="">1</INT_ID>
               </moc:QRY_SELECT_SRH_PERSONA>
            </format>
            <args/>
         </payloadFactory>
         <log level="custom">
            <property name="sequence" value="fileWriteSequence"/>
         </log>
         <property xmlns:ns2="http://org.apache.synapse/xsd"
                   name="transport.vfs.ReplyFileName"
                   expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.txt')"
                   scope="transport"/>
         <property name="transport.vfs.Locking" value="disable" scope="transport"/>
         <property name="OUT_ONLY" value="true"/>
         <send>
            <endpoint name="FileEpr">
               <address uri="vfs:file:///C:/home/username/test/out"/>
            </endpoint>
         </send>
</sequence>

【讨论】:

  • 所以你添加了这个代理,但你是否以某种方式将它链接到 API?我需要编写一个错误的序列并将其链接到特定的 API(最好来自 API Manager UI)。您是如何触发此文件创建的?
  • 好的,但是您使用了 WSO ESB - 您知道如何创建与 WSO2 API Manager 兼容的序列吗? WSO2 AM 不能在代理上运行,所以这个解决方案不符合我的需要 - 抱歉,如果我的问题具有误导性,但我想将此序列集成到 WSO2 AM,而不是普通的 ESB
  • 如果您阅读了我的问题,我已经编写了相同的序列,所以它不能解决任何问题 - 在 Windows 上没有创建文件(它无法创建路径 C:/home/username/ test/out/*),在 Ubuntu 上它会创建一个名为 * 的文件,但它是空的。此序列在 Api Manager 中是否适合您?
【解决方案2】:

所以最后我能够“修复”这个问题,但不是完全。

结果表明"*" 来自我为我在 WSO2 API 管理器中访问的 API 创建的端点。因此,一旦我添加了新的端点(资源),例如"/test",序列就会在使用所需内容指定的路径下创建一个文件“test”。 它仍然远非理想,因为看起来 API Manager 只是忽略了 ReplyFileName 参数。不过,假设解决了我面临的主要问题,所以我将从那时开始进一步研究。

【讨论】:

    猜你喜欢
    • 2021-09-13
    • 2019-12-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-08-29
    相关资源
    最近更新 更多