Topic
14 replies Latest Post - ‏2012-10-27T08:10:42Z by JagadishVemugunta
JagadishVemugunta
JagadishVemugunta
37 Posts
ACCEPTED ANSWER

Pinned topic Data Power unable to set the correct ContentType on MTOM response messages

‏2012-10-18T02:01:09Z |
Service has been exposed to accept SOAP with attachments

1) Client sends an MTOM request to the service. The content type comes correctly as

Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_806D8FD2D542EDCC2C1199332890718; type="application/xop+xml"; start="0.urn:uuid:806D8FD2D542EDCC2C1199332890719@apache.org"; start-info="application/soap+xml"; action="urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b"

2) The service calls a backend application. The backend application sends a positive response with content type as

Content-Type text/xml; charset=UTF-8
3) The service sends the positive response to client with Content type as

Content-Type application/soap+xml; charset=UTF-8

Note that this response message does not NEED MTOM/XOP encoding (no attachments present). But, since the request and response must be in the same format (SIMPLE SOAP or MTOM) this response must be in MTOM encoding based on MTOM specifications

Now, the client wants us to send the content type as

Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_7BFFF2BD24C642EA531247750913327; type="application/xop+xml";
start="<0.urn:uuid:7BFFF2BD24C642EA531247750913328@apache.org>";
start-info="application/soap+xml"; action="urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse"

I tried two options and both of them didn’t work

1) Proxy-settings -> Include charset in response-type as on
2) Wrote a custom stylesheet as below

<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:dp="http://www.datapower.com/extensions" extension-element-prefixes="dp"
exclude-result-prefixes="dp" version="1.0">
<xsl:output method="xml"/>
<xsl:template match="/">
<xsl:variable name="input-content-type" select="dp:http-request-header('Content-Type')"/>
<xsl:message dp:priority="debug">
input-content-type=
<xsl:copy-of select="$input-content-type" />
</xsl:message>

<dp:set-variable name="'var://service/set-response-header/content-type'"
value="$input-content-type"/>
<xsl:copy-of select="."/>
</xsl:template>
</xsl:stylesheet>
This style sheet copies the content type from request to reposnse, but I see an error while processing as client

Couldn't find MIME boundary: --uuid:8d5e23eb-d17b-4131-980f-3e21c53f25b7

However, I wrote the service implementation on a J2EE application server (tomcat) to observe the behavior. I see both the request and response coming with correct MTOM content type as

multipart/related; type="application/xop+xml";
Is this a bug in DataPower or am I doing anything wrong?

Please advise.
Updated on 2012-10-27T08:10:42Z at 2012-10-27T08:10:42Z by JagadishVemugunta
  • msiebler
    msiebler
    140 Posts
    ACCEPTED ANSWER

    Re: Data Power unable to set the correct ContentType on MTOM response messages

    ‏2012-10-18T10:06:11Z  in response to JagadishVemugunta
    I think the boundary error is unrelated to the stylesheet. Can you show me a debug log from 1 transaction?
    • JagadishVemugunta
      JagadishVemugunta
      37 Posts
      ACCEPTED ANSWER

      Re: Data Power unable to set the correct ContentType on MTOM response messages

      ‏2012-10-18T10:20:28Z  in response to msiebler
      Agreed, the boundary error is not related to the stylesheet.

      It is very simple to prove. The log doesn't shown anything as there is no error in the stylesheet

      If I have request content type as

      Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_806D8FD2D542EDCC2C1199332890718; type="application/xop+xml"; start="0.urn:uuid:806D8FD2D542EDCC2C1199332890719@apache.org"; start-info="application/soap+xml"; action="urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b"

      If I use the stylesheet to copy the request content type to the response content type, the response content type will become

      Content-Type: multipart/related; boundary=MIMEBoundaryurn_uuid_806D8FD2D542EDCC2C1199332890718; type="application/xop+xml";text/xml;charset=utf-8 start="0.urn:uuid:806D8FD2D542EDCC2C1199332890719@apache.org"; start-info="application/soap+xml"; action="urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b"
      When the client reads this response, the mime boundary is missing urn_uuid_806D8FD2D542EDCC2C1199332890718 and the response could not be processed.

      I guess the question is how to create MTOM content type for the responses that doesn't have attachments?

      As I said the same works in a J2EE container, the MTOM content type is automatically set by the Web Service obtainer even if there is no attachment on the response.
      Hope I was clear with my question.
      • msiebler
        msiebler
        140 Posts
        ACCEPTED ANSWER

        Re: Data Power unable to set the correct ContentType on MTOM response messages

        ‏2012-10-22T17:16:49Z  in response to JagadishVemugunta
        Since the response message does not have any attachments then you cannot just set the content type to have a boundary.
        Can you attach a small file to the response to put it in SwA?
        • JagadishVemugunta
          JagadishVemugunta
          37 Posts
          ACCEPTED ANSWER

          Re: Data Power unable to set the correct ContentType on MTOM response messages

          ‏2012-10-22T18:00:09Z  in response to msiebler
          No, we can't add an empty attachment as it requires changes on the client side.

          However, If I test the same think on a J2EE container, I see the MTOM response with the correct boundaries even if I don't have attachment on the response message.

          Why is DataPower no doing by default and this what the MTOM spec says. If the request is MTOM, the response should be also MTOM as a best practice. The client is complaining they we are not MTOM complaint
          • msiebler
            msiebler
            140 Posts
            ACCEPTED ANSWER

            Re: Data Power unable to set the correct ContentType on MTOM response messages

            ‏2012-10-22T19:29:33Z  in response to JagadishVemugunta
            I'm not sure if there is a way to make our box send an XML message as MTOM if there are no attachments. Also; I am not sure if i would agree that this violates the protocol; from http://www.w3.org/TR/soap12-mtom/#HTTP-implementation
            2.3.3 Intermediaries

            Use of the Abstract SOAP Transmission Optimization Feature is a hop-by-hop contract between a SOAP node and the next SOAP node in the SOAP message path. Therefore, no changes or restrictions to the SOAP processing model are introduced by this feature at an intermediary.
            • JagadishVemugunta
              JagadishVemugunta
              37 Posts
              ACCEPTED ANSWER

              Re: Data Power unable to set the correct ContentType on MTOM response messages

              ‏2012-10-24T02:00:20Z  in response to msiebler
              http://wiki.ihe.net/index.php?title=XDS.b_Implementation#Example_Provide_and_Register_Document_Set-b_transaction

              This is the health care specification that talks about MTOM response without attachments.
              • HermannSW
                HermannSW
                4128 Posts
                ACCEPTED ANSWER

                Re: Data Power unable to set the correct ContentType on MTOM response messages

                ‏2012-10-24T11:33:43Z  in response to JagadishVemugunta
                Hi Jagadish,

                I will let Matthias continue on the spec discussion.

                Of course you can always generate any output with DataPower if doing it by hand, see the smtp posting as an example:
                https://www.ibm.com/developerworks/mydeveloperworks/blogs/HermannSW/tags/smtp

                (XSLT is Turing complete, mentioned in Examples section)

                 
                Hermann<myXsltBlog/> <myXsltTweets/>
                • JagadishVemugunta
                  JagadishVemugunta
                  37 Posts
                  ACCEPTED ANSWER

                  Re: Data Power unable to set the correct ContentType on MTOM response messages

                  ‏2012-10-24T14:30:26Z  in response to HermannSW
                  I thought about the same and wrote a custom stylesheet and put this one as the last transform action that takes the "INPUT" and generates the output based on the below stylesheet. The custom stylesheet is nothing but building a correct MIME headers for the MTOM response. I looked the tcpdump on a good MTOM attachment to build this MIME headers
                  <xsl:stylesheet version="1.0"
                  xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions"
                  xmlns:regexp="http://exslt.org/regular-expressions"
                  extension-element-prefixes="dp">

                  <xsl:variable name="CRLF" select="'&#13;&#10;'" />
                  <xsl:variable name="DDASH" select="'--'" />
                  <xsl:variable name="QUOT" select="'&quot;'" />
                  <xsl:variable name="boundary" select="dp:generate-uuid()" />
                  <xsl:variable name="plus" select="'&#43;'" />
                  <xsl:variable name="slash" select="'&#47;'" />

                  <xsl:template match="/">

                  <xsl:variable name="contentType"
                  select="concat('multipart/related; boundary=',$boundary,';
                  type=',$QUOT,'application',$slash,'xop',$plus,'xml;','start=',$QUOT,'ITI41_ID;','
                  start-info=',$QUOT,'application',$slash,'soap',$plus,'xml',$QUOT,';','
                  action=',$QUOT,'urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse',$QUOT)" />
                  <dp:set-http-response-header name="'Content-Type'"
                  value="$contentType" />
                  <dp:freeze-headers />
                  <xsl:call-template name="buildMIMEpart"></xsl:call-template>
                  <xsl:copy-of select="." />
                  <xsl:value-of disable-output-escaping="yes"
                  select="concat($CRLF,$DDASH,$boundary,$DDASH,$CRLF)" />

                  </xsl:template>
                  <xsl:template name="buildMIMEpart">
                  <xsl:value-of disable-output-escaping="yes"
                  select="concat($CRLF,$DDASH,$boundary,$CRLF)" />
                  <xsl:value-of disable-output-escaping="yes"
                  select="concat('Content-Type: application',$slash,'xop',$plus,'xml;',' charset=UTF-8; type=',$QUOT,'application',$slash,'soap',$plus,'xml',$QUOT,$CRLF)" />
                  <xsl:value-of disable-output-escaping="yes"
                  select="concat('Content-Transfer-Encoding: binary',$CRLF)" />

                  <xsl:value-of disable-output-escaping="yes"
                  select="concat('Content-ID: ITI41_ID',$CRLF)" />

                  </xsl:template>

                  </xsl:stylesheet>

                  This one seems to have set the right content type on the response header as below

                  Content-Type multipart/related; boundary=ad72cd61-e330-490f-b1d3-0880cb3a39e2; type="application/xop+xml;start="ITI41_ID; start-info="application/soap+xml"; action="urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse"
                  But, this one resulted in a parsing error while reading the MIME headers as below

                  mpgw (Availity_ITI_MPG_INBOUND): Internal error
                  mpgw (Availity_ITI_MPG_INBOUND): rule (Availity_ITI_MPG_POLICY_rule_1): implied action Process unread attachments failed: Internal error
                  mpgw (Availity_ITI_MPG_INBOUND): rule (Availity_ITI_MPG_POLICY_rule_1): implied action Begin reading attachments failed: Internal error
                  mpgw (Availity_ITI_MPG_INBOUND): Invalid MIME package: error parsing entity headers
                  • JagadishVemugunta
                    JagadishVemugunta
                    37 Posts
                    ACCEPTED ANSWER

                    Re: Data Power unable to set the correct ContentType on MTOM response messages

                    ‏2012-10-24T15:03:55Z  in response to JagadishVemugunta
                    To bring more clarification on how I build the mime headers. I captured tcpdump on a J2EE container that doesn't have attachments on the response.

                    Please have a look at the response from the tcp dump.

                    HTTP/1.1 200 OK
                    Server: Apache-Coyote/1.1
                    Content-Type: multipart/related;type="application/xop+xml";boundary="uuid:c98951b3-a2ce-4140-b910-aa7934b22378";start="<root.message@cxf.apache.org>";start-info="application/soap+xml"
                    Content-Length: 708
                    Date: Wed, 24 Oct 2012 14:59:11 GMT
                    --uuid:c98951b3-a2ce-4140-b910-aa7934b22378
                    Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml";
                    Content-Transfer-Encoding: binary
                    Content-ID: <root.message@cxf.apache.org>

                    <soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Body><ns3:RegistryResponse xmlns="urn:ihe:iti:xds-b:2007" xmlns:ns2="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" xmlns:ns3="urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0" xmlns:ns4="urn:oasis:names:tc:ebxml-regrep:xsd:query:3.0" xmlns:ns5="urn:oasis:names:tc:ebxml-regrep:xsd:lcm:3.0" status="urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success"/></soap:Body></soap:Envelope>
                    --uuid:c98951b3-a2ce-4140-b910-aa7934b22378--
                    When I build exactly like the same in DataPower, It complains with unable to read MIME headers. I guess I may be doing something wrong, or DataPower always except an attachment incase there is MTOM mime header.
                    • msiebler
                      msiebler
                      140 Posts
                      ACCEPTED ANSWER

                      Re: Data Power unable to set the correct ContentType on MTOM response messages

                      ‏2012-10-24T15:35:01Z  in response to JagadishVemugunta
                      Hi I am not sure i understand the traffic flow. I think Hermann was recommending that you build the message as the last step of the response rule; just before it is returned to the HTTP client.
                      I am not sure then in that case why DataPower would be trying to parse the message.
                      Can you show us the complete debug log from 1 transaction?
                      • JagadishVemugunta
                        JagadishVemugunta
                        37 Posts
                        ACCEPTED ANSWER

                        Re: Data Power unable to set the correct ContentType on MTOM response messages

                        ‏2012-10-25T15:25:37Z  in response to msiebler
                        Thank you, I guess the problem was I didn't put my custom MTOM stylesheet as the last step. Now, when I put this as the last step and it seems to be working. I have tested with the tools I have and seems to be sending the correct MTOM headers on the responses that doesn't have attachments.

                        Now, I am waiting for the client (.NET) to test to observe the results. I will keep you posted.
                        • JagadishVemugunta
                          JagadishVemugunta
                          37 Posts
                          ACCEPTED ANSWER

                          Re: Data Power unable to set the correct ContentType on MTOM response messages

                          ‏2012-10-27T08:08:27Z  in response to JagadishVemugunta
                          I am able to make it work with the .NET client.

                          How, this is not working in the error rule.

                          Can you please advise what could be the issue?
                          • JagadishVemugunta
                            JagadishVemugunta
                            37 Posts
                            ACCEPTED ANSWER

                            Re: Data Power unable to set the correct ContentType on MTOM response messages

                            ‏2012-10-27T08:10:00Z  in response to JagadishVemugunta
                            <xsl:stylesheet version="1.0"
                            xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:dp="http://www.datapower.com/extensions"
                            xmlns:regexp="http://exslt.org/regular-expressions"
                            extension-element-prefixes="dp">

                            <xsl:output omit-xml-declaration="yes"></xsl:output>
                            <xsl:strip-space elements="*" />

                            <xsl:variable name="CRLF" select="'&#13;&#10;'" />
                            <xsl:variable name="DDASH" select="'--'" />
                            <xsl:variable name="QUOT" select="'&quot;'" />
                            <xsl:variable name="boundary" select="dp:generate-uuid()" />
                            <xsl:variable name="plus" select="'&#43;'" />
                            <xsl:variable name="slash" select="'&#47;'" />
                            <xsl:variable name="lt" select="'&lt;'" />
                            <xsl:variable name="gt" select="'&gt;'" />

                            <xsl:template match="/">
                            <xsl:variable name="multipart" select="'multipart/related; '"></xsl:variable>
                            <xsl:variable name="bound"
                            select="concat('boundary=',$QUOT,$boundary,$QUOT,'; ')"></xsl:variable>
                            <xsl:variable name="type"
                            select="concat('type=',$QUOT,'application',$slash,'xop',$plus,'xml',$QUOT,'; ')"></xsl:variable>
                            <xsl:variable name="start"
                            select="concat('start=',$QUOT,$lt,'TEST_ID',$gt,$QUOT,'; ')"></xsl:variable>
                            <xsl:variable name="start-info"
                            select="concat('start-info=',$QUOT,'application',$slash,'soap',$plus,'xml',$QUOT,'; ')"></xsl:variable>
                            <xsl:variable name="action"
                            select="concat('action=',$QUOT,'urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-bResponse',$QUOT,'; ')"></xsl:variable>

                            <xsl:variable name="contentType"
                            select="concat($multipart,$action,$bound,$type,$start,$start-info)" />
                            <dp:set-http-response-header name="'Content-Type'"
                            value="$contentType" />
                            <dp:freeze-headers />

                            <xsl:message>
                            header=

                            <xsl:value-of select="dp:http-response-header('Content-Type')"></xsl:value-of>

                            </xsl:message>
                            <xsl:call-template name="buildMIMEpart"></xsl:call-template>
                            <xsl:value-of disable-output-escaping="yes" select="$CRLF" />
                            <xsl:copy-of select="." />
                            <xsl:value-of disable-output-escaping="yes"
                            select="concat($CRLF,$DDASH,$boundary,$DDASH,$CRLF)" />

                            </xsl:template>
                            <xsl:template name="buildMIMEpart">
                            <xsl:value-of disable-output-escaping="yes"
                            select="concat($CRLF,$DDASH,$boundary,$CRLF)" />
                            <xsl:value-of disable-output-escaping="yes"
                            select="concat('Content-Type: application',$slash,'xop',$plus,'xml;',' charset=UTF-8; type=',$QUOT,'application',$slash,'soap',$plus,'xml',$QUOT,$CRLF)" />
                            <xsl:value-of disable-output-escaping="yes"
                            select="concat('Content-Transfer-Encoding: binary',$CRLF)" />

                            <xsl:value-of disable-output-escaping="yes"
                            select="concat('Content-ID: ',$lt,'TEST_ID',$gt,$CRLF)" />

                            </xsl:template>

                            </xsl:stylesheet>
                            • JagadishVemugunta
                              JagadishVemugunta
                              37 Posts
                              ACCEPTED ANSWER

                              Re: Data Power unable to set the correct ContentType on MTOM response messages

                              ‏2012-10-27T08:10:42Z  in response to JagadishVemugunta
                              Sorry, this is code I am using to build the custom MTOM header