0
votes

I have created a ProxyService that involves service chaining where output from first service is used to iterate and make calls to second service. First I tried the following Proxy configuration:

    <?xml version="1.0" encoding="UTF-8"?>
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="ListingProxyService"
       transports="https,http"
       startOnLoad="true">
   <target>
      <inSequence>
         <log>
            <property name="sequence" value="IN SEQ LISTINGPROXY"/>
         </log>
        <property name="uri.var.apiUrl" value="https://api.srwd83.com" scope="default" type="STRING"/>
        <property name="uri.var.accessToken" value="9afc63fe80b7b770b1b2293af4f398c" scope="default" type="STRING"/>
        <property name="uri.var.userGuid" value="89A2530728201ABCE04400144FB7AE36" scope="default" type="STRING"/>
        <property xmlns:ns="http://org.apache.synapse/xsd" name="Authorization" expression="fn:concat('Bearer ', get-property('uri.var.accessToken'))" scope="transport" type="STRING"/>
         <log>
            <property name="sequence" value="IN SEQ GETLISTINGS REQUEST"/>
         </log>
         <send>
            <endpoint>
               <http method="get"
                     uri-template="{uri.var.apiUrl}/accountmanagement/listings/v1/seller/{uri.var.userGuid}"/>
            </endpoint>
         </send>
      </inSequence>
      <outSequence>
         <log level="full">
            <property name="sequence" value="OUT SEQ GETLISTINGS RESPONSE"/>
         </log>
         <xslt key="GetListingToCreateListingTransformation"/>
         <log level="full">
            <property name="sequence" value="OUT SEQ AFTER TRANSFORMATION"/>
         </log>      
         <iterate expression="//listings" preservePayload="true" attachPath="//listing" xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
         <target>
         <sequence>
            <log>
                <property name="sequence" value="OUT SEQ CREATE LISTING"/>
            </log>
            <send/>
        </sequence>
        </target>
        </iterate>       
      </outSequence>
   </target>
   <description/>
</proxy>

Here is the localEntry for transforming the payload:

<localEntry key="GetListingToCreateListingTransformation">
      <xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
                      xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
                      xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
                      version="2.0"
                      exclude-result-prefixes="xsl xsi soapenv">
         <xsl:output method="xml" version="1.0" encoding="UTF-8" indent="yes"/>
         <!-- Root template matcher --><xsl:template match="/">
            <listings>
               <xsl:for-each select="//soapenv:Envelope/soapenv:Body/jsonObject/listings/listing">
                  <xsl:call-template name="createListingTemplate">
                     <xsl:with-param name="listingparam" select="."/>
                  </xsl:call-template>
               </xsl:for-each>
            </listings>
         </xsl:template>
         <!-- Template to create listing request object --><xsl:template name="createListingTemplate">
            <xsl:param name="listingparam"/>
            <listing><xsl:value-of select="$listingparam/id"/></listing>
         </xsl:template>
      </xsl:stylesheet>
      <description>XSL used for transforming getListings output to a list of nodes that can be used for createListing operation.</description>
   </localEntry>

I am seeing that after inSequence call, the log entry just inside outSequence was dumping the Envelope properly. Here is the response payload from inSequence call:

2014-04-09 21:08:12,177 [-] [PassThroughMessageProcessor-11]  INFO ListingProxyService To: /services/ListingProxyService.ListingProxyServiceHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:ba858d67-3a42-4310-af7d-4add3cea4f27, Direction: request, sequence = IN SEQ LISTINGPROXY

2014-04-09 21:08:12,178 [-] [PassThroughMessageProcessor-11]  INFO ListingProxyService To: /services/ListingProxyService.ListingProxyServiceHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:ba858d67-3a42-4310-af7d-4add3cea4f27, Direction: request, sequence = IN SEQ GETLISTINGS REQUEST

2014-04-09 21:08:14,018 [-] [PassThroughMessageProcessor-12]  INFO ListingProxyService To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:858b292d-496e-4351-99e5-43ec8417e80f, Direction: response, sequence = OUT SEQ GETLISTINGS RESPONSE, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><jsonObject><listings><listing><id>1068540737</id><status>INACTIVE</status></listing><listing><id>1067213811</id><status>INACTIVE</status></listing><listing><id>1070845353</id><status>INACTIVE</status></listing><listing><id>522269067</id><status>INACTIVE</status></listing><listing><id>1070845354</id><status>INACTIVE</status></listing></listings></jsonObject></soapenv:Body></soapenv:Envelope>

2014-04-09 21:08:14,050 [-] [PassThroughMessageProcessor-12]  INFO ListingProxyService To: http://www.w3.org/2005/08/addressing/anonymous, WSAction: , SOAPAction: , MessageID: urn:uuid:858b292d-496e-4351-99e5-43ec8417e80f, Direction: response, sequence = OUT SEQ AFTER TRANSFORMATION, Envelope: <?xml version="1.0" encoding="utf-8"?><soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"><soapenv:Body><listings xmlns="http://ws.apache.org/ns/synapse"></listings></soapenv:Body></soapenv:Envelope>

But after transformation, I don't see proper values after transformation. If i transform using the xsl content seperately in an IDE, then its works fine. Its only through this flow it is not able to get handle to that Envelope from first call.

1
Replace //soapenv:Envelope/soapenv:Body/jsonObject/listings/listing with //jsonObject/listings/listing in your localEntry and check.Kasun Gajasinghe

1 Answers

1
votes

Your transformation must apply on the first child node of the body, xslt doesn't see nodes Envelope and Body