Layer7 API Management

Expand all | Collapse all

How to pass all headers through when using context varible as Request Source on Route assertion

  • 1.  How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 13, 2017 11:14 PM
      |   view attached

    Hi

     

    We use the assertion "Route via HTTP(S)" with a context variable as Request Source.

    HTTP Header setting is  pass through as default, but the request all headers wasn't sent to the backend.

     

    I tried these things below but they didn't work.

      - The certain headers pass through with '<original values>' in Header tab of Route Assertion properties.

      - Manage Transport Headers assertion before routing didn't work.

     

    After all I made ther certain header with custom value on the routing properties and it did work

    But we need  to pass all headers to backend because headers could be vary.

     

    Is it a bug or did I miss something to do?

     

     

    Best Regards

    Becky

    Attachment(s)

    zip
    WarehouseTest03.xml.zip   1 KB 1 version


  • 2.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 13, 2017 11:41 PM

    Hi Becky,

     

        When you are keeping header as original value, you should pass the value while testing the service from testing tools or from any application code. Because whatever the value you pass it will simply validate at the backend and respond back. 

     

    if above not works out please provide your route configuration along with where you are testing?

     

    Regards

    Rajasekhar



  • 3.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 14, 2017 02:36 AM

    Hi

     

    I use Postman for testing and pass all the headers what i need.

     

    My Policy is encapsulated assertions :

    ** Test Case 1

    Set Conext Variable req.new as Message to: ${request}

    Set Context Variable req.new.mainpart as String to: ${decoded.payload}

    [Route via HTTP(s)]

       - default configuration except two things below

       - HTTP Method : ${request.http.method}

          ==> Setting context variable as Request Source always overwrite this to POST, so I should set like this

       - Request Source : req.new  (as Message)

     

    ==>  case1)  req.new  Context variable copied with ${request} and then replace ${req.new.mainpart} with new conents > didn't work (backed api didn't recieved replaced content , and not all headers)

     

    ** Test Case 2

    Set Conext Variable req.new as Message to: ${decoded.payload}

    [Route via HTTP(s)]

       - default configuration except two things below

       - HTTP Method : ${request.http.method}

       - Request Source : req.new  (as Message)

     

     ==> case 2) req.new  Context variable as Message with new String > backend api recieved new content but not all headers

     

    The Backend recieved the headers

    [when Default Request Source]

    accept:application/json, accept-encoding:gzip, deflate, apikey:l7xx243e7b1751454f0d9f4a4b3fb9c36259, connection:Keep-Alive, content-length:188, content-type:application/json, host:localhost:8080, user-agent:PostmanRuntime/6.1.6, x-bc-txid:D0000015d2f81fa21-f00

     

    [when Using Context Variable Request Source]

    connection:Keep-Alive, content-length:188, content-type:application/json; charset=utf-8, host:localhost:8080, user-agent:Apache-HttpClient/4.2.5 (java 1.5)

     

    I can't understand the Message type variable's behavier as Request Source in Route Assertion. and the headers problem.

    I need guide to fix this.



  • 4.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 14, 2017 04:03 AM

    Test Case 1
    ============

    Set Conext Variable req.new as Message to: ${request}
    Set Context Variable req.new.mainpart as String to: ${decoded.payload}

    You have created 2 variables but there aren't replacement happened due to which backend didnt received anything.


    Test Case 2
    ===========

    Configuration is correct. Please try in SOAPUi as well, may be Postman is not displaying the headers but not really sure.



  • 5.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 14, 2017 06:34 AM

    thanks ,

    Here questions again 

    1) so I should set the configuration of route like case #2 ?

    I thought it need the headers of $request  variable.  Is there any other assertion to replace the  mainpart of Message type variable instead the set context variable assertion?

     

    2) I did test other client testing tools. And It'not about testing tools i think.

    The same request with some headers have different result when change the Request Source of Route assertion. 

    Please see the last part my reply (backend api log). 

     

    Thanks your help!



  • 6.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 17, 2017 01:24 AM

    Hi Becky,

    1) so I should set the configuration of route like case #2 ?

    Yes

     Is there any other assertion to replace the  mainpart of Message type variable instead the set context variable assertion?

    ${request.mainpart} to capture request. If your request has the headers , tool will display the same headers in headers portion.

    We are using set context variable assertion to just creating the user defined variable so it is not an problem.

     

    2) If you send the headers along with ur request , the headers will display otherwise each testing tool may vary the headers.

     

    Regards

    Rajasekhar



  • 7.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 17, 2017 03:05 AM

    Hi.

     

    Thank you again.

    Sorry, I made you misunderstand my problem about testing tools.

     

    The call flow is,
    client tool(postman) --> gateway api --> backend api

     

    The request header of client has a custom header x-obp-txid. (for example)
    The other client tool's headers like postman-token are not my concern. I just want to receive the x-obp-txid.
    The received headers of the gateway API which is routing to backend api are all the same. The logs are always the same and I could see the header x-obp-txid in the audit logs. So, client testing tool, the postman have done right.
    The difference is,
    - when Routing assertion use default config, backend api received the x-obp-txid
    - when Routing assertion use context variable as Request Source, the backend api didn't receive the x-obp-txid.


    Thank you.
    Becky



  • 8.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 17, 2017 04:06 AM

    Hi Becky,

          Can you please provide complete configuration screen shot instead of typing the scenario and Routing assertion properties screenshot. If i am not wrong there is some thing we have to tune to make it proper.

     

    Regards

    Rajasekhar



  • 9.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 17, 2017 08:38 AM
      |   view attached

    Hi Rajasekhar,

     

    My customer doesn't allow capturing screen shot and connecting Internet.

    So I've made a simple policy which is routing to ACMEWarehouse (provided by tutorials) at my own computer.

    The testing result is the same before.

    Please check the screen shots.

     

     

    * Gateway API Inbound Request log

     

    * Backend API (ACMEWarehouse) Inbound Request log

     

    The content-type and user-agent have changed, and the x-obp-txid and other custom headers are gone.

     

     

     

    I'm gonna attach the Policy xml to the original question.

    My gateway is 9.2 CR03.

     

    Thank you

    Attachment(s)

    zip
    WarehouseTest03.xml.zip   1 KB 1 version


  • 10.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 17, 2017 11:09 PM

    Hi Becky,

     

           Whatever the headers you are passing in your request kindly hardcode in Route properties. Keep required headers are Original value.

            Enable Pass through only certain request headers: then add all headers which are required and test the service.

     

     

            I hope this will fix your issue.

     

    Regards

    Rajasekhar



  • 11.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 18, 2017 12:45 AM

    Hi Rajasekhar,

     

    Thanks for your reply.

     

    My problem is a little complicate.

    Your suggestion is not exactly what I want. And I did try that before.

    I have already mentioned at the original question that <original value> doesn't work. 

    And I need all headers because we use CA developer portal which manage the APIs of gateway. The gateway doesn't know exactly what headers are used and would be use in the future. My client want  flexible gateway which doesn't have dependency with backend api.

    But I will try to persuade my customer with your approach - whenever new headers are needed we should modify the 'portal integration service' or portal template fragments. If I fail, maybe, I should open a case. 

     

    I really really appreciate your kind support. 

     

    Thank you

    Becky



  • 12.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 18, 2017 01:29 AM

    Hi Becky,

     

    When using a custom request message other than the default request message , the default headers coming with the request will not be passed to backend. So, We need to set a context variable , output the actual value of our header to this context variable and then add this header in the routing assertion again with reference to this context variable.


    Set context variable Header1 as ${request.http.header.x-obp-txid}

     

    Route via Policy with custom request message
    Add header "x-obp-txid" and values as ${Header1}

     

    Please try above once and let me know.Its working for me.

     

    Regards
    Rajasekhar



  • 13.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 18, 2017 05:19 AM

    Hi Rajasekhar,

     

    Yes I already know that the custom value instead of <original value> works fine. I've mentioned that too before.

    It is static way of header setting, you know, that is not what I want. 

     

    Anyway Thanks again

    Becky



  • 14.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 18, 2017 05:29 AM

    Then i don't think its possible 

    As far as i know the default headers coming with the request will not be passed to backend.

    Better you can raise case to CA.

    Once you get the solution please provide here.

     

    Thanks in Advance.

     

    Regards

    Rajasekhar



  • 15.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 20, 2017 12:28 PM

    What you can do is use ${request.http.allheadervalues} in a for each loop, then parse each one, which will be 'name: value' to add these headers to your decodedBody message object.  Alternatively, there are a few assertions that can manipulate the contents of ${request.mainpart} (and leave the origional request headers in place so you can route that message instead of a variable), like the xslt, manipulate xml, and regular expresion assertions.



  • 16.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 24, 2017 08:49 PM

    Hi,

     

    I couldn't make it works fine that just adding 'name: value', I've asked to Mark_HE below about your first suggestion. 

    Your second looks good idea. 

     

    Thank you.



  • 17.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Broadcom Employee
    Posted Jul 23, 2017 07:35 PM

    Hi BeckyJang ,

    Ben.Deutsch is correct.

    Keep in mind that the default request message and your decodedBody message are 2 different messages, and have their own header set. Since you route the decodedBody message, it won't pass the headers of request message.

    If you want to pass the headers of incoming request, you have to copy them to decodedBody message as Ben.Deutsch suggested.

     

    Regards,

    Mark



  • 18.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 24, 2017 08:41 PM

    Hi Mark,

     

     

    Should I set ${decodedBody.http.header} with the value?

    Could you guide it more details about how to build the Message type object with some headers?

    I couldn't find any document about handling Message type.

     

    Thank you.



  • 19.  Re: How to pass all headers through when using context varible as Request Source on Route assertion
    Best Answer

    Broadcom Employee
    Posted Jul 24, 2017 11:24 PM
      |   view attached

    Dear BeckyJang ,

    You can use "Manage Transport Properites/Headers" assertion to add header to a message context variable.(remember to right click on the assertion to set the target message)

    But the regex to split the allheadervalues is a bit tricky as the comma ',' is not just to separate the headers, but also used to separate the multiple values of a header.

    Here is a sample policy to copy all header from request message to decodedBody message, I attach it as well(copyHeader.xml).

     

    Regards,

    Mark

    Attachment(s)

    zip
    copyHeaders.xml.zip   1 KB 1 version


  • 20.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Jul 25, 2017 01:42 AM

    Hi, 

     

    That's what I want!

    It really helps me.

    Thank you.



  • 21.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Broadcom Employee
    Posted Jul 26, 2017 11:38 PM

    You are welcome



  • 22.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Posted Mar 15, 2019 04:06 PM

    Hi everyone,

     

    I have a question please correct me if it's not a valid one..

     

    In Ideal case, when Routing via HTTPS with default request as source, will the custom headers added by "Manage Transport Properties assertion", target as "Request", reaches the backend? 

     

    In my case I tried to pass the X-Forwarded-For header to an endpoint and checked if  this header is set in the routed request in Browser developer tools. But it isn't available, 



  • 23.  Re: How to pass all headers through when using context varible as Request Source on Route assertion

    Broadcom Employee
    Posted Mar 17, 2019 06:29 PM

    I can see the header assertion apply the change on requestMainpart message, not the default request message.

    Please ensure the message you apply the header change is the same message you route to the backend (on Route via HTTP assertion -> Request Source).