0
votes

In our project we are using WSO2 API Manager v 2.1.0. Our goal is to write a fault sequence that will log some information in custom logfile, example timestamp, name of the API etc. I was able to create a file and write to it, but it does not work as expected. Things I need to have is

  • Control the file name
  • Append content to file instead of overwriting it each time

This is the sequence I am using (simplified easier reading):

<?xml version="1.0" encoding="UTF-8"?>
<sequence xmlns="http://ws.apache.org/ns/synapse" name="admin--FaultyAPI2:v1.0.0--Fault">
   <clone continueParent="true">
      <target>
         <sequence>
            <property xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:wsa="http://www.w3.org/2005/08/addressing" xmlns:ns3="http://org.apache.synapse/xsd" name="destination" expression="get-property('To')"/>
               <format>
                        {
                            "destination_host" : "$1"
                        }
                    </format>
               <args>
                  <arg xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:ns3="http://org.apache.synapse/xsd" evaluator="xml" expression="get-property('destination')"/>
               </args>
            </payloadFactory>
            <property name="transport.vfs.ReplyFileName" value="test.txt" scope="transport" type="STRING"/>
            <property name="OUT_ONLY" value="true" scope="default" type="STRING"/>
            <send>
               <endpoint>
                  <http uri-template="vfs:file:///home/install/out?transport.vfs.Append=true"/>
               </endpoint>
            </send>
         </sequence>
      </target>
   </clone>
</sequence>

Following documentation I have used transport.vfs.ReplyFileName to specify the file name and ?transport.vfs.Append=true path parameter to tell it to append to file. The problem is that those two things are ignored. First thing is that the file created is not test.txt but it is the endpoint URI that failed (the one I have setup in API Manager). So if I call /fault endpoint the file created is fault under location specified. The second thing is that it is not appending to a file, but overwriting it each time the sequence is triggered. It is even worse! It creates actual path /home/install/out?transport.vfs.Append=true on file system and saves the file under this directory.

Those features seems to work under WSO ESB, but not API Manager. Any ideas anyone?

1

1 Answers

0
votes

First of all, I have tested this in WSO2 EI, not in API Manager, but it seemed to me, the same problems you described appeared.

Controlling the filename

I've had some issues with this as well. The problem is that when you call the sequence through an API, the filename is not constructed based on the "transport.vfs.ReplyFileName" transport property, but based on the "REST_URL_POSTFIX" axis2 property. You can solve this by setting the "REST_URL_POSTFIX" property to the correct filename or by removing that property.

Appending the content

You are using an http endpoint, but you should use an address endpoint. In that case the path parameter will be recognized.

Example

I think your code should look more like this:

<?xml version="1.0" encoding="UTF-8"?>
<sequence name="admin--FaultyAPI2:v1.0.0--Fault" trace="disable" xmlns="http://ws.apache.org/ns/synapse">
    <clone continueParent="true">
        <target>
            <sequence>
                <payloadFactory media-type="json">
                    <format>
                  {
                  "destination_host" : "$1"
                  }
               </format>
                    <args>
                        <arg evaluator="xml" expression="get-property('destination')" xmlns:ns3="http://org.apache.synapse/xsd" xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"/>
                    </args>
                </payloadFactory>
                <property name="transport.vfs.ReplyFileName" scope="transport" type="STRING" value="test.txt"/>
                <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
                <property name="REST_URL_POSTFIX" action="remove" scope="axis2" />
                <send>
                    <endpoint>
                        <address uri="vfs:file:///home/install/out?transport.vfs.Append=true"/>
                    </endpoint>
                </send>
            </sequence>
        </target>
    </clone>
</sequence>