Powered By Blogger

Sep 28, 2014

Removing additional namespace prefixes in the SOAP Fault using xslt


As some of you all know there is a limitation with AXIOM where is generates additional namespace prefixes inside the SOAP Fault. In order to get rid of the issue you can include a namespace prefix to the fault message generates from the Fault Mediator before sending back. You can easily do this by using an XSLT mediator. Please refer the proxy configuration and the xslt as a sample. 


TestProxy


<proxy xmlns="http://ws.apache.org/ns/synapse" name="TestProxy" transports="https,http" statistics="disable" trace="disable" startOnLoad="true"> 

    <target> 
        <inSequence> 
            <makefault version="soap11" response="true"> 
                <code xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/" value="soap11Env:VersionMismatch"/> 
                <reason value="Test the SOAP Message"/> 
                <role/> 
                <detail expression="/*[local-name()='Envelope']/*[local-name()='Body']/*"/> 
            </makefault> 
            <xslt key="prefixSet" source="//detail/child::node()"/> 
            <send/> 
        </inSequence> 
    </target> 
    <description/> 

</proxy> 



prefixSet.xslt 


<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:ns0="http://some.data" version="1.0"> 

        <xsl:output omit-xml-declaration="yes" indent="yes"></xsl:output> 
        <xsl:strip-space elements="*"></xsl:strip-space> 
        <xsl:template match="node()|@*"> 
            <xsl:copy> 
                <xsl:apply-templates select="node()|@*"></xsl:apply-templates> 
            </xsl:copy> 
        </xsl:template> 
        <xsl:template match="*"> 
            <xsl:element name="ns0:{name()}" namespace="http://some.data"> 
                <xsl:copy-of select="namespace::*"></xsl:copy-of> 
                <xsl:apply-templates select="node()|@*"></xsl:apply-templates> 
            </xsl:element> 
        </xsl:template> 
    </xsl:stylesheet> 

This transformation applies for the fault message and includes in the OMElement created, and provides a response with a predefined namespace prefix as follows.



<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">

   <soapenv:Body>
      <soapenv:Fault>
         <faultcode xmlns:soap11Env="http://schemas.xmlsoap.org/soap/envelope/">soap11Env:VersionMismatch</faultcode>
         <faultstring>Test the SOAP Message</faultstring>
         <detail>
            <ns0:someData xmlns:ns0="http://some.data">
               <ns0:blaData/>
            </ns0:someData>
         </detail>
      </soapenv:Fault>
   </soapenv:Body>

</soapenv:Envelope>



No comments:

Post a Comment