How to change the name of the received files

Previous Next

When receiving a message that contains MTOM encoded binary data, USoft creates a unique file name by default and saves the binary data with that name.

If the response when calling an MTOM web service contains binary data in the SOAP message (base64 encoded) then USoft cannot automatically tell where the binary data is, to save it using a uniquely generated file name. In this case the user must create a transformation that will generate custom file names. Using this transformation, binary data in the response message will be saved regardless of the encoding (base64 in the SOAP message or MTOM attachments).

You can overrule the unique file name(s) created by USoft with a user-defined file name(s) based on the data in the received XML message by specifying a transformation (XSL). The transformation will be automatically applied by USoft to the received XML message.The transformation must produce the same result as the received message, except that for the binary element it must add a usoft-mtom processing instruction containing the path to the file:

<?usoft-mtom path="path to the file"?>

 

For example, if the received message is:

<MTOMResponse xmlns="http://www.test.com/TestMtom/v1">

<result>

<FileName>SomeFileName.txt</FileName>

<BinaryData></BinaryData>

</result>

</MTOMResponse>

and you want to retrieve the file name from the <FileName> element, the transformation must look like the following:

'<?xml version="1.0" encoding="windows-1252"?>

<xsl:stylesheet   version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://www.test.com/TestMtom/v1">

<xsl:output method="xml" encoding="windows-1252" omit-xml-declaration="no"/>

<xsl:template match="*|@*|comment()|processing-instruction()|text()">

  <xsl:copy>    

<xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()"/>  

</xsl:copy>

</xsl:template>

<xsl:template match="ns1: BinaryData">

<xsl:copy>

<xsl:processing-instruction name="usoft-mtom"><xsl:text>path="</xsl:text><xsl:value-of select="../ns1:FileName"/>

<xsl:text>.txt"</xsl:text></xsl:processing-instruction>

</xsl:copy>

</xsl:template>

</xsl:stylesheet>'

The resulting XML will be

<?xml version="1.0" encoding="windows-1252"?><MTOMResponse xmlns="http://www.test.com/TestMtom/v1">

<result>

<FileName>SomeFileName.txt</FileName>

<BinaryData><?usoft-mtom path="SomeFileName.txt.txt"?></BinaryData>

</result>

</MTOMResponse>

To specify the transformation to the web service component change the constructor method as follows:

1.Change the Physical Name to

this=new com.usoft.WebServiceClient.WSClient()

this.setEndpointURL((U):0)

this.setInputFolder((U):1)

this.setOutputFolder((U):2)

this.setOutputFileNameTransformation((U):3)

2.Add a new input parameter with name 'transformation' and type String to the parameter list.
3.Change the constructor SQL to:

SELECT  'http://www.test.com/TestingMtom'

,       'C:/Input/'

,       'C:/Output'

,

  '<?xml version="1.0" encoding="windows-1252"?>

  <xsl:stylesheet   version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns1="http://www.test.com/TestMtom/v1">

  <xsl:output method="xml" encoding="windows-1252" omit-xml-declaration="no"/>

  <xsl:template match="*|@*|comment()|processing-instruction()|text()">

    <xsl:copy>    

  <xsl:apply-templates select="*|@*|text()|comment()|processing-instruction()"/>  

  </xsl:copy>

  </xsl:template>

  <xsl:template match="ns1: BinaryData">

  <xsl:copy>

  <xsl:processing-instruction name="usoft-mtom"><xsl:text>path="</xsl:text><xsl:value-of select="../ns1:FileName"/>

  <xsl:text>.txt"</xsl:text></xsl:processing-instruction>

  </xsl:copy>

  </xsl:template>

  </xsl:stylesheet>'