I am not able to fetch Servicecallout response

Not applicable

Hi ,

I have created a proxy with no endpoint .Called a service using servicecallout(Inline request message) in request flow ,response from this service I am trying to fetch using extract variable(Extract Variables-res) and tried to display using assign message(Assign Message-Res),but I am not able see the data in final response.

Here are the details:

Proxy:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <APIProxy revision="1" name="ServiceCallOutCountries"> <Basepaths>/servicecalloutcountries</Basepaths> <ConfigurationVersion majorVersion="4" minorVersion="0"/> <CreatedAt>1477307794866</CreatedAt> <CreatedBy>nvraghavendra254@gmail.com</CreatedBy> <Description/> <DisplayName>ServiceCallOutCountries</DisplayName> <LastModifiedAt>1478860271272</LastModifiedAt> <LastModifiedBy>nvraghavendra254@gmail.com</LastModifiedBy> <Policies> <Policy>Assign-Message-Res</Policy> <Policy>Extract-Variables-res</Policy> <Policy>Message-Logging-1</Policy> <Policy>ServiceCallout-GetBaasToken</Policy> </Policies> <ProxyEndpoints> <ProxyEndpoint>default</ProxyEndpoint> </ProxyEndpoints> <Resources/> <Spec/> <TargetServers/> <TargetEndpoints/> <validate>false</validate> </APIProxy>

Service callout (Inline request message):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ServiceCallout name="ServiceCallout-GetBaasToken"> <DisplayName>Inline request message</DisplayName> <Request variable="authenticationRequest"/> <Response>GeocodingResponse</Response> <Timeout>30000</Timeout> <HTTPTargetConnection> <URL>http://www.thomas-bayer.com/sqlrest/CUSTOMER/13</URL> </HTTPTargetConnection> </ServiceCallout>

Extract variable(Extract Variables-res):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables name="Extract-Variables-res"> <DisplayName>Extract Variables-res</DisplayName> <Source>GeocodingResponse</Source> <XMLPayload> <Namespaces> <Namespace prefix="xlink">http://www.w3.org/1999/xlink</Namespace> </Namespaces> <Variable name="firstname" type="string"> <XPath>/xlink:CUSTOMER/xlink:FIRSTNAME</XPath> </Variable> </XMLPayload> </ExtractVariables>

Assign message(Assign-Message-Res):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-Res"> <DisplayName>Assign Message-Res</DisplayName> <Properties/> <Copy source="response"> <Payload/> </Copy> <AssignVariable> <Name>name</Name> <Value>firstname</Value> </AssignVariable> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <AssignTo createNew="false" transport="http" type="response"/> <Set> <Payload> <Tamatar>{firstname}</Tamatar> <Aloo>{firstname}</Aloo> </Payload> </Set> </AssignMessage>

Could you please help me on this .

Solved Solved
0 6 501
1 ACCEPTED SOLUTION

nmallesh
Participant V

Hi @veeraraghavendra,

Please find the solution for the above issue - (cross - verified)

default.xml -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Service-Callout</Name>
            </Step>
            <Step>
                <Name>XSL-Transform</Name>
            </Step>
            <Step>
                <Name>Extract-Variables</Name>
            </Step>
            <Step>
                <Name>Assign-Message</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPProxyConnection>
        <BasePath>/extract-variables</BasePath>
        <Properties/>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="noroute"/>
</ProxyEndpoint>

Service Callout Policy -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout">
    <DisplayName>Service Callout</DisplayName>
    <Properties/>
    <Request variable="authenticationRequest"/>
    <Response>GeocodingResponse</Response>
    <Timeout>30000</Timeout>
    <HTTPTargetConnection>
        <URL>http://www.thomas-bayer.com/sqlrest/CUSTOMER/18</URL>
    </HTTPTargetConnection>
</ServiceCallout>

XSL Transform Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="XSL-Transform">
    <DisplayName>XSL Transform</DisplayName>
    <Properties/>
    <Source>request</Source>
    <ResourceURL>xsl://XSL-Transform-1.xsl</ResourceURL>
    <Parameters ignoreUnresolvedVariables="true"/>
    <OutputVariable/>
</XSL>

apiproxy/resources/xsl/XSL-Transform-1.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="*">
        <xsl:element name="{local-name(.)}">
            <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="@*">
        <xsl:attribute name="{local-name(.)}">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

Extract Variables Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables">
    <DisplayName>Extract Variables</DisplayName>
    <Properties/>
    <Source>GeocodingResponse</Source>
    <XMLPayload>
        <Variable name="firstname" type="string">
            <XPath>/CUSTOMER/FIRSTNAME</XPath>
        </Variable>
    </XMLPayload>
    <VariablePrefix>customerresponse</VariablePrefix>
</ExtractVariables>

Assign Message Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message">
    <DisplayName>Assign Message</DisplayName>
    <Properties/>
    <Copy source="response">
        <Payload/>
    </Copy>
    <AssignVariable>
        <Name>name</Name>
        <Ref>customerresponse.firstname</Ref>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
    <Set>
        <Payload>
            <Tamatar>{name}</Tamatar>
            <Aloo>{name}</Aloo>
        </Payload>
    </Set>
</AssignMessage>

Let me know if you don't get the desired results.

Hope this helps, thank you!

View solution in original post

6 REPLIES 6

nmallesh
Participant V

@veeraraghavendra

The following endpoint gives HTTP Status 404 - Resource not found

http://www.thomas-bayer.com/sqlrest/CUSTOMER/13

Hi, Please use this 'http://www.thomas-bayer.com/sqlrest/CUSTOMER/18' .It is working for other than 13 ,I have tried with other numbers.

Shall get back to you!

Kindly add the code snippet in code tab for readability.

nmallesh
Participant V

Hi @veeraraghavendra,

Please find the solution for the above issue - (cross - verified)

default.xml -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ProxyEndpoint name="default">
    <Description/>
    <FaultRules/>
    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>Service-Callout</Name>
            </Step>
            <Step>
                <Name>XSL-Transform</Name>
            </Step>
            <Step>
                <Name>Extract-Variables</Name>
            </Step>
            <Step>
                <Name>Assign-Message</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>
    <PostFlow name="PostFlow">
        <Request/>
        <Response/>
    </PostFlow>
    <Flows/>
    <HTTPProxyConnection>
        <BasePath>/extract-variables</BasePath>
        <Properties/>
        <VirtualHost>default</VirtualHost>
        <VirtualHost>secure</VirtualHost>
    </HTTPProxyConnection>
    <RouteRule name="noroute"/>
</ProxyEndpoint>

Service Callout Policy -

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="Service-Callout">
    <DisplayName>Service Callout</DisplayName>
    <Properties/>
    <Request variable="authenticationRequest"/>
    <Response>GeocodingResponse</Response>
    <Timeout>30000</Timeout>
    <HTTPTargetConnection>
        <URL>http://www.thomas-bayer.com/sqlrest/CUSTOMER/18</URL>
    </HTTPTargetConnection>
</ServiceCallout>

XSL Transform Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<XSL async="false" continueOnError="false" enabled="true" name="XSL-Transform">
    <DisplayName>XSL Transform</DisplayName>
    <Properties/>
    <Source>request</Source>
    <ResourceURL>xsl://XSL-Transform-1.xsl</ResourceURL>
    <Parameters ignoreUnresolvedVariables="true"/>
    <OutputVariable/>
</XSL>

apiproxy/resources/xsl/XSL-Transform-1.xsl

<?xml version="1.0" encoding="utf-8"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
    <xsl:output method="xml" indent="yes"/>
    <xsl:template match="*">
        <xsl:element name="{local-name(.)}">
            <xsl:apply-templates select="@* | node()"/>
        </xsl:element>
    </xsl:template>
    <xsl:template match="@*">
        <xsl:attribute name="{local-name(.)}">
            <xsl:value-of select="."/>
        </xsl:attribute>
    </xsl:template>
</xsl:stylesheet>

Extract Variables Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables">
    <DisplayName>Extract Variables</DisplayName>
    <Properties/>
    <Source>GeocodingResponse</Source>
    <XMLPayload>
        <Variable name="firstname" type="string">
            <XPath>/CUSTOMER/FIRSTNAME</XPath>
        </Variable>
    </XMLPayload>
    <VariablePrefix>customerresponse</VariablePrefix>
</ExtractVariables>

Assign Message Policy

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message">
    <DisplayName>Assign Message</DisplayName>
    <Properties/>
    <Copy source="response">
        <Payload/>
    </Copy>
    <AssignVariable>
        <Name>name</Name>
        <Ref>customerresponse.firstname</Ref>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
    <Set>
        <Payload>
            <Tamatar>{name}</Tamatar>
            <Aloo>{name}</Aloo>
        </Payload>
    </Set>
</AssignMessage>

Let me know if you don't get the desired results.

Hope this helps, thank you!

Many Many thanks again .It is working now.Got some more knowledge on Extractvar,Assignmessage.