WebSphere Application Server & Liberty

WebSphere Application Server & Liberty

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only

Variables set in xslt using apim:setvariable are not available in invoke action

  • 1.  Variables set in xslt using apim:setvariable are not available in invoke action

    Posted Tue December 03, 2024 09:24 AM

    Hello Team, 

    I have created the XSLT to read the xml file from gateway and able to create the URL from the file but while accessing the framed URL in invoke action it's showing as undefined need your suggestion on how to take this further, I have attached the screenshots of the code and logs.

    Initially I tried using the variables in invoke action but they're not accessible getting error as undefined, so added the set variable action and tried using even though same issue , your help  is much appreciated.

    <xsl:stylesheet version="1.0"   xmlns:xsl="http://www.w3.org/1999/XSL/Transform"   xmlns:dp="http://www.datapower.com/extensions"   xmlns:func="http://exslt.org/functions"   xmlns:apim="http://www.ibm.com/apimanagement"   xmlns:apigw="http://www.ibm.com/xmlns/datapower/2017/11/apigateway"   exclude-result-prefixes="dp func apim apigw"   extension-element-prefixes="dp func apim apigw">
    	<xsl:import href="local:/isp/policy/apim.custom.xsl"/>  
    	  <xsl:template  match="/">
    	    <xsl:message dp:priority="error">
           Started 02 with xslt
    		</xsl:message>		
          <xsl:variable name="resourceConfigFile" select="document('local:///apic/commonMapping/resConfigMap.xml')" />
          <xsl:variable name="clientID" select="apigw:get-variable('client.app.id')"/>  
          <xsl:variable name="uri" select="apigw:get-variable('request.uri')"/>
    <xsl:variable name="path" select="apigw:get-variable('api.root')"/>
          <xsl:variable name="backendURL">
            <xsl:copy-of select="$resourceConfigFile/resConfigMaps/resource[resOperation='providers']/resURL" />
          </xsl:variable>
    <xsl:variable name="reqPathHdrs" select="apigw:get-variable('request.path')"/>
    <xsl:variable name="reqQuerystr" select="apigw:get-variable('request.querystring')"/>
     <xsl:variable name="pathParams">
            <!-- Extract Path parameter from input '/' -->
                    <xsl:value-of select="substring-after(substring-after($reqPathHdrs, '/'), '/')" />
          </xsl:variable>
    <xsl:variable name="backendURL">
            <xsl:copy-of select="$resourceConfigFile/resConfigMaps/resource[resOperation=$pathParams]/resURL" />
          </xsl:variable>
    <xsl:variable name="allCurrHdrs" select="apigw:all-headers('message')"/>
      <!-- parms  -->
    <xsl:call-template name="apim:setVariable">
          <xsl:with-param name="varName" select="'parms'" />
          <xsl:with-param name="value" select="$reqQuerystr" />
          <xsl:with-param name="action" select="'set'" />
        </xsl:call-template>
       
        <xsl:call-template name="apim:setVariable">
          <xsl:with-param name="varName" select="'serviceEndpoint'" />
          <xsl:with-param name="value" select="$backendURL" />
          <xsl:with-param name="action" select="'set'" />
        </xsl:call-template>
        
    	   <xsl:message dp:priority="error">
    reqpathdrs=<xsl:copy-of select="$pathParams"/>
    reqqryhdrs=<xsl:copy-of select="$reqQuerystr"/>
           clientid=<xsl:value-of select="$clientID"/> 
    	   firsturi=<xsl:value-of select="$uri"/>
    path = <xsl:value-of select="$path"/>
           backendurl=<xsl:value-of select="$backendURL"/>
          getContextURL <xsl:value-of select="apim:getVariable('serviceEndpoint')" />
          getContextparms <xsl:value-of select="apim:getVariable('parms')" />
    		</xsl:message>
          </xsl:template>
    	 
    </xsl:stylesheet>


    <xsl:call-template name="apim:setVariable">
          <xsl:with-param name="varName" select="'parms'" />
          <xsl:with-param name="value" select="$reqQuerystr" />
          <xsl:with-param name="action" select="'set'" />
        </xsl:call-template>

    tried using apigw also but same 

    Logs displayed the URL which declared and used in console
    Created Variables in set var actions later used in Invoke action


    ------------------------------
    mahesh n
    ------------------------------