API Connect

API Connect

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.


#API Connect
#Applicationintegration
#APIConnect
 View Only
  • 1.  Mapping an output from Gateway script to Map Policy

    Posted Thu July 04, 2019 06:21 AM
    Edited by Susant Kumar Palai Thu July 04, 2019 06:50 AM
    Hi , 

    I have written a gateway script to read the incoming SOAP message and is trying to map its values into a different user defined object. Now , I want to use this object into my map activity so as to send the details to backed service call. 

    Below in the gateway script I have created a response object "output"  and is looking for a solution to consume it's values in map policy . 

    So in map policy should I define
    input : message.body.output
    contect type - application/json
    defination - inline schema , where this schema must have the similar structure as  of the output object . 

    is this correct?  (I am trying this but unable to deploy it , getting error saying 
    he OpenAPI definition 'genericinquiryinterface:1.0.0 (GenericInquiryInterface)' cannot execute on the gateway service 'gateway-dev' because the required version 1.0.0 of the 'invoke' policy is not available. (Available versions: 2.0.0.) ) 

    or do we have any other option to do it like creating a  API definition object , and refer it in the gateway script  to map the value ( how to map the incoming values to definition object using gateway script ?)   and then use it in Map policy.

    Gateway script :

    var apic = require('apim');
    var xmlDOM=apic.getvariable('message.body');

    var result = false;

    var action = xmlDOM.getElementsByTagNameNS('http://www.etisalat.ae/Middleware/GenericInquiryInterface/GenericInquiryRequest.xsd', 'Action');

    console.log('action value is:'+ action);

    if (action.length > 0 && action.item(0).textContent=='GET_ORDER_PAY_DETAILS') {
    result = true;
    }

    var requestId = xmlDOM.getElementsByTagNameNS('http://www.tibco.com/schemas/CustomerInquiry/Processes/GetOrderPaymentDetailsRequest.xsd', 'RequestID');



    var output= {}
    output.response = {}
    output.response.code= 200
    output.response.message = result
    output.response.name = action.item(0).textContent
    output.response.requestId = requestId.item(0).textContent


    context.set('message.body',output)
    context.set('message.headers.content-type', 'application/json');

    Regards
    Susant



    ------------------------------
    Susant Kumar Palai
    ------------------------------


  • 2.  RE: Mapping an output from Gateway script to Map Policy

    Posted Fri July 05, 2019 06:57 PM

    Hi Susant,

    You've created a JSON object named output which has 

    var output= {}
    output.response = {}
    output.response.code= 200
    output.response.message = result
    output.response.name = action.item(0).textContent
    output.response.requestId = requestId.item(0).textContent

    and you're setting message.body to that object output

    context.set('message.body',output)

    The map policy would consume message.body.  You're JSON input schema would match the object that you're producing.

    Regards,

    Steve




  • 3.  RE: Mapping an output from Gateway script to Map Policy

    Posted Sun July 07, 2019 07:36 PM

    Hi Susant,

    Another point I should have noted in my last post.  The map policy will take XML as input, and this above gatewayscript policy's intent is to simply translate an XML structure into a JSON structure, which is redundant since the map policy would handle this.  You can remove the gatewayscript policy entirely, specify your map input is of type application/xml, specify an input schema as inline using a source example from your backend, and simply map the action and requestId input properties to the appropriate output schema.

    Regards,

    Steve




  • 4.  RE: Mapping an output from Gateway script to Map Policy

    Posted Wed July 10, 2019 08:15 AM
    Hi Stephen , 
    Actually, I have used gateway script because my request XML contains another XML string as an input I want to map this XML string as an input to backend WSDL.  Kindly suggest if there is better way to do this . 

    Shared below is the input XML where <RequestDetailsAny> contains input XML as string:
    <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:gen="http://www.etisalat.ae/Middleware/GenericInquiryInterface/GenericInquiryRequest.xsd" xmlns:com="http://www.etisalat.ae/Middleware/SharedResources/Common/Common.xsd">
    <soapenv:Header/>
    <soapenv:Body>
    <gen:GenericInquiryRequest>
    <gen:RequestedSystem>mCashier</gen:RequestedSystem>
    <gen:Action>GET_ORDER_PAY_DETAILS</gen:Action>
    <gen:ModeType>?</gen:ModeType>
    <gen:RequestDetails>?</gen:RequestDetails>
    <gen:RequestDetailsAny>
      <ns1:GetOrderPaymentDetailsRequest xmlns:ns1="http://www.tibco.com/schemas/CustomerInquiry/Processes/GetOrderPaymentDetailsRequest.xsd">
       <ns2:ApplicationHeader      xmlns:ns2="http://www.etisalat.ae/Middleware/SharedResources/Common/ApplicationHeader.xsd">
      <ns2:TransactionID>1124</ns2:TransactionID>
       <ns2:RequestedSystem>mCashier</ns2:RequestedSystem>
       <ns2:RetryLimit>1</ns2:RetryLimit>
       </ns2:ApplicationHeader>
       <ns1:DataHeader>
       <ns1:RequestID>186544078</ns1:RequestID>
       </ns1:DataHeader>
       </ns1:GetOrderPaymentDetailsRequest>
    </gen:RequestDetailsAny>
    <com:AdditionalInfo>
    <com:Name>?</com:Name>
    <com:Value>?</com:Value>
    </com:AdditionalInfo>
    </gen:GenericInquiryRequest>
    </soapenv:Body>
    </soapenv:Envelope>


    Now, I am  at stuck mapping the response , where I have a similar XML as string in the response XML and I have to map it to the response XML. 

    Response back to client : [ Map to map the XML resposne from backend in ResponseDetailsAny ]

    <xs:schema xmlns="http://www.etisalat.ae/Middleware/GenericInquiryInterface/GenericInquiryResponse.xsd" xmlns:ns1="http://www.etisalat.ae/Middleware/SharedResources/Common/Common.xsd" xmlns:ns0="http://www.etisalat.ae/Middleware/SharedResources/Common/AckMessage.xsd" xmlns:xs="http://www.w3.org/2001/XMLSchema" targetNamespace="http://www.etisalat.ae/Middleware/GenericInquiryInterface/GenericInquiryResponse.xsd" elementFormDefault="qualified" attributeFormDefault="unqualified">
    <xs:import namespace="http://www.etisalat.ae/Middleware/SharedResources/Common/AckMessage.xsd"/>
    <xs:import namespace="http://www.etisalat.ae/Middleware/SharedResources/Common/Common.xsd"/>
    <xs:element name="GenericInquiryResponse">
    <xs:complexType>
    <xs:sequence>
    <xs:element name="Action" type="xs:string"/>
    <xs:element name="ResponseDetails" type="xs:string" minOccurs="0"/>
    <xs:element name="ResponseDetailsAny" minOccurs="0">
            <xs:complexType>
               <xs:sequence>
                    <xs:any processContents="lax" namespace="##any"/>
              </xs:sequence>
        </xs:complexType>
    </xs:element>
    <xs:element ref="ns1:AdditionalInfo" minOccurs="0" maxOccurs="unbounded"/>
    </xs:sequence>
    </xs:complexType>
    </xs:element>
    </xs:schema>


    ------------------------------
    SAMPATH K
    ------------------------------