Topic
2 replies Latest Post - ‏2011-10-21T15:01:20Z by meaton78
meaton78
meaton78
25 Posts
ACCEPTED ANSWER

Pinned topic MIME response with no end tag through MPGW

‏2011-10-18T17:20:32Z |
We have a service provider that is sending a MIME response, however, it is missing the end MIME tag. This is resulting in XML parsing errors. We have them setup through a MPGW with XML as the response type. While that response code is being researched and fixed, do I have any options on the DataPower side? I can't change the Response Type as we have some services that use response rules in the MPGW. I'd prefer not to create a second MPGW if I can avoid it.

I've tried removing the Content-Type header, but then I get errors about unexpected characters at the beginning of the message where the MIME tag begins. Is there any way to change the response type for this one message, or anything clever that I can temporarily put in place so testing isn't held up? Thanks
Updated on 2011-10-21T15:01:20Z at 2011-10-21T15:01:20Z by meaton78
  • HermannSW
    HermannSW
    4238 Posts
    ACCEPTED ANSWER

    Re: MIME response with no end tag through MPGW

    ‏2011-10-18T18:10:31Z  in response to meaton78
    Hi,

    > We have a service provider that is sending a MIME response, however, it is missing the end
    > MIME tag. This is resulting in XML parsing errors.
    that is expected for XML or SOAP response type.

    > We have them setup through a MPGW with XML as the response type. While that response code
    > is being researched and fixed, do I have any options on the DataPower side?
    Yes, see below.

    > I can't change the Response Type as we have some services that use response rules in the MPGW.
    What is your response type?

    > I'd prefer not to create a second MPGW if I can avoid it.
    >
    Sorry, repairing broken web services requires Transform Binary stylesheets, and those require Non-XML type.
    The workarounds work best if proxying your request eg. through an XML FW with passthru request and Non-XML response type.
    See this slide for an example:
    http://www-01.ibm.com/support/docview.wss?uid=swg27019119&aid=1#page=6
    > I've tried removing the Content-Type header, but then I get errors about unexpected characters
    > at the beginning of the message where the MIME tag begins.
    Yes, because MIME preamble, or at least the MIME boundary, make a Non-XML response.

    > Is there any way to change the response type for this one message,
    Sorry, response type is for all responses of a service.

    > or anything clever that I can temporarily put in place so testing isn't held up?
    See broken Web Service slide above.

    In addition, based on stylesheet Signed2Related.xsl from this recent slide:
    http://www-01.ibm.com/support/docview.wss?uid=swg27022979&aid=3#page=24
    (please lookup that webcast and the previous one for details)

    Stylesheet fixMissingMIMEend.xsl (also attached) does what you seem to need for UTF-8 encoded responses.
    Other respone encodings can be handled, too.

    
    $ tail broken.mime ------=_Part_2_12345 Content-Type: application/pkcs7-signature; name=smime.p7s; smime-type=signed-data Content-Transfer-Encoding: base64 Content-Disposition: attachment; filename=
    "smime.p7s" Content-Description: S/MIME Cryptographic Signature   This should be base64 sign part data. Missing intentionally 
    
    for qouted-printable demo.   end boundary and epilogue missing intentionally, too. $ $ coproc2 fixMissingMIMEend.xsl broken.mime http:
    //dp5-l3:2224 -s | tail -4 end boundary and epilogue missing intentionally, too. ------=_Part_2_12345-- epilogue; end boundary has been added $ $ $ tail -4 Qp.mime Missing intentionally 
    
    for qouted-printable demo. ------=_Part_2_12345--   epilogue, gets ignored. $ $ coproc2 fixMissingMIMEend.xsl Qp.mime http:
    //dp5-l3:2224 -s | tail -4 Missing intentionally 
    
    for qouted-printable demo. ------=_Part_2_12345--   epilogue, gets ignored. $ $ $ cat fixMissingMIMEend.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"/> <dp:output-mapping href=
    "store:///pkcs7-convert-input.ffd" type=
    "ffd"/>   <xsl:template match=
    "/"> <!-- base64 encode Non-XML input data --> <xsl:variable name=
    "input64" select=
    "dp:binary-encode(/object/message/node())"/>   <!-- base64 decode; results in input in 
    
    case of valid UTF-8 --> <xsl:variable name=
    "input" select=
    "dp:decode($input64, 'base-64')"/>   <!-- determine bounday --> <xsl:variable name=
    "boundary" select=
    "substring-before( substring-after($input,
    '&#10;--'), 
    '&#13;&#10;' )
    "/>   <xsl:variable name=
    "endBoundary" select=
    "concat('--',$boundary,'--&#13;&#10;')"/>   <xsl:variable name=
    "fixed"> <xsl:value-of select=
    "$input"/>   <xsl:
    
    if test=
    "not(contains($input,$endBoundary))"> <xsl:value-of select=
    "concat($endBoundary, 
    'epilogue; end boundary has been added&#13;&#10;')
    "/> </xsl:if> </xsl:variable>   <object> <message> <xsl:copy-of select=
    "dp:binary-decode(dp:encode($fixed,'base-64'))"/> </message> </object> </xsl:template> </xsl:stylesheet> $
    

     
    Hermann<myXsltBlog/>
    • meaton78
      meaton78
      25 Posts
      ACCEPTED ANSWER

      Re: MIME response with no end tag through MPGW

      ‏2011-10-21T15:01:20Z  in response to HermannSW
      Thanks Hermann,

      That was exactly what I needed. I ended up creating a XMLFirewall as suggested and did the processing in there. I did notice however, that I could use the transform action in my MPGW and use the non-XML feature in there. All I needed to do was remove the Content-Type header first in the stylesheet.

      However, to make it a bit more supportable, I decided to move the processing out into the XMLFirewall. Thanks again