Topic
  • 13 replies
  • Latest Post - ‏2013-08-01T16:11:21Z by HermannSW
rdp87
rdp87
41 Posts

Pinned topic SOAP message validation using xslt wrt WSDL

‏2013-06-14T07:35:23Z |

Hi All,

I am trying to validate soap message with wsdl using dp:schema-validate function. I have extract the schema from wsdl and using that in dp:schema-validate function. But it is not working. The extracted xsd is expecting xml message as input and not soap message.

please help out if anyone faces similar issue.

Thanks....

  • SatheshSubramaniam
    SatheshSubramaniam
    12 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-14T08:33:18Z  

    can you specify  what is the error that exactly you are getting. because it should accept soap messages also.

    its exactly what datapower does for  "Validate Document via WSDL URL" for a validate action.

    Updated on 2013-06-14T08:39:27Z at 2013-06-14T08:39:27Z by SatheshSubramaniam
  • HermannSW
    HermannSW
    4657 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-14T21:38:07Z  

    can you specify  what is the error that exactly you are getting. because it should accept soap messages also.

    its exactly what datapower does for  "Validate Document via WSDL URL" for a validate action.

    I agree with Satesh that the best you can do is to use Validate action against WSDL URL.
    That does all the Schema Extraction and SOAP handling for you.


    Please do not try to extract the Schemata yourself, it may work in simple cases,
    but I have seen customer configs with hundreds of Schemata imported/included directly or indirectly.

    The best alternative I can think of if you really want to do it by dp:schema-validate is the following:

    • please install the WSDL and the Schemata needed on DataPower in a WSP service (if not already done)
    • as you may know, "http(s)://box:port/endpoint?WSDL" returns the WSDL published by DataPower (GET method on FSH needs to be enabled)
    • internally DataPower accesses the XSDs by "http(s)://box:port/endpoint.xsd1.xsd", "http(s)://box:port/endpoint.xsd2.xsd", ...
    • "http(s)://box:port/endpoint.xsd1.xsd" is the top level Schema
    • just validating like this does what you want, and DataPower WSDL publish deals with all the details for you:
      "dp:schema-validate('http(s)://box:port/endpoint.xsd1.xsd', $nodeset)"


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

    Updated on 2013-06-15T20:20:37Z at 2013-06-15T20:20:37Z by HermannSW
  • rdp87
    rdp87
    41 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-24T09:27:08Z  
    • HermannSW
    • ‏2013-06-14T21:38:07Z

    I agree with Satesh that the best you can do is to use Validate action against WSDL URL.
    That does all the Schema Extraction and SOAP handling for you.


    Please do not try to extract the Schemata yourself, it may work in simple cases,
    but I have seen customer configs with hundreds of Schemata imported/included directly or indirectly.

    The best alternative I can think of if you really want to do it by dp:schema-validate is the following:

    • please install the WSDL and the Schemata needed on DataPower in a WSP service (if not already done)
    • as you may know, "http(s)://box:port/endpoint?WSDL" returns the WSDL published by DataPower (GET method on FSH needs to be enabled)
    • internally DataPower accesses the XSDs by "http(s)://box:port/endpoint.xsd1.xsd", "http(s)://box:port/endpoint.xsd2.xsd", ...
    • "http(s)://box:port/endpoint.xsd1.xsd" is the top level Schema
    • just validating like this does what you want, and DataPower WSDL publish deals with all the details for you:
      "dp:schema-validate('http(s)://box:port/endpoint.xsd1.xsd', $nodeset)"


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

    Hi Hermann/Sathesh,

    Thanks for the input provided....I will try it out...one more information...can I get all validations error in one go using dp:schema-validate or just one error like we get when dp validates the request with wsdl(default functionality).

    Thanks...

  • HermannSW
    HermannSW
    4657 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-24T09:44:24Z  
    • rdp87
    • ‏2013-06-24T09:27:08Z

    Hi Hermann/Sathesh,

    Thanks for the input provided....I will try it out...one more information...can I get all validations error in one go using dp:schema-validate or just one error like we get when dp validates the request with wsdl(default functionality).

    Thanks...

    Hi,

    you will only get the first error,

    While it is not possible to generate all errors in all situations, getting all errors if possible would be a good enhancement request:
    http://www.ibm.com/developerworks/rfe/?PROD_ID=577


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

  • Jaango
    Jaango
    267 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-24T15:23:15Z  
    • HermannSW
    • ‏2013-06-24T09:44:24Z

    Hi,

    you will only get the first error,

    While it is not possible to generate all errors in all situations, getting all errors if possible would be a good enhancement request:
    http://www.ibm.com/developerworks/rfe/?PROD_ID=577


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

    Hi,

     

    Will dp:schema-validate function return the error message(even the first one)? It will either return the complete nodeset if the validation is success, otherwise an empty nodeset, right?

     

    Or using the above method, we can get schema validation errors?

  • HermannSW
    HermannSW
    4657 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-25T10:17:17Z  
    • Jaango
    • ‏2013-06-24T15:23:15Z

    Hi,

     

    Will dp:schema-validate function return the error message(even the first one)? It will either return the complete nodeset if the validation is success, otherwise an empty nodeset, right?

     

    Or using the above method, we can get schema validation errors?

    You are right, dp:schema-validate() returns a node-set, and empty node-set indicates validation failure.

    Details on schema validation errors appear in the log.

    In case of dp:schema-validate() you can lookup the error message in Probe as well.

    Below I did enable Probe on coproc2 service of dp2-l3 box.
    As you can see the 2nd tranbsform action (the one executing stylesheet "validate.xsl") gives the details:

     

    $ echo "<num>1.23</num>" | coproc2 validate.xsl - dp2-l3:2223 ; echo
    true
    $ echo "<num>1.2.3</num>" | coproc2 validate.xsl - dp2-l3:2223 ; echo
    false
    $
    $ cat float.xsd
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="num" type="xs:float"/>
    </xs:schema>
    $
    $ cat validate.xsl
    <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:template match="/">
        <xsl:variable name="result">
          <xsl:copy-of
            select="dp:schema-validate('http://9.152.93.14/float.xsd',.)"/>
        </xsl:variable>

        <xsl:value-of select="count($result/*) > 0"/>
      </xsl:template>
     
    </xsl:stylesheet>
    $

     

     

     

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

     

  • Jaango
    Jaango
    267 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-25T14:06:40Z  
    • HermannSW
    • ‏2013-06-25T10:17:17Z

    You are right, dp:schema-validate() returns a node-set, and empty node-set indicates validation failure.

    Details on schema validation errors appear in the log.

    In case of dp:schema-validate() you can lookup the error message in Probe as well.

    Below I did enable Probe on coproc2 service of dp2-l3 box.
    As you can see the 2nd tranbsform action (the one executing stylesheet "validate.xsl") gives the details:

     

    $ echo "<num>1.23</num>" | coproc2 validate.xsl - dp2-l3:2223 ; echo
    true
    $ echo "<num>1.2.3</num>" | coproc2 validate.xsl - dp2-l3:2223 ; echo
    false
    $
    $ cat float.xsd
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema">
      <xs:element name="num" type="xs:float"/>
    </xs:schema>
    $
    $ cat validate.xsl
    <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:template match="/">
        <xsl:variable name="result">
          <xsl:copy-of
            select="dp:schema-validate('http://9.152.93.14/float.xsd',.)"/>
        </xsl:variable>

        <xsl:value-of select="count($result/*) > 0"/>
      </xsl:template>
     
    </xsl:stylesheet>
    $

     

     

     

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

     

    Perfect. Thanks, Hermann.

     

    Can we get the error in xslt, may be using any service variable or extension variable?

  • HermannSW
    HermannSW
    4657 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-25T17:00:12Z  
    • Jaango
    • ‏2013-06-25T14:06:40Z

    Perfect. Thanks, Hermann.

     

    Can we get the error in xslt, may be using any service variable or extension variable?

    Sorry, no, because the error ends up in log only.

    If this is not for production use, but for development,  you may use the approach described in ths blog posting:
    https://www.ibm.com/developerworks/community/blogs/HermannSW/entry/reading_logtemp_default_log_xml_in_a_stylesheet17

     

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

  • Jaango
    Jaango
    267 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-26T10:24:28Z  
    • HermannSW
    • ‏2013-06-25T17:00:12Z

    Sorry, no, because the error ends up in log only.

    If this is not for production use, but for development,  you may use the approach described in ths blog posting:
    https://www.ibm.com/developerworks/community/blogs/HermannSW/entry/reading_logtemp_default_log_xml_in_a_stylesheet17

     

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

    Hermann,

    Looks like var://context/OUTPUT/_extension/error variable is getting set with the error message(from probe). However while accessing the same variable through stylesheet is returning nothing(accessing throgh dp:variable().

    from the online help

    This variable contains the error message, if any, from the last dp:transform(), dp:parse(), or dp:document() invocation. If the variable is empty, no error occurred. If an error occurs in any subsequent call to one of these functions, the existing error message, if any, will be overwritten.

  • HermannSW
    HermannSW
    4657 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-26T14:45:15Z  
    • Jaango
    • ‏2013-06-26T10:24:28Z

    Hermann,

    Looks like var://context/OUTPUT/_extension/error variable is getting set with the error message(from probe). However while accessing the same variable through stylesheet is returning nothing(accessing throgh dp:variable().

    from the online help

    This variable contains the error message, if any, from the last dp:transform(), dp:parse(), or dp:document() invocation. If the variable is empty, no error occurred. If an error occurs in any subsequent call to one of these functions, the existing error message, if any, will be overwritten.

    The enumeration you cited does not contain dp:schema-validate().


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

    Updated on 2013-06-26T14:45:38Z at 2013-06-26T14:45:38Z by HermannSW
  • Jaango
    Jaango
    267 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-26T16:37:13Z  
    • HermannSW
    • ‏2013-06-26T14:45:15Z

    The enumeration you cited does not contain dp:schema-validate().


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

    Hi Hermann,

     

    I checked using schema validate and it is coming in the probe. In the example you cited above, it should be there in the probe lens( after the execution trace section(context variable tab)

    I dont have connectivity now to give a screenshot.

     

    Even though it is available in that variable, I was not able to access using a stylesheet.

  • HermannSW
    HermannSW
    4657 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-06-26T21:00:00Z  
    • Jaango
    • ‏2013-06-26T16:37:13Z

    Hi Hermann,

     

    I checked using schema validate and it is coming in the probe. In the example you cited above, it should be there in the probe lens( after the execution trace section(context variable tab)

    I dont have connectivity now to give a screenshot.

     

    Even though it is available in that variable, I was not able to access using a stylesheet.

    Hi,

    it does not work with OUTPUT context, but with any other, and independent on whether Probe is enabled or disabled.

    See stylesheet below on how to do that, I did attach the service export, too:

    $ curl --data-binary "<num>1.23</num>" http://dp2-l3:3456
    true

    $ curl --data-binary "<num>1.2.3</num>" http://dp2-l3:3456
    false
    http://dp2-l3:3456/: cvc-simple-type 1: element num value '1.2.3' is not a valid instance of type {http://www.w3.org/2001/XMLSchema}float
    $
    $ cat exterr.xsl
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY LF "<xsl:text>&#10;</xsl:text>">
    ]>
    <xsl:stylesheet version="1."
      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:template match="/">
        <xsl:variable name="result">
          <xsl:copy-of
            select="dp:schema-validate('http://9.152.93.14/float.xsd',.)"/>
        </xsl:variable>

        <xsl:value-of select="count($result/*) > 0"/> &LF;
        <xsl:value-of select="dp:variable('var://context/ctx/_extension/error')"/> &LF;
      </xsl:template>
     
    </xsl:stylesheet>
    $

     

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

    Attachments

  • HermannSW
    HermannSW
    4657 Posts

    Re: SOAP message validation using xslt wrt WSDL

    ‏2013-08-01T16:11:21Z  
    • HermannSW
    • ‏2013-06-26T21:00:00Z

    Hi,

    it does not work with OUTPUT context, but with any other, and independent on whether Probe is enabled or disabled.

    See stylesheet below on how to do that, I did attach the service export, too:

    $ curl --data-binary "<num>1.23</num>" http://dp2-l3:3456
    true

    $ curl --data-binary "<num>1.2.3</num>" http://dp2-l3:3456
    false
    http://dp2-l3:3456/: cvc-simple-type 1: element num value '1.2.3' is not a valid instance of type {http://www.w3.org/2001/XMLSchema}float
    $
    $ cat exterr.xsl
    <!DOCTYPE xsl:stylesheet [
      <!ENTITY LF "<xsl:text>&#10;</xsl:text>">
    ]>
    <xsl:stylesheet version="1."
      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:template match="/">
        <xsl:variable name="result">
          <xsl:copy-of
            select="dp:schema-validate('http://9.152.93.14/float.xsd',.)"/>
        </xsl:variable>

        <xsl:value-of select="count($result/*) > 0"/> &LF;
        <xsl:value-of select="dp:variable('var://context/ctx/_extension/error')"/> &LF;
      </xsl:template>
     
    </xsl:stylesheet>
    $

     

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

    Just leaened that validate action error message gets stored in another local variable.

    Its value can be used eg. in an Error rule like this:

    $ cat msg.xsl
    <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:template match="/">
        <msg><xsl:copy-of select="dp:variable('var://local/_internal/ap_conformance/results_err_msg')"/></msg>
      </xsl:template>
     
    </xsl:stylesheet>
    $


    This is a sample return of the error rule:

    <msg>http://dp1-l3:38256/error: cvc-simple-type 1: element {http://example.com/stockquote}pricesymbol value 'abc1.23' is not a valid instance of type {http://www.w3.org/2001/XMLSchema}float</msg>


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

    Updated on 2013-08-01T16:14:06Z at 2013-08-01T16:14:06Z by HermannSW