Friday, July 25, 2014

Proxying VFS file system to HTTP with WSO2 ESB or API Manager

I ran into a very tiny issue today when I was trying to proxy a file system to an http backend using WSO2 ESB.  It would be the same situation with WSO2 AM proxies.  I know, this seems like a little bit of an obscure scenario.  And, there is excellent documentation already available on this feature here, here and here.

The Symptoms

Let's say that you're adding a custom proxy for vfs -> https.  You've already enabled vfs in your axis2.xml file.  You've created a custom proxy with the vfs properties.  You've pointed the file at your endpoint with a send mediator.  Yet, the backend is not receiving the file at all!  It will be picked up, and placed in the vfs error directory.  Mysterious.

The Solution

There is a property necessary for the outbound endpoint handling a vfs file that isn't often necessary with http to http proxies.  The type of the document with vfs does not default to soap, as it does for http input.  It must be assigned manually!  This is laid out in the examples, but it's not apparent.  Here is the property that is probably missing for you:

<definitions xmlns="http://ws.apache.org/ns/synapse">
    <proxy name="StockQuoteProxy" transports="vfs">
        <parameter name="transport.vfs.FileURI">file:///home/user/test/in</parameter> <!--CHANGE-->
        <parameter name="transport.vfs.ContentType">text/xml</parameter>
        <parameter name="transport.vfs.FileNamePattern">.*\.xml</parameter>
        <parameter name="transport.PollInterval">15</parameter>
        <parameter name="transport.vfs.MoveAfterProcess">file:///home/user/test/original</parameter> <!--CHANGE-->
        <parameter name="transport.vfs.MoveAfterFailure">file:///home/user/test/original</parameter> <!--CHANGE-->
        <parameter name="transport.vfs.ActionAfterProcess">MOVE</parameter>
        <parameter name="transport.vfs.ActionAfterFailure">MOVE</parameter>
        <target>
            <endpoint>
                <address format="soap12" uri="http://localhost:9000/services/SimpleStockQuoteService"/>
            </endpoint>
            <outSequence>
                <property name="transport.vfs.ReplyFileName"
                          expression="fn:concat(fn:substring-after(get-property('MessageID'), 'urn:uuid:'), '.xml')"
                          scope="transport"/>
                <property action="set" name="OUT_ONLY" value="true"/>
                <send>
                    <endpoint>
                        <address uri="vfs:file:///home/user/test/out"/> <!--CHANGE-->
                    </endpoint>
                </send>
            </outSequence>
        </target>
        <publishWSDL uri="file:repository/samples/resources/proxy/sample_proxy_1.wsdl"/>
    </proxy>
</definitions>

This format="soap12" (or soap11) is necessary for the message to be constructed properly for a soap endpoint.  If you miss it, the message can't be sent.  It's just a small property, and it's not always necessary... so it's easy to miss.  

Cheers, Y'all. 

No comments:

Post a Comment