Topic
  • 9 replies
  • Latest Post - ‏2013-08-22T02:14:19Z by lenisha
SystemAdmin
SystemAdmin
6772 Posts

Pinned topic Payload as a XML to system logs instead of String

‏2012-10-24T21:04:46Z |
Hi,

I have a use case that I have to send the payload xml message from request to system logs

Use-case 1:-
<xsl:variable name="Shyam" select="/*/*/*/*/node()"/>
<xsl:message dp:type="all" dp:priority="notice">
<xsl:copy-of select="$Shyam"/>
</xsl:message>

Output in System logs:
<firstname>Shyam</firstname>
<lastname>Soddoji</lastname>
Use-case 2:
According to my requirement I have to use context variable to cache the payload and use other xslt to retrieve the value and send payload to system log as XML format.
XSLT1:
<xsl:variable name="Shyam">
<xsl:copy-of select="/*/*/*/*/node()"/>
</xsl:variable>
<dp:set-variable name="'var://context/store/DATA'" value="$Shyam"/>

XSLT 2:
<xsl:variable name="bar" select="dp:variable('var://context/store/DATA')"/> OR <xsl:variable name="bar"> <xsl:copy-of select="dp:variable('var://context/store/DATA')"/></xsl:variable>
<xsl:message dp:type="all" dp:priority="notice">
<xsl:copy-of select="$bar"/>
</xsl:message>

Output in System logs:-
Shyam Soddoji

MyQuestion:- what I need to do in Use-case 2 to get the payload xml as xml in logs instead of string?

I can able to see complete payload xml in context variable var://context/store/DATA but it showing as a string in system logs.

Please advice me
Updated on 2012-10-30T16:58:57Z at 2012-10-30T16:58:57Z by SystemAdmin
  • HermannSW
    HermannSW
    4657 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2012-10-25T07:27:57Z  
    Hi,

    I get this in the log:
    
    03:09:10        all     error           4579953 request 9.152.201.158   0x80000001      mpgw (coproc2): <myXML>123</myXML>
    


    by
    
    $ echo 
    "<myXML>123</myXML>" | coproc2 mesg.xsl - http:
    //dp9-l3:2223 $ cat mesg.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:template match=
    "/"> <xsl:message dp:type=
    "all" dp:priority=
    "error"> <xsl:copy-of select=
    "."/> </xsl:message> </xsl:template>   </xsl:stylesheet> $
    


    I do not know your input, but from what you said it seems that "/*/*/*/*/node()" matches text nodes only from your input.
    Just try a shorter XPath expression to get the tags you want to see in the log.

    Please be aware that log is for informational purposes and messages get truncated at a certain length:
    http://www-01.ibm.com/support/docview.wss?uid=swg21447824

    Also logging is done on "best effort" basis.
    If box gets a spike in client requests logging will be dropped first (if needed) for ensuring correct transaction processing.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2012-10-25T13:24:26Z  
    • HermannSW
    • ‏2012-10-25T07:27:57Z
    Hi,

    I get this in the log:
    <pre class="jive-pre"> 03:09:10 all error 4579953 request 9.152.201.158 0x80000001 mpgw (coproc2): <myXML>123</myXML> </pre>

    by
    <pre class="jive-pre"> $ echo "<myXML>123</myXML>" | coproc2 mesg.xsl - http: //dp9-l3:2223 $ cat mesg.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:template match= "/"> <xsl:message dp:type= "all" dp:priority= "error"> <xsl:copy-of select= "."/> </xsl:message> </xsl:template> </xsl:stylesheet> $ </pre>

    I do not know your input, but from what you said it seems that "/*/*/*/*/node()" matches text nodes only from your input.
    Just try a shorter XPath expression to get the tags you want to see in the log.

    Please be aware that log is for informational purposes and messages get truncated at a certain length:
    http://www-01.ibm.com/support/docview.wss?uid=swg21447824

    Also logging is done on "best effort" basis.
    If box gets a spike in client requests logging will be dropped first (if needed) for ensuring correct transaction processing.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    thanks for input..
    is it possible to do by using context variables to achieve this ?

    my input is
    <firstname>Shyam</firstname>
    <lastname>Soddoji</lastname>

    I am expecting same output to system logs by using the context variable
    <firstname>Shyam</firstname>
    <lastname>Soddoji</lastname>

    In my previous post, I am able to achieve this by use-case1 but not with use-case2.

    I am looking to implement with use-case2 for re-usability purpose.
  • HermannSW
    HermannSW
    4657 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2012-10-26T22:40:11Z  
    thanks for input..
    is it possible to do by using context variables to achieve this ?

    my input is
    <firstname>Shyam</firstname>
    <lastname>Soddoji</lastname>

    I am expecting same output to system logs by using the context variable
    <firstname>Shyam</firstname>
    <lastname>Soddoji</lastname>

    In my previous post, I am able to achieve this by use-case1 but not with use-case2.

    I am looking to implement with use-case2 for re-usability purpose.
    Hi Shyam,

    I suspect, as said already above, that the level of "node()" in your XPath expression is just too deep.

    As you can see in the log, below two executions of stylesheet "shyam.xsl" result in the entry you want, and an entry which you seem to experience.
    For demonstration I combined your two XSLT parts in one stylesheet, see below.


    
    $ coproc2 shyam.xsl shyam.xml http:
    //dp6-l3:2223 $ coproc2 shyam.2.xsl shyam.xml http:
    //dp6-l3:2223 $ diff shyam.xsl shyam.2.xsl 10c10 <       <xsl:copy-of select=
    "/*/node()"/> --- >       <xsl:copy-of select=
    "/*/*/node()"/> $ $ cat shyam.xml <data> <firstname>Shyam</firstname> <lastname>Soddoji</lastname> </data> $ $ cat shyam.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 method=
    "xml"/>   <xsl:template match=
    "/"> <xsl:variable name=
    "input"> <xsl:copy-of select=
    "/*/node()"/> </xsl:variable>   <dp:set-variable name=
    "'var://context/store/DATA'" value=
    "$input"/>   <xsl:message dp:type=
    "all" dp:priority=
    "error"> <xsl:copy-of select=
    "dp:variable('var://context/store/DATA')"/> </xsl:message> </xsl:template>   </xsl:stylesheet> $
    


     
    Hermann<myXsltBlog/> <myXsltTweets/>
  • SystemAdmin
    SystemAdmin
    6772 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2012-10-30T16:58:57Z  
    • HermannSW
    • ‏2012-10-25T07:27:57Z
    Hi,

    I get this in the log:
    <pre class="jive-pre"> 03:09:10 all error 4579953 request 9.152.201.158 0x80000001 mpgw (coproc2): <myXML>123</myXML> </pre>

    by
    <pre class="jive-pre"> $ echo "<myXML>123</myXML>" | coproc2 mesg.xsl - http: //dp9-l3:2223 $ cat mesg.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:template match= "/"> <xsl:message dp:type= "all" dp:priority= "error"> <xsl:copy-of select= "."/> </xsl:message> </xsl:template> </xsl:stylesheet> $ </pre>

    I do not know your input, but from what you said it seems that "/*/*/*/*/node()" matches text nodes only from your input.
    Just try a shorter XPath expression to get the tags you want to see in the log.

    Please be aware that log is for informational purposes and messages get truncated at a certain length:
    http://www-01.ibm.com/support/docview.wss?uid=swg21447824

    Also logging is done on "best effort" basis.
    If box gets a spike in client requests logging will be dropped first (if needed) for ensuring correct transaction processing.

     
    Hermann<myXsltBlog/> <myXsltTweets/>
    I was using concat function to get multiple values output. that's the reason i saw as a string.
    but when I am using copy function for all values output as you mentioned. it's working as expected.

    Thanks a lot.
  • karthik999
    karthik999
    3 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2013-08-16T16:36:40Z  
    I was using concat function to get multiple values output. that's the reason i saw as a string.
    but when I am using copy function for all values output as you mentioned. it's working as expected.

    Thanks a lot.

    Hi..

    I have a similar situation but when my response is other than 200 the response should print in the syslog..Any help on this is greatly appreciated

     

    Thanks!

     

  • swlinn
    swlinn
    1348 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2013-08-16T16:45:29Z  

    Hi..

    I have a similar situation but when my response is other than 200 the response should print in the syslog..Any help on this is greatly appreciated

     

    Thanks!

     

    You can check your backside return code in the first action of your response rule by using retrieving the x-dp-response-code from the response header.

    <xsl:variable name="rc" select="dp:response-header('x-dp-response-code')"/>

    This assumes you have set your service property of "process backend errors" to enabled so your response rule will get the response instead of being directed to your error rule.  If you still need to do your error rule processing, you can also do a dp:reject

    Regards,
    Steve

  • karthik999
    karthik999
    3 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2013-08-20T14:16:23Z  
    • swlinn
    • ‏2013-08-16T16:45:29Z

    You can check your backside return code in the first action of your response rule by using retrieving the x-dp-response-code from the response header.

    <xsl:variable name="rc" select="dp:response-header('x-dp-response-code')"/>

    This assumes you have set your service property of "process backend errors" to enabled so your response rule will get the response instead of being directed to your error rule.  If you still need to do your error rule processing, you can also do a dp:reject

    Regards,
    Steve

    Hi..As per your suggestion i written an Xslt,but i am getting the error as " Unknown function - Name and number of arguments do not match any function signature in the static context - 'http://www.datapower.com/extensions:response-header'".

    Here is my xslt

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:str="http://exslt.org/strings" exclude-result-prefixes="dp str" extension-element-prefixes="dp">
        <xsl:output method="xml" indent="yes"/>
        <!--xsl:variable name="routing" select="document('local:///endpoint.xml')"/-->
        <xsl:template match="/">
            <!-- Get the response Code -->
            <xsl:variable name="ResponseCode" select="dp:response-header('x-dp-response-code')"/>
            <xsl:choose>
                <xsl:when test="$ResponseCode= '200 ok'">
                    <dp:accept/>
                </xsl:when>
                <xsl:otherwise>
                    <!--xsl:variable name="endpoint" select="$routing-->
                    <dp:set-variable name="'var://service/routing-url'" value=" 'https://192.168.100:9090/' "/>
                    <xsl:message dp:type="all" dp:priority="error">
                        <xsl:copy-of select="."/>
                    </xsl:message>
                    <dp:reject/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>

     

    And i have one more question while using the https as routing url do i need to use the variable 'var://service/routing-url-sslprofile

     

    Thanks !

    Karthik

  • swlinn
    swlinn
    1348 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2013-08-20T19:17:57Z  

    Hi..As per your suggestion i written an Xslt,but i am getting the error as " Unknown function - Name and number of arguments do not match any function signature in the static context - 'http://www.datapower.com/extensions:response-header'".

    Here is my xslt

    <?xml version="1.0" encoding="UTF-8"?>
    <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions" xmlns:str="http://exslt.org/strings" exclude-result-prefixes="dp str" extension-element-prefixes="dp">
        <xsl:output method="xml" indent="yes"/>
        <!--xsl:variable name="routing" select="document('local:///endpoint.xml')"/-->
        <xsl:template match="/">
            <!-- Get the response Code -->
            <xsl:variable name="ResponseCode" select="dp:response-header('x-dp-response-code')"/>
            <xsl:choose>
                <xsl:when test="$ResponseCode= '200 ok'">
                    <dp:accept/>
                </xsl:when>
                <xsl:otherwise>
                    <!--xsl:variable name="endpoint" select="$routing-->
                    <dp:set-variable name="'var://service/routing-url'" value=" 'https://192.168.100:9090/' "/>
                    <xsl:message dp:type="all" dp:priority="error">
                        <xsl:copy-of select="."/>
                    </xsl:message>
                    <dp:reject/>
                </xsl:otherwise>
            </xsl:choose>
        </xsl:template>
    </xsl:stylesheet>

     

    And i have one more question while using the https as routing url do i need to use the variable 'var://service/routing-url-sslprofile

     

    Thanks !

    Karthik

    Hi Karthik,

    I have to admit I'm scratching my head over your xsl as the error suggests it cannot find the extension function.  Your dp namespace and the use of the extension function look ok to me unless I'm just overlooking something very obvious.  What version firmware are you using?  The only thing I can think of is if you were doing a copy/paste into your code from some other filetype and somehow have some special character that is in your xsl but didn't get copies into your post above.

    As for setting the var://service/routing-url (much less the ssl-profile variable) in your otherwise clause is meaningless since you are doing a dp:reject.  When this stylesheet finishes processing, it will drive your error rule.  No backside processing (which would use the var://service/routing-url or routing-url-sslprofile) will be attempted.

    Regards,
    Steve

  • lenisha
    lenisha
    23 Posts

    Re: Payload as a XML to system logs instead of String

    ‏2013-08-22T02:14:19Z  
    • HermannSW
    • ‏2012-10-25T07:27:57Z
    Hi,

    I get this in the log:
    <pre class="jive-pre"> 03:09:10 all error 4579953 request 9.152.201.158 0x80000001 mpgw (coproc2): <myXML>123</myXML> </pre>

    by
    <pre class="jive-pre"> $ echo "<myXML>123</myXML>" | coproc2 mesg.xsl - http: //dp9-l3:2223 $ cat mesg.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:template match= "/"> <xsl:message dp:type= "all" dp:priority= "error"> <xsl:copy-of select= "."/> </xsl:message> </xsl:template> </xsl:stylesheet> $ </pre>

    I do not know your input, but from what you said it seems that "/*/*/*/*/node()" matches text nodes only from your input.
    Just try a shorter XPath expression to get the tags you want to see in the log.

    Please be aware that log is for informational purposes and messages get truncated at a certain length:
    http://www-01.ibm.com/support/docview.wss?uid=swg21447824

    Also logging is done on "best effort" basis.
    If box gets a spike in client requests logging will be dropped first (if needed) for ensuring correct transaction processing.

     
    Hermann<myXsltBlog/> <myXsltTweets/>

    @Herman

    "Also logging is done on "best effort" basis.
    If box gets a spike in client requests logging will be dropped first (if needed) for ensuring correct transaction processing."

    Is this feature documented somewhere and is it applicable to both <xsl:message> and Log action?

     

    Thank you