WSO2 Api 写入文件的管理器序列不工作
WSO2 Api Manager sequence to write to a file is not working
最近我们开始研究 WSO2 Api Manager 并希望创建一个故障流序列,它将一些有关故障的信息写入位于文件系统中的文件中。 WSO2 API 管理器安装适用于 Windows.
我按照 this dock page to enable VFS transport. Then I followed this example from the docks 中的文档步骤创建文件代理和文件写入序列(我跳过了数据库和文件 reader,因为我不需要它们):
<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)
您可能会注意到,末尾有 "*"
并且找不到整个文件路径我并不感到惊讶,但它是由库添加的,因此可能是预期的。
有没有人使用过 WSO2 ESB/AM 并且知道如何解决这个问题?这可能是微不足道的,但经过多次尝试我找不到解决方案。
你的配置适合我,看看:
<?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\outa11314c-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>
所以我终于能够 "fix" 这个,但还不完全。
结果是 "*"
来自我为我在 WSO2 API 管理器中访问的 API 创建的端点。因此,一旦我添加了新的端点(资源),例如 "/test"
,序列就会在指定的路径下创建一个文件 "test",其中包含所需的内容。
它仍然远非理想,因为看起来 API 管理器只是忽略了 ReplyFileName 参数。尽管如此,假设这解决了我面临的主要问题,所以我将从那时开始进一步研究。
最近我们开始研究 WSO2 Api Manager 并希望创建一个故障流序列,它将一些有关故障的信息写入位于文件系统中的文件中。 WSO2 API 管理器安装适用于 Windows.
我按照 this dock page to enable VFS transport. Then I followed this example from the docks 中的文档步骤创建文件代理和文件写入序列(我跳过了数据库和文件 reader,因为我不需要它们):
<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)
您可能会注意到,末尾有 "*"
并且找不到整个文件路径我并不感到惊讶,但它是由库添加的,因此可能是预期的。
有没有人使用过 WSO2 ESB/AM 并且知道如何解决这个问题?这可能是微不足道的,但经过多次尝试我找不到解决方案。
你的配置适合我,看看:
<?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\outa11314c-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>
所以我终于能够 "fix" 这个,但还不完全。
结果是 "*"
来自我为我在 WSO2 API 管理器中访问的 API 创建的端点。因此,一旦我添加了新的端点(资源),例如 "/test"
,序列就会在指定的路径下创建一个文件 "test",其中包含所需的内容。
它仍然远非理想,因为看起来 API 管理器只是忽略了 ReplyFileName 参数。尽管如此,假设这解决了我面临的主要问题,所以我将从那时开始进一步研究。