Topic
  • 13 replies
  • Latest Post - ‏2014-10-22T18:17:59Z by bekataoka
Arnab_Ghosh
Arnab_Ghosh
94 Posts

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
    1614 Posts

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

    ‏2013-06-18T23:22:24Z  

    what's your code look like?

  • Nitin_Jha
    Nitin_Jha
    20 Posts

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

    ‏2013-06-19T01:40:16Z  

    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
    12 Posts

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

    ‏2013-06-19T03:52:41Z  

    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
    94 Posts

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

    ‏2013-06-19T16:35:49Z  

    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.

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

  • HermannSW
    HermannSW
    4894 Posts

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

    ‏2013-06-19T19:00:44Z  

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

    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
    63 Posts

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

    ‏2013-09-27T13:00:36Z  

    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.

    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
    1614 Posts

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

    ‏2013-09-27T13:12:33Z  
    • d.m.spice
    • ‏2013-09-27T13:00:36Z

    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

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

  • d.m.spice
    d.m.spice
    63 Posts

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

    ‏2013-09-27T13:18:07Z  
    • kenhygh
    • ‏2013-09-27T13:12:33Z

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

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

  • HermannSW
    HermannSW
    4894 Posts

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

    ‏2013-09-27T18:48:53Z  
    • d.m.spice
    • ‏2013-09-27T13:18:07Z

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

    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
    63 Posts

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

    ‏2013-09-27T20:13:51Z  
    • HermannSW
    • ‏2013-09-27T18:48:53Z

    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/>

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

  • d.m.spice
    d.m.spice
    63 Posts

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

    ‏2013-09-27T23:33:57Z  
    • HermannSW
    • ‏2013-09-27T18:48:53Z

    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/>

    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
    63 Posts

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

    ‏2013-09-27T23:46:46Z  
    • d.m.spice
    • ‏2013-09-27T23:33:57Z

    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".

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

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

  • bekataoka
    bekataoka
    15 Posts

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

    ‏2014-10-22T18:17:59Z  
    • d.m.spice
    • ‏2013-09-27T23:33:57Z

    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".

    I was wondering if you ever solved this problem.  I have run into the same situation.  Can you share your solution?