Layer7 API Management

  • 1.  How to transform XML Request body in LAC

    Posted Sep 30, 2018 05:01 AM

    Hi There,

     

    I need to create a function or a Custom Endpoint in LAC which will accept a request XML body and transform it and then we need to call another resource.

     

    I know how to call a resource from a function but what I need to know how we can accept a request XML body in the request and how we can transform it. By transforming it I mean to change some node name.

     

    For Example below will the request body.

     

    <root>

    <reqid>00001</reqid>

    <source>mfa</source>

    <inward>11119099</inward>

    </root>

     

    After Transforming the above request I need the below payload which will be sent to the resource endpoint

     

    <root>

    <reqid-lac1>0001</reqid-lac1>

    <source-lac1>mfa</source-lac1>

    <inward>1119099</inward>

    </root>

     

    The issue is I am not able to log or capture the request packet using the function in LAC 4.1.

     

     

     

    Thanks,

    Irfan



  • 2.  Re: How to transform XML Request body in LAC

    Posted Oct 02, 2018 04:19 PM

    My apologies for not responding sooner. I've reached out to one of our LAC subject matter experts to weigh in on this one. Please stay tuned.



  • 3.  Re: How to transform XML Request body in LAC

    Posted Oct 04, 2018 02:00 AM

    Hi Dustin,

     

    Thank you for the attention. 

     

    Will be waiting for the response.

     

     

    Thanks,

    Irfan



  • 4.  Re: How to transform XML Request body in LAC

    Broadcom Employee
    Posted Oct 05, 2018 12:08 AM

    Hello Irfan,

     

    It looks LAC can transform incoming HTTP requests by creating Request Event Handlers.

     

    https://docops.ca.com/ca-live-api-creator/4-1/en/developing-apis/extensibility/event-handlers/#EventHandlers-RequestEventHandlers

     

    The request body is set to a pre-defined variable "json" as raw JSON string.
    I checked the contents of "json" by setting "log.debug('json=' + json);" in an Event Handler and I found the "json" variable was set properly as a JSON string regardless of the request's Content-Type (either application/json or application/xml).

     

    LAC transforms request messages from XML to JSON automatically, so JSON to JSON transformation is necessary in the Event Handler before your resource endpoint.
    I checked it on LAC 5.0 but probably it is the same on LAC 4.1.

     

    Best regards,
    Seiji



  • 5.  Re: How to transform XML Request body in LAC

    Posted Oct 05, 2018 03:37 AM

    Hi Seiji,

     

    Thank you for your response.

     

    So for every XML Request body we need to  create a request event which will convert XML body into JSON.

     

    It will be very useful if you can provide me sample for converting any XML body into Json.

    Which method do we need to call for conversion in javascript?

    In the request event how we can then pass this json request body to a function?

     

     

    Thanks,

    Irfan



  • 6.  Re: How to transform XML Request body in LAC

    Broadcom Employee
    Posted Oct 05, 2018 05:34 AM

    Hi Irfan,

     

    I assumed that your resource endpoint would be updated with the following XML payload.

     

    <root>
    <reqid-lac1>0001</reqid-lac1>
    <source-lac1>mfa</source-lac1>
    <inward>1119099</inward>
    </root>

     

    Its JSON expression is:

     

    {
    "reqid-lac1" : "0001",
    "source-lac1" : "mfa",
    "inward" : "1119099"
    }

     

    The APIs created by LAC accept both types of payload at the same URI by specifying the Content-Type as "application/xml" or "application/json".
    They both are passed to Request Event Handlers in JSON format before the actual resource endpoint is invoked. If you send the following XML body to your resource endpoint:

     

    <root>
    <reqid>00001</reqid>
    <source>mfa</source>
    <inward>11119099</inward>
    </root>

     

    It is passed to Event Handlers as a JSON string like this:

     

    {
    "reqid": "00001",
    "source": "mfa",
    "inward": "11119099"
    }

     

    XML to JSON conversion is automatically done by LAC in the very early stage, so I think JSON to JSON transformation is necessary in a Request Event Handler (javascript code) of your resource endpoint.
    Request Event Handlers work as "filters" for Resources and Functions, so it is enough to put the reformatted JSON string back to the "json" variable.

     

     

    I found an example about "Reformat Request" was included in the Web UI of LAC 5.0.

     

     

    Best regards,
    Seiji



  • 7.  Re: How to transform XML Request body in LAC

    Posted Oct 09, 2018 12:06 AM

    Hi Seiji,

     

    Thank you for the help. 

    Now i understand that the request received at LAC is converted into json. 

     

    But my second issue is i want to transform the node value such reqid to reqid-lac1 and after transforming the node name i need to send a XML body to our resource endpoint.

    So how can we change the node name and transform it again to XML? 

     

     

    Thanks,

    Irfan



  • 8.  Re: How to transform XML Request body in LAC

    Broadcom Employee
    Posted Oct 09, 2018 12:24 AM

    Hi Irfan,

     

    Isn't your resource endpoint created on LAC?
    As I mentioned, LAC accepts both JSON and XML requests for each API. It is just controlled by the specified Content-Type. I think you can just send the JSON body to your resource endpoint instead of converting it to XML.

     

    Do you have any reasons to transform it back to XML?

     

    Best regards,
    Seiji



  • 9.  Re: How to transform XML Request body in LAC

    Broadcom Employee
    Posted Dec 10, 2018 06:34 PM

    Good afternoon,

     

    Were you able to resolve the issue? What was the final result?

     

    Sincerely,


    Stephen Hughes
    Broadcom Support