Topic
12 replies Latest Post - ‏2013-09-27T23:46:46Z by d.m.spice
Arnab_Ghosh
Arnab_Ghosh
70 Posts
ACCEPTED ANSWER

Pinned topic How to set header Content-Type in error rule

‏2013-06-18T19:48:30Z |

Hi,

I want to set few headers in error-rule. All of the headers are getting set but the header Content-Type is not getting set. Can you please let me know how to set it in an error rule? And how to set the header Content-Length?

Thanks,

Arnab

  • kenhygh
    kenhygh
    873 Posts
    ACCEPTED ANSWER

    Re: How to set header Content-Type in error rule

    ‏2013-06-18T23:22:24Z  in response to Arnab_Ghosh

    what's your code look like?

  • Nitin_Jha
    Nitin_Jha
    20 Posts
    ACCEPTED ANSWER

    Re: How to set header Content-Type in error rule

    ‏2013-06-19T01:40:16Z  in response to Arnab_Ghosh

    Hi Arnab

     As Ken said, it would helpful to , if we have more details, but as a generic solution this should work.

    I am assuming you are trying to set the value same as it comes in the request. The original value can be read from the service variable "var://service/original-content-type" and then you can it assign it to the response header as given below.

    var://service/set-response-header/Content-Type = var://service/original-content-type.

    You can use a set variable action or a XSLT to achieve this.

    Hope this helps.

     

  • SatheshSubramaniam
    SatheshSubramaniam
    11 Posts
    ACCEPTED ANSWER

    Re: How to set header Content-Type in error rule

    ‏2013-06-19T03:52:41Z  in response to Arnab_Ghosh

    hi

    set this service variable var://service/set-response-header/Content-Type using set variable action.

    this set variable action should placed after Result action.

    try it.

    • Arnab_Ghosh
      Arnab_Ghosh
      70 Posts
      ACCEPTED ANSWER

      Re: How to set header Content-Type in error rule

      ‏2013-06-19T16:35:49Z  in response to SatheshSubramaniam

      Thanks all of you it worked as Sathesh explained above. Do you know how can i set the Content-Length as well?

      • HermannSW
        HermannSW
        3145 Posts
        ACCEPTED ANSWER

        Re: How to set header Content-Type in error rule

        ‏2013-06-19T19:00:44Z  in response to Arnab_Ghosh

        Please do not do that, you are likely to set it incorrectly (how would you want to compute the length not knowing how DataPower creates output?).

        I assume that you do not see a Content-Length in DataPower response and want one.
        This is the case if DataPower returns the response in chunked mode, which is a HTTP 1.1 feature.

        The easiest way I know of to enforce DataPower returning a Content-Length HTTP response header is this:
        Set "HTTP Version to Client" in the FSH to "HTTP 1.0" instead of default of "HTTP 1.1".


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

    • d.m.spice
      d.m.spice
      35 Posts
      ACCEPTED ANSWER

      Re: How to set header Content-Type in error rule

      ‏2013-09-27T13:00:36Z  in response to SatheshSubramaniam

      Hello,

      I'm having a similar issue, so I tried your suggestion.  It appears to work, but when the consumer receives the error, the content-type is back to "text/xml" Attached is a pic of the error rule probe, showing the content-type is correct:

      Anyone have any thoughts? Thanks in advance

      Attachments

      • kenhygh
        kenhygh
        873 Posts
        ACCEPTED ANSWER

        Re: How to set header Content-Type in error rule

        ‏2013-09-27T13:12:33Z  in response to d.m.spice

        did you use <dp:freeze-headers/> ?

        • d.m.spice
          d.m.spice
          35 Posts
          ACCEPTED ANSWER

          Re: How to set header Content-Type in error rule

          ‏2013-09-27T13:18:07Z  in response to kenhygh

          I put an xform after my set variable that did a freeze-headers to no avail.

          • HermannSW
            HermannSW
            3145 Posts
            ACCEPTED ANSWER

            Re: How to set header Content-Type in error rule

            ‏2013-09-27T18:48:53Z  in response to d.m.spice

            Please create a simplified service showing the problem and attach an export of the service.

            Please provide also how to send request to trigger problem.

             

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

            • d.m.spice
              d.m.spice
              35 Posts
              ACCEPTED ANSWER

              Re: How to set header Content-Type in error rule

              ‏2013-09-27T20:13:51Z  in response to HermannSW

              Thank you, I will as soon as I can, hopefully tonight or tomorrow.

            • d.m.spice
              d.m.spice
              35 Posts
              ACCEPTED ANSWER

              Re: How to set header Content-Type in error rule

              ‏2013-09-27T23:33:57Z  in response to HermannSW

              I've figured out what is causing the issue, but I do not understand why.  The behavior exhibits itself when there is an on-error action on the request.

              Attached is a zip of a simple MPG with a request, response, and error rule that demonstrate this.  The request has an on-error action, a simple xform that does a dp:reject (to force the error), and a results action.  The error rule has a results action and a set var action.

              If you leave the on-error in, the response content-type is returned as "text/xml".  If you remove the on-error, the content-type correctly returns "application/json".

              Attachments

              • d.m.spice
                d.m.spice
                35 Posts
                ACCEPTED ANSWER

                Re: How to set header Content-Type in error rule

                ‏2013-09-27T23:46:46Z  in response to d.m.spice

                Forgot to mention how to invoke.  It's basically a REST GET:

                http://{your device}:19666/test