简体   繁体   中英

WSO2 Api Manager sequence to write to a file is not working

Recently we started looking into WSO2 Api Manager and want to create a fault flow sequence, which will write some information about the fauilure to a file located in file system. The WSO2 API Manager installation is for Windows .

I followed the documentation steps from this dock page to enable VFS transport. Then I followed this example from the docks to create a file proxy and file write sequence (I skipped database and file reader as I don't need them):

<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>

I have created API and uploaded sequence just fine and looks like it is being triggered as expected, but the file is not being created - this is the log from the process:

[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

First I thought it is an issue with permissions, but I granted full controll for anonymous user for this location and run WSO2 AM process as an Administrator - still no luck.

UPDATE

I did a workaround by disabling file locking in global configuration (axis2)

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

It still doesn't work, but the error is slightly different (still complains about the path).

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)

As you might notice, there is "*" at the end and I am not surprised that whole file path cannot be found, but it is added by the lib, so it is possible that it is expected.

Does anyone have any experience with WSO2 ESB/AM and knows how to solve this? It might be trivial, but after many tries I couldn't find a solution.

Your config work for me, take a look:

<?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>

My file in C:\\home\\username\\test\\out\\8a11314c-4c22-4ad3-bbfc-4fb56ba415a0.txt with this content:

<?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>

UPDATE 1:

The sequence outside the proxy config:

<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>

So finally I was able to "fix" this, but not fully.

It came out that the "*" comes from the endpoint I have created for the API I am accessing in WSO2 API Manager. So once I added new endpoint (resource), example "/test" , sequence creates a file "test" under path specified with desired content. It is still far from ideal, because looks like API Manager just ignores ReplyFileName parameter. Nevertheless, let's say that solved main issue I was facing, so I will start further research from that point.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM