Topic
5 replies Latest Post - ‏2011-12-13T17:04:24Z by HermannSW
msmps
msmps
138 Posts
ACCEPTED ANSWER

Pinned topic How to accept xml and non xml in same service

‏2011-12-12T20:09:49Z |
we have a mpgw. Its request type is xml. so far it is good. now we have requirement came to use the non xml message thru the same service.
So I changed the request type to non-xml. with this change the xml requests starts failing. In Datapower it is good, but to the backend, the xml goes as null message.

So how to achieve this in single service
Updated on 2011-12-13T17:04:24Z at 2011-12-13T17:04:24Z by HermannSW
  • HermannSW
    HermannSW
    2818 Posts
    ACCEPTED ANSWER

    Re: How to accept xml and non xml in same service

    ‏2011-12-13T13:48:42Z  in response to msmps
    > we have a mpgw. Its request type is xml. so far it is good. now we have requirement came to use the non xml message thru the same service.
    > So I changed the request type to non-xml. with this change the xml requests starts failing. In Datapower it is good, but to the backend, the xml goes as null message.
    >
    > So how to achieve this in single service
    >
    There is currently no way to dispatch XML and Non-XML requests on the same service without side effects.

    In order to process Non-XML requests the service request type must be Non-XML.
    But as you have experienced that missed the XML parsing step for the XML requests.

    What you can do is to try a dp:parse(_).
    If the dp:parse(_) succeeds, continue with XML processing, otherwise do your Non-XML processing
    (please see webcasts swg27022977 and swg27022979 on "Non-XML Data Processing in WebSphere DataPower SOA Appliances Stylesheets").

    The side effect is, that an unmaskable error gets logged for parsing of Non-XML documents, which may be acceptable or not depending on your production environment policies.
    (you may want to have your IBM Sales Representative create an Enhancement Request (ER) on this)

    This is the error that gets logged:
    
    08:40:32      xslt    error           21104   request         0x80a002b2      mpgw (coproc2nonxml): dp:parse() error: illegal character 
    't' at offset 0 of *dp:parse*
    


    You may want to use isXML.xsl (also attached) as a basis:
    
    $ echo 
    "<a/>" | coproc2 isXML.xsl - http:
    //dp6-l3:2224; echo Input is XML. $ echo 
    "<a>123</a>" | coproc2 isXML.xsl - http:
    //dp6-l3:2224; echo Input is XML. $ echo 
    "<a>123 /a>" | coproc2 isXML.xsl - http:
    //dp6-l3:2224; echo Input is not XML. $ $ cat isXML.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" > <dp:input-mapping  href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/>   <xsl:output omit-xml-declaration=
    "yes" /> <xsl:template match=
    "/"> <xsl:variable name=
    "input64" select=
    "dp:binary-encode(/object/message/node())"/>   <xsl:variable name=
    "xml"> <xsl:copy-of select=
    "dp:parse($input64,'base-64')"/> </xsl:variable>   <xsl:text>Input is </xsl:text> <xsl:
    
    if test=
    "not($xml/*)"><xsl:text>not </xsl:text></xsl:if> <xsl:text>XML.</xsl:text>   </xsl:template> </xsl:stylesheet> $
    


    Hermann<myXsltBlog/>

    Attachments

    • swlinn
      swlinn
      1327 Posts
      ACCEPTED ANSWER

      Re: How to accept xml and non xml in same service

      ‏2011-12-13T14:35:26Z  in response to HermannSW
      >> The side effect is, that an unmaskable error gets logged for parsing of Non-XML documents, which may be acceptable or not depending on
      >> your production environment policies.
      >> (you may want to have your IBM Sales Representative create an Enhancement Request (ER) on this)

      One thing you can do to avoid these errors in your log is to check at a minimum that the content starts with a <. For example, if you didn't do the base64 encoding.

      <xsl:variable name="xmlInput">
           <xsl:if test="starts-with($input, '&lt;')">
               <xsl:copy-of select="dp:parse($input)" />
          </xsl:if>
      </xsl:variable>
      


      In either case, whether you skip the dp:parse or if dp:parse fails, you can determine if the document is xml if the xmlInput variable is empty. You could always do this check on the raw input and then integrate it into Hermann's base64 encoded example. Then the log records you will get are truly malformed XML where you would want the log record.

      Regards,
      Steve
      Updated on 2014-03-25T03:05:32Z at 2014-03-25T03:05:32Z by iron-man
    • msmps
      msmps
      138 Posts
      ACCEPTED ANSWER

      Re: How to accept xml and non xml in same service

      ‏2011-12-13T14:43:14Z  in response to HermannSW
      Thanks Hermann.
      that worked.
      But have an issue , the non xml is also an xml but it is encoded.
      After binary transformation. I'm using dp:decode($input,'url') in xsl.
      but it failed.
      Input is
      %3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3CINPUT%3E%3CMSG%3E%3C!%5BCDATA%5B00073%5D%5D%3E%3C%2FMSG%3E%3C%2FINPUT%3E%0A
      
      Updated on 2014-03-25T03:05:28Z at 2014-03-25T03:05:28Z by iron-man
      • msmps
        msmps
        138 Posts
        ACCEPTED ANSWER

        Re: How to accept xml and non xml in same service

        ‏2011-12-13T14:45:51Z  in response to msmps
        I'm trying to convert non-xml to xml
        • HermannSW
          HermannSW
          2818 Posts
          ACCEPTED ANSWER

          Re: How to accept xml and non xml in same service

          ‏2011-12-13T17:04:24Z  in response to msmps
          Hi Robert,

          your url-encoded string does not encode XML, corrected everything works.

          Using xpath++ tool shows the output of dp:decode(_,'url').
          As you can see one of the [ character 5B encodings misses its percent prefix.
          And the CDATA exclamation before it (%21) is missing:
          
          $ echo 
          "<u>%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3CINPU T%3E%3CMSG%3E%3C5BCDATA%5B00073%5D%5D%3E%3C%2FMSG%3E%3C%2FINPUT%3E%0A</u>
          " | xpa th++ 
          "dp:decode(.,'url')" - &​lt;?xml version=
          "1.0" encoding=
          "UTF-8"?>&​lt;INPUT>&​lt;MSG>&​lt;5BCDATA[00073]]&g t;&​lt;/MSG>&​lt;/INPUT>   $
          


          After inserting "%21%" decoding gives you serialized XML:
          
          $ echo 
          "<u>%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3CINPU T%3E%3CMSG%3E%3C%21%5BCDATA%5B00073%5D%5D%3E%3C%2FMSG%3E%3C%2FINPUT%3E%0A</u>
          " | xpath++ 
          "dp:decode(.,'url')" - &​lt;?xml version=
          "1.0" encoding=
          "UTF-8"?>&​lt;INPUT>&​lt;MSG>&​lt;![CDATA[00073]]&g t;&​lt;/MSG>&​lt;/INPUT>   $
          


          dp:parse() is able to process that:
          
          $ echo 
          "<u>%3C%3Fxml%20version%3D%221.0%22%20encoding%3D%22UTF-8%22%3F%3E%3CINPU T%3E%3CMSG%3E%3C%21%5BCDATA%5B00073%5D%5D%3E%3C%2FMSG%3E%3C%2FINPUT%3E%0A</u>
          " | xpath++ 
          "dp:parse(dp:decode(.,'url'))" - <INPUT><MSG>00073</MSG></INPUT> $
          


           
          Hermann<myXsltBlog/>