wso2vfssmooks

WSO2 Remove Blank Spaces from beginning of text file


I have written a WSO2 integration which calls an API, grabs the properties I want from that API call, puts together a payload, passes that payload to a smooks mediator, which right pads each value with an appropriate number of spaces, and then writes to a .txt file. Everything is working GREAT - except - the beginning of each row in my .txt file is pre-pended with several blank spaces. So the file looks like this:

     value value value value
     value value value value

rather than this:

value value value value
value value value value

the portion of my smooks generator that pads each element looks like this:

<ftl:freemarker applyOnElement="Employee180">
     <ftl:template>
          <!--${.vars["Employee180"].RecordType?right_pad(3)}${.vars["Employee180"].BlankSpace1?right_pad(1)}${.vars["Employee180"].ContractNumber?right_pad(6)}${.vars["Employee180"].BlankSpace2?right_pad(1)}${.vars["Employee180"].EmployeeIDNumber?right_pad(9)?replace("-","")}${.vars["Employee180"].BlankSpace3?right_pad(1)}${.vars["Employee180"].EmployeeName?right_pad(24)}${.vars["Employee180"].DateOfBirth?right_pad(10)}${.vars["Employee180"].BlankSpace4?right_pad(1)}${.vars["Employee180"].DateOfEmployment?right_pad(10)}${.vars["Employee180"].BlankSpace5?right_pad(1)}${.vars["Employee180"].Sex?right_pad(1)}${.vars["Employee180"].BlankSpace6?right_pad(8)}${.vars["Employee180"].SocialSecurityNumber?right_pad(9)}${.vars["Employee180"].BlankSpace7?right_pad(133)}${.vars["Employee180"].BenefitEventDate?right_pad(10)}${.vars["Employee180"].BlankSpace8?right_pad(5)}${.vars["Employee180"].BenefitEventReason?right_pad(4)}${.vars["Employee180"].BlankSpace9?right_pad(3)}${'\r\n'}-->
     </ftl:template>
</ftl:freemarker>

I'm not sure if that's what's making the beginning spaces though, or if it's the actual creation of the .txt. file. For that I'm doing this:

<property expression="fn:concat(get-property('ContractNumber'), get-property('DATE_FOR_FILE'), '.txt')" name="transport.vfs.ReplyFileName" scope="transport" type="STRING" xmlns:ns2="http://org.apache.synapse/xsd"/>
    <property name="OUT_ONLY" scope="default" type="STRING" value="true"/>
    <property name="messageType" scope="axis2" type="STRING" value="text/plain"/>
    <send>
        <endpoint name="FileEpr">
            <address uri="vfs:file:///O:/myTestFolder/WSO2 Testing?transport.vfs.Append=true">
                <suspendOnFailure>
                    <initialDuration>-1</initialDuration>
                    <progressionFactor>1</progressionFactor>
                </suspendOnFailure>
                <markForSuspension>
                    <retriesBeforeSuspension>0</retriesBeforeSuspension>
                </markForSuspension>
            </address>
        </endpoint>
    </send>

Any ideas what might be putting those initial spaces in my file? Or even some handy terms to start googling? No luck so far in my searches.


Solution

  • Try removing the whitespaces from your Freemarker template:

    <ftl:freemarker applyOnElement="Employee180">
         <ftl:template>
    <!--${.vars["Employee180"].RecordType?right_pad(3)}${.vars["Employee180"].BlankSpace1?right_pad(1)}${.vars["Employee180"].ContractNumber?right_pad(6)}${.vars["Employee180"].BlankSpace2?right_pad(1)}${.vars["Employee180"].EmployeeIDNumber?right_pad(9)?replace("-","")}${.vars["Employee180"].BlankSpace3?right_pad(1)}${.vars["Employee180"].EmployeeName?right_pad(24)}${.vars["Employee180"].DateOfBirth?right_pad(10)}${.vars["Employee180"].BlankSpace4?right_pad(1)}${.vars["Employee180"].DateOfEmployment?right_pad(10)}${.vars["Employee180"].BlankSpace5?right_pad(1)}${.vars["Employee180"].Sex?right_pad(1)}${.vars["Employee180"].BlankSpace6?right_pad(8)}${.vars["Employee180"].SocialSecurityNumber?right_pad(9)}${.vars["Employee180"].BlankSpace7?right_pad(133)}${.vars["Employee180"].BenefitEventDate?right_pad(10)}${.vars["Employee180"].BlankSpace8?right_pad(5)}${.vars["Employee180"].BenefitEventReason?right_pad(4)}${.vars["Employee180"].BlankSpace9?right_pad(3)}${'\r\n'}-->
         </ftl:template>
    </ftl:freemarker>