Layer7 API Management

  • 1.  Validate request URI

    Posted Jan 31, 2019 03:38 PM

    I am planning to catch OOTB exception e.g. 500, 404 etc.

    OOTB Scenario: trying to access invalid URI and OOTB response with message "Policyfied Error" with response  status code 500

    My Requirement: To override above OOTB 500 error message and  response with custom message with status code 404

     

    At present, I am using "CustomizeErrorResponse" assertion which is working fine. but facing below challenges.

    Challenges: How to validate ${request.htt.uri} with existing routing_uri available ssg.published_service.

    Database Query: select routing_uri as Id from ssg.published_service;

    Either I have to use "Perform JDBC Query" assertions to fetch routing_uri from ssg.published_service table. I want to avoid a database query. Is there any alternate way?

     

    I am using Gateway 9.2 version.



  • 2.  Re: Validate request URI

    Broadcom Employee
    Posted Jan 31, 2019 03:44 PM

    Hello,

     

    Based on the requirement it sounds like you would benefit from a catch all service as described here: How to set a default response when a service canno - CA Knowledge 

     

    Regards,

    Joe   



  • 3.  Re: Validate request URI

    Posted Feb 01, 2019 05:17 AM

    Thank you Joe for your inputs,

    Yes, it is working. 

    Last question : How to catch "Gateway sometimes internal issues happen" e.g. 500, 401 etc. status code which is a default.?

    Because I am getting always status code is 0 for all scenrio: Response status: ${response.http.status}

     

    Regards,

    Tattwa



  • 4.  Re: Validate request URI

    Broadcom Employee
    Posted Feb 03, 2019 04:58 PM

    Dear Tattwadarsi Biswal ,

    Status code 0 means there is no response returned from backend, or it doesn't call anywhere at all.

    I believe you don't have a route via http assertion in your "catch all" policy, that's why it always be 0.

     

    The "catch all" should only for those "service not found" requests, it should not be able to catch the 401 requests.

    As Joe's document advised, you can just put a fix 404 response in your "catch all" policy.

     

    Regards,

    Mark



  • 5.  Re: Validate request URI

    Posted Feb 04, 2019 06:56 AM

    Thank you Mark for your inputs.

    I got it about 404 error scenario and implemented which is working fine for me.

     

    I have done customization in"#OTK Fail with error message" for OTK related 500, 401 errors which is working fine.

    Could you please help me on  "How to handle Gateway 500, 401 etc.?" error/exception.

     

    Regards,

    Tattwa



  • 6.  Re: Validate request URI

    Broadcom Employee
    Posted Feb 04, 2019 05:47 PM

    Dear Tattwa,

    1. I don't think you can customize 401 Unauthorized response

    2. if you don't use custom error response assertion, I don't think you can change http status code

    3. for default soap error response, you can define your own response template via following cwp
    - soapfault.level=1
    - soapfault.template=<your response template, using ${soapfault.detail} in template to return error reason >
    - soapfault.template.contentType=<content-type of your template, eg. text/plain, application/json, etc.>

     

    for more details, you can refer to,
    https://docops.ca.com/ca-api-gateway/9-4/en/reference/gateway-cluster-properties/fault-level-cluster-properties/

    basically, this custom response is for http 500

     

    4. otherwise, you may need to use custom error response assertion in every policy.

    But some errors may occur before policy execution which you still cannot control.

     

    Regards,

    Mark



  • 7.  Re: Validate request URI

    Posted Feb 05, 2019 12:10 PM

    Thank you Mark for your valuable inputs,

    Agree, even I didn't get the answer in the community too.

    So, I tried as per your recommendation and prefer CWP options for the time being.

    Unable to get json response soapfault.template.contentType is not working for "application/json" or "application/json; charset=utf-8". 

     

    Regards,

    Tattwa



  • 8.  Re: Validate request URI

    Broadcom Employee
    Posted Feb 05, 2019 05:08 PM

    The soapfault.template.contentType was introduced since gateway 9.3, I believe.

    what version of gateway you have?



  • 9.  Re: Validate request URI

    Posted Feb 07, 2019 04:09 AM

    I am using Gateway 9.2



  • 10.  Re: Validate request URI

    Broadcom Employee
    Posted Feb 07, 2019 06:41 PM

    then you can only use xml template



  • 11.  Re: Validate request URI

    Posted Feb 12, 2019 02:05 PM

    Thank you Mark for your valuable inputs and guidance.