Topic
10 replies Latest Post - ‏2013-12-28T16:11:18Z by HermannSW
mtz
mtz
38 Posts
ACCEPTED ANSWER

Pinned topic Accessing datapower XML Management interface from within a stylesheet

‏2013-12-19T16:43:15Z |

Hi,

I found a posting with same title on developer works to access xml management interface from within my stylesheet which I am using on a transform action in xmlfw service.

Here is how xslt looks like:


<xsl:stylesheet version=
"1.0"
  xmlns:xsl=
"http://www.w3.org/1999/XSL/Transform"
  xmlns:dp=
"http://www.datapower.com/extensions"
  extension-element-prefixes=
"dp"
>
  <xsl:output omit-xml-declaration=
"yes" />
    
  <xsl:variable name=
"FirmwareVersion">
    <env:Envelope xmlns:env=
"http://schemas.xmlsoap.org/soap/envelope/">
      <env:Body>
        <dp:request domain=
"default"
                    xmlns:dp=
"http://www.datapower.com/schemas/management">
          <dp:get-status class=
"FirmwareVersion"/>
        </dp:request>
      </env:Body>
    </env:Envelope>
  </xsl:variable>
 
  <xsl:variable name=
"pwd64" select=
"dp:encode('soma:secret','base-64')"/>
  <xsl:variable name=
"basicAuth" select=
"concat('Basic ',$pwd64)"/>
 
  <xsl:template match=
"/*">
    <xsl:variable name=
"httpHeaders">
      <header name=
"Content-Type">application/soap+xml</header>
      <header name=
"Authorization"><xsl:value-of select=
"$basicAuth"/></header>
    </xsl:variable>
 
    <xsl:variable name=
"result"
                  select=
"dp:soap-call('https://127.0.0.1:5550/service/mgmt/current',
                                       $FirmwareVersion
/*,
                                       'xslt-ssl',
                                       0,
                                       '',
                                       $httpHeaders/*
                                      )"
    />

    <xsl:copy-of select="$result"/>
  </xsl:template>

</xsl:stylesheet>

 

I am firing a plain xml using 'send a test message' to the datapower service that contains stylesheet with exact same config as posted above (the only change is instead of local host:5550, I have given <eth2>:5550 since this where our xml mgmnt interface is defined while I am firing the request through GUI which is defined on eth1) but I am not getting any response. 

Could someone let me know as to how should my request message look like? I tried firing a soap message as well with empty header n body but didn't get any response either.

 

Thanks,

Mohit

  • kenhygh
    kenhygh
    873 Posts
    ACCEPTED ANSWER

    Re: Accessing datapower XML Management interface from within a stylesheet

    ‏2013-12-19T20:37:53Z  in response to mtz

    You cannot just copy code from the internet and expect it to do something without looking at it, understanding it, and adapting it to your needs.

    For example, I seriously doubt that you have a userid 'soma' with a password of 'secret' authorized to perform administration tasks.

    • HermannSW
      HermannSW
      3145 Posts
      ACCEPTED ANSWER

      Re: Accessing datapower XML Management interface from within a stylesheet

      ‏2013-12-19T22:54:37Z  in response to kenhygh

      Hi Mohit,

      I agree with Ken.

      I did describe ALL steps needed in this blog posting (including which user to create):
      https://www.ibm.com/developerworks/community/blogs/HermannSW/entry/accessing_xml_management_interface_from_within_a_stylesheet38

      Please follow the steps, and it will work (best try the provided example first, when it works, modify to your needs).


      Hermann<myXsltBlog/> <myXsltTweets/> <myCE/> <myFrameless/>

    • mtz
      mtz
      38 Posts
      ACCEPTED ANSWER

      Re: Accessing datapower XML Management interface from within a stylesheet

      ‏2013-12-20T12:14:55Z  in response to kenhygh

      Hi Ken,

      No I didn't just copy and paste the code from somewhere on the internet; I pasted it from one of Hermann's post only on developer works. And yes, I have my own user id and password instead of soma and secret.

      My needs and requirements are entirely different and since I have used soma multiple times but never made a call from within the service, so I wanted to test the same sample xslt for once that is given above.

      Hermann,

      I tested with the above code and the only changes that I made were my userId:pwd combination (which already has access on DP) and the call in the xslt was made on eth2:5550 instead of localhost:5550 as this is where our xml management interface is defined. I fired the request using 'Send a test message' option in datapower but I am not getting any response. Probe is also not showing anything.

       

      Thanks,

      Mohit

      • HermannSW
        HermannSW
        3145 Posts
        ACCEPTED ANSWER

        Re: Accessing datapower XML Management interface from within a stylesheet

        ‏2013-12-23T13:41:45Z  in response to mtz

        Hi Mohit,

        I did redefine XML management interface to only listen on mgt0 interface and made my stylesheet go against mgt0:5550.
        Everything works.

        So please just take the stylesheet from my blog posting "as is" and then just change username, password and ip address.
        Then try it with that stylesheet.

        Have you used the user you specify in stylesheet to access XML management interface successfully from external?

        Please set loglevel to debug (and perhaps enable internal logging) and look where/why the xmlmgmt call fails.


        Hermann<myXsltBlog/> <myXsltTweets/> <myCE/> <myFrameless/>

        Updated on 2013-12-23T13:43:29Z at 2013-12-23T13:43:29Z by HermannSW
        • mtz
          mtz
          38 Posts
          ACCEPTED ANSWER

          Re: Accessing datapower XML Management interface from within a stylesheet

          ‏2013-12-25T15:03:54Z  in response to HermannSW

          Hi Hermann,

          I was facing issues that day due to some problems with "send a test message" option it seems. It worked fine with soapUI.

          Currently, I am developing a service which will capture the domain that have probes enabled and loop through each of those domains to get the services where probe is enabled. Now I am putting a condition that if probe is enabled for 3 or more services for a domain, then only disable all of them else leave it like that.

          I am facing two issues here:

          1. For disabling the probes for a domain, I need to use modify-config where the syntax is such that I need to give debug mode off for mpgw, wsp and xmlfw separately. How do i do that since my output is displaying multiple service names which aren't categorized into service types? Is it possible to do it in a single shot for a domain?

          2. Another thing is I am not able to do get-config for multiple domains for which I am getting the probe enabled status. I have to hard ciode the domain name to do get-config else I am getting authentication failure.

          Here is my xslt code:

          <xsl:stylesheet version="1.0"
          xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions"
          extension-element-prefixes="dp">
          <xsl:output omit-xml-declaration="yes" />
          <xsl:variable name="DomainStatus">
          <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
          <env:Body>
          <dp:request domain="default" 
          xmlns:dp="http://www.datapower.com/schemas/management">
          <dp:get-status class="DomainStatus"/>
          </dp:request>
          </env:Body>
          </env:Envelope>
          </xsl:variable>
          <xsl:variable name="pwd64" select="dp:encode('user:pwd','base-64')" />
          <xsl:variable name="basicAuth" select="concat('Basic ',$pwd64)" />
          <xsl:template match="/*">
          <xsl:variable name="httpHeaders">
          <header name="Content-Type">application/soap+xml</header>
          <header name="Authorization">
          <xsl:value-of select="$basicAuth" />
          </header>
          </xsl:variable>
          <xsl:variable name="result"
          select="dp:soap-call('https://eth2:5550/service/mgmt/current',$DomainStatus/*,'somaTest',0,'',$httpHeaders/*)" />
          <xsl:variable name="domainProbe">
              <xsl:for-each select="$result/*[local-name()= 'Envelope']/*[local-name()= 'Body']/*[local-name()= 'response']/*[local-name()= 'status']/DomainStatus">
                             <xsl:if test="(ProbeEnabled) ='on'">
          <DomainDetails>  <xsl:text>&#10;</xsl:text>
          <Domain><xsl:value-of select = "Domain"/> </Domain> <xsl:text>&#10;</xsl:text>
          <ProbeStatus><xsl:value-of select = "ProbeEnabled"/> </ProbeStatus> <xsl:text>&#10;</xsl:text> 
          </DomainDetails>  <xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
          </xsl:if>
          </xsl:for-each>
          </xsl:variable>
          <xsl:variable name="ObjectStatus">
          <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
          <env:Body>
          <dp:request domain="abc" 
          xmlns:dp="http://www.datapower.com/schemas/management">
          <dp:get-config/> </dp:request>
          </env:Body>
          </env:Envelope>
          </xsl:variable>
          <xsl:variable name="result1"
          select="dp:soap-call('https://eth2:5550/service/mgmt/current',$ObjectStatus/*,'somaTest',0,'',$httpHeaders/*)" />
           <xsl:variable name="serviceProbe">
           <domain>
           <xsl:for-each select="$result1/*[local-name()= 'Envelope']/*[local-name()= 'Body']/*[local-name()= 'response']/*[local-name()= 'config']/*">
          <xsl:if test="./DebugMode[text()='on']">
          <ServiceName>
          <xsl:value-of select="./*/.."/> 
          </ServiceName>
          </xsl:if>
          </xsl:for-each>
          </domain>
          </xsl:variable>
          <!--  <xsl:copy-of select="$serviceProbe"/> -->
           
          <xsl:if test="count($serviceProbe/domain/ServiceName) &gt; 2">
          <xsl:copy-of select="$serviceProbe"/></xsl:if>
           
           </xsl:template>
          </xsl:stylesheet>

           

          Thanks,

          Mohit

          • mtz
            mtz
            38 Posts
            ACCEPTED ANSWER

            Re: Accessing datapower XML Management interface from within a stylesheet

            ‏2013-12-25T15:08:50Z  in response to mtz

            Slight correction in the above code:

            I am doing

            <xsl:if test="./DebugMode[text()='on']">
            <ServiceName>
            <xsl:value-of select="./*/../@name"/>                 <!--   <xsl:value-of select="./*/.."/> was tp test the output    -->
            </ServiceName>
            </xsl:if>

             

            Thanks,

            Mohit

            • mtz
              mtz
              38 Posts
              ACCEPTED ANSWER

              Re: Accessing datapower XML Management interface from within a stylesheet

              ‏2013-12-26T16:40:00Z  in response to mtz

              Hi Hermann,

              PFB the enhanced code where I am getting the output as:

              <domain>&lt;WSGateway>some1&lt;WSGateway>
              &lt;XMLFirewallService>some2&lt;XMLFirewallService>
              &lt;XMLFirewallService>some3&lt;XMLFirewallService>
              </domain>

              Here the problem is &lt; isn't getting displayed as <. I require this since the output of value-of select="name()" is a text value which needs to be displayed as an xml tag in order to do further processing on that. I tried using hex value of less than in a variable and then display but it's still coming as &lt; This issue isn't happening with > (&gt;). Also, CDATA is throwing internal error when changing xslt on datapower. I am sure this is the probl;em with xslt parser that we have on our appliance but then what is the workaround?

               

              CODE:

              <xsl:stylesheet version="1.0"
              xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions"
              extension-element-prefixes="dp">
              <xsl:output omit-xml-declaration="yes" />
              <xsl:variable name="DomainStatus">
              <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
              <env:Body>
              <dp:request domain="default" 
              xmlns:dp="http://www.datapower.com/schemas/management">
              <dp:get-status class="DomainStatus"/>
              </dp:request>
              </env:Body>
              </env:Envelope>
              </xsl:variable>
              <xsl:variable name="pwd64" select="dp:encode('id:pwd','base-64')" />
              <xsl:variable name="basicAuth" select="concat('Basic ',$pwd64)" />
              <xsl:template match="/*">
              <xsl:variable name="httpHeaders">
              <header name="Content-Type">application/soap+xml</header>
              <header name="Authorization">
              <xsl:value-of select="$basicAuth" />
              </header>
              </xsl:variable>
              <xsl:variable name="result"
              select="dp:soap-call('https://eth2:5550/service/mgmt/current',$DomainStatus/*,'somaTest',0,'',$httpHeaders/*)" />
              <xsl:variable name="domainProbe">
                  <xsl:for-each select="$result/*[local-name()= 'Envelope']/*[local-name()= 'Body']/*[local-name()= 'response']/*[local-name()= 'status']/DomainStatus">
                                 <xsl:if test="(ProbeEnabled) ='on'">
              <DomainDetails>  <xsl:text>&#10;</xsl:text>
              <Domain><xsl:value-of select = "Domain"/> </Domain> <xsl:text>&#10;</xsl:text>
              <ProbeStatus><xsl:value-of select = "ProbeEnabled"/> </ProbeStatus> <xsl:text>&#10;</xsl:text> 
              </DomainDetails>  <xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
              </xsl:if>
              </xsl:for-each>
              </xsl:variable>
              <xsl:variable name="ObjectStatus">
              <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
              <env:Body>
              <dp:request domain="soasdm" 
              xmlns:dp="http://www.datapower.com/schemas/management">
              <dp:get-config/> </dp:request>
              </env:Body>
              </env:Envelope>
              </xsl:variable>
              <!-- <xsl:variable name="lessThan" select="'&#x3C;'"/> -->
              <!--  <xsl:variable name="lessThan" select="'<'"/> -->
              <xsl:variable name="result1"
              select="dp:soap-call('https://eth2:5550/service/mgmt/current',$ObjectStatus/*,'somaTest',0,'',$httpHeaders/*)" />
               <xsl:variable name="serviceProbe">
               <domain>
               <xsl:for-each select="$result1/*[local-name()= 'Envelope']/*[local-name()= 'Body']/*[local-name()= 'response']/*[local-name()= 'config']/*">
              <xsl:if test="DebugMode='on'">
              <xsl:value-of select="concat('&lt;',name(),'&gt;')"/> 
              <xsl:value-of select="@name"/>
              <xsl:value-of select="concat('&lt;',name(),'&gt;')"/> 
               
              <!-- <xsl:value-of  disable-output-escaping = "yes" select="$lessThan"/>  -->  <xsl:text>&#10;</xsl:text> 
              </xsl:if>
              </xsl:for-each>
              </domain>
              </xsl:variable>
               
               <xsl:copy-of select="$serviceProbe"/> 
               <xsl:value-of select="count($serviceProbe/domain/*)"/>
              <!-- <xsl:for-each select="$serviceProbe/domain">
              <xsl:value-of select="XMLFirewallService"/></xsl:for-each> -->
               
              <!--   <xsl:if test="count($serviceProbe/domain) &gt; 1">
              <xsl:copy-of select="$serviceProbe"/></xsl:if> -->
               
               </xsl:template>
              </xsl:stylesheet>

               

              Thanks,

              Mohit

              • HermannSW
                HermannSW
                3145 Posts
                ACCEPTED ANSWER

                Re: Accessing datapower XML Management interface from within a stylesheet

                ‏2013-12-26T18:56:35Z  in response to mtz

                Hi Mohit,

                please construct your solution with just SOMA calls first, no stylesheet.

                If everything works, then integrate all into a stylesheet.

                You can determine the domains of a box easily by doing "get-fonfig" for "default" domain:

                $ doSoma admin get-config.xml dp1-l3:5550 -s | xpath++ "//*[name()='Domain']/@name" -
                Enter host password for user 'admin':

                -------------------------------------------------------------------------------
                name="39130"
                -------------------------------------------------------------------------------
                name="39977"
                -------------------------------------------------------------------------------
                name="40255"
                -------------------------------------------------------------------------------
                name="40593"
                -------------------------------------------------------------------------------
                name="default"
                $
                $ cat get-config.xml
                <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
                  <env:Body>
                    <dp:request domain="default"
                      xmlns:dp="http://www.datapower.com/schemas/management">
                      <dp:get-config/>
                    </dp:request>
                  </env:Body>
                </env:Envelope>
                $

                 

                Hermann<myXsltBlog/> <myXsltTweets/> <myCE/> <myFrameless/>

                • This reply was deleted by mtz 2013-12-28T06:53:35Z. Reason for deletion: resolved
                  • This reply was deleted by mtz 2013-12-28T06:53:49Z. Reason for deletion: resolved
                    • This reply was deleted by mtz 2013-12-28T06:53:55Z. Reason for deletion: resolved
                      • This reply was deleted by mtz 2013-12-28T06:54:03Z. Reason for deletion: resolved
                • mtz
                  mtz
                  38 Posts
                  ACCEPTED ANSWER

                  Re: Accessing datapower XML Management interface from within a stylesheet

                  ‏2013-12-28T06:58:45Z  in response to HermannSW

                  Hi Hermann,

                  I have deleted my previous posts as I got solution to most of them. CDATA problem got resolved using another stylesheet and it's working fine on DP. I am stuck at one thing though.

                  How do i pass domain name dynamically in get-config? If I do get-config, then there might be out of mem issue due to large number of domains and configurations within. So, first I am making a soma call do check domain status and from there, whichever domain has probe enabled will be passed as a parameter to get-config but it doesn't seem to be working.

                  It's only working when I am hard coding the domain name. Here is the code snippet which is causing issue:

                   

                  <!--  this is working as expected -->

                   
                  <xsl:variable name="DomainStatus">
                  <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
                  <env:Body>
                  <dp:request domain="default" 
                  xmlns:dp="http://www.datapower.com/schemas/management">
                  <dp:get-status class="DomainStatus"/>
                  </dp:request>
                  </env:Body>
                  </env:Envelope>
                  </xsl:variable>
                  <xsl:variable name="pwd64" select="dp:encode('id:pwd','base-64')" />
                  <xsl:variable name="basicAuth" select="concat('Basic ',$pwd64)" />
                  <xsl:template match="/*">
                  <xsl:variable name="httpHeaders">
                  <header name="Content-Type">application/soap+xml</header>
                  <header name="Authorization">
                  <xsl:value-of select="$basicAuth" />
                  </header>
                  </xsl:variable>
                  <xsl:variable name="result"
                  select="dp:soap-call('https://eth2:5550/service/mgmt/current',$DomainStatus/*,'somaTest',0,'',$httpHeaders/*)" />
                  <xsl:variable name="domainProbe">
                  <ProbeStatus>
                      <xsl:for-each select="$result/*[local-name()= 'Envelope']/*[local-name()= 'Body']/*[local-name()= 'response']/*[local-name()= 'status']/DomainStatus">
                                     <xsl:if test="(ProbeEnabled) ='on'">
                  <DomainDetails>  <xsl:text>&#10;</xsl:text>
                  <Domain><xsl:value-of select = "Domain"/> </Domain> <xsl:text>&#10;</xsl:text>
                  <ProbeStatus><xsl:value-of select = "ProbeEnabled"/> </ProbeStatus> <xsl:text>&#10;</xsl:text> 
                  </DomainDetails>  <xsl:text>&#10;</xsl:text> <xsl:text>&#10;</xsl:text>
                  </xsl:if>
                  </xsl:for-each>
                  </ProbeStatus>
                  </xsl:variable>
                  <!-- xsl:copy-of select="$domainProbe"/ -->

                  <!-- this is the trouble part -->

                  <xsl:variable name="ObjectStatus">
                  <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/">
                  <env:Body>
                  <dp:request domain="$domainProbe/ProbeStatus/DomainDetails/Domain" 
                  xmlns:dp="http://www.datapower.com/schemas/management">
                  <dp:get-config/> </dp:request>
                  </env:Body>
                  </env:Envelope>
                  </xsl:variable>

                  Thanks,

                  Mohit

                  Updated on 2013-12-28T07:19:12Z at 2013-12-28T07:19:12Z by mtz