Frage

I have a Proxy webservice in Mule where I am using XSLT transformation response to modify the response ... It works fine and response is somewhat like :-

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <retrieveDataResponse xmlns="http://services.test.com/schema/MainData/V1">
         <Response>The Data retrieved from the Database</Response>
         <Id>3</Id>
         <Name>anir</Name>
         <Age>44</Age>
         <Designation>SE</Designation>
      </retrieveDataResponse>
   </soap:Body>
</soap:Envelope> 

Now the issue is when any SOAP fault occurs say UNMARSHAL_ERROR, The response do not shows the SOAP fault ... it is somewhat like :-

 <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
   <soap:Body>
      <retrieveDataResponse xmlns="http://services.test.com/schema/MainData/V1">
         <Response/>
      </retrieveDataResponse>
   </soap:Body>
</soap:Envelope> 

But it should show the SOAP Fault ... If I remove XSLT from response it works fine and shows the response with SOAP Fault .. but if I place XSLT again it's not showing fault in response .. How can I modify my XSLT so that it handles the SOAP fault ..... My XSLT is as follows :-

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:md1="http://services.test.com/schema/MainData/V1"
    exclude-result-prefixes="md1">
    <xsl:template match="/">
        <soap:Envelope>
            <soap:Body>
                <retrieveDataResponse xmlns="http://services.test.com/schema/MainData/V1">
                    <Response>
                        <xsl:value-of
                            select="soap:Envelope/soap:Body/md1:retrieveDataResponse/md1:Response" />
                    </Response>
                    <xsl:if
                        test="soap:Envelope/soap:Body/md1:retrieveDataResponse/md1:Response='The Data retrieved from the Database'">
                        <Id>
                            <xsl:value-of
                                select="soap:Envelope/soap:Body/md1:retrieveDataResponse/md1:Id" />
                        </Id>
                        <Name>
                            <xsl:value-of
                                select="soap:Envelope/soap:Body/md1:retrieveDataResponse/md1:Name" />
                        </Name>
                        <Age>
                            <xsl:value-of
                                select="soap:Envelope/soap:Body/md1:retrieveDataResponse/md1:Age" />
                        </Age>
                        <Designation>
                            <xsl:value-of
                                select="soap:Envelope/soap:Body/md1:retrieveDataResponse/md1:Designation" />
                        </Designation>
                    </xsl:if>
                </retrieveDataResponse>
            </soap:Body>
        </soap:Envelope>
    </xsl:template>
</xsl:stylesheet>

Please Help ... How to modify my XSLT to catch SOAP Fault

War es hilfreich?

Lösung

I would design the XSLT more modular and then take it step by step:

<xsl:stylesheet version="1.0"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"
    xmlns:md1="http://services.test.com/schema/MainData/V1"
    xmlns="http://services.test.com/schema/MainData/V1"
    exclude-result-prefixes="md1">
    <xsl:template match="/">
        <xsl:apply-templates />
    <xsl:template>

    <xsl:template match="soap:Envelope">
        <soap:Envelope>
                <xsl:apply-templates />
            </soap:Envelope>
    </xsl:template>

    <xsl:template match="soap:Body">
          <soap:Body>
             <xsl:apply-templates />
          </soap:Body>
    </xsl:template>

    <xsl:template match="retrieveDataResponse">
        <retrieveDataResponse>
                    <Response>
                        <xsl:value-of select="Response" />
                    </Response>
                    <xsl:if test="Response='The Data retrieved from the Database'">
                        <Id>
                            <xsl:value-of select="Id" />
                        </Id>
                        <Name>
                            <xsl:value-of select="Name" />
                        </Name>
                        <Age>
                            <xsl:value-of select="Age" />
                        </Age>
                        <Designation>
                            <xsl:value-of select="Designation" />
                        </Designation>
                    </xsl:if>
                </retrieveDataResponse>
    </xsl:template>

    <xsl:template match="*">
        <xsl:copy-of select="." />
    </xsl:template>

</xsl:stylesheet>

A little verbose, but you get the idea. It doesn't do a lot of transformation. Typically you would strip off the envelope so processing becomes easier. if you want to suppress a specific element, you always can use <xsl:template match="prefix:element" /> this would suppress all output of such an element. Recommended reading.

Let us know how it goes!

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top