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.  Switch case implementation - using input request XML parameter

    Posted 06/24/19 06:04 AM
    Hi All, 
    I have a requirement where based on the value in the  input request parameter I have to make multiple backed calls. Kindly help me to understand what shall I put in the switch case condition to handle multiple backend calls. 

    I am getting a SOAP message in the input request and my backed is also exposed over SOAP. 

    Request XML : 
    <ns0:GenericInquiryRequest xmlns:ns0="http://www.etisalat.ae/Middleware/GenericInquiryInterface/GenericInquiryRequest.xsd" xmlns:ns3="http://www.etisalat.ae/Middleware/SharedResources/Common/Common.xsd"><!-- mandatory -->
    <ns0:RequestedSystem><!-- mandatory -->string</ns0:RequestedSystem>
    <ns0:Action><!-- mandatory -->string</ns0:Action>
    <ns0:ModeType><!-- mandatory -->string</ns0:ModeType>
    <ns0:RequestDetails>string</ns0:RequestDetails>
    <ns0:RequestDetailsAny></ns0:RequestDetailsAny>
    <ns3:AdditionalInfo><!-- between zero and unlimited repetitions of this element -->
    <ns3:Name><!-- mandatory -->string</ns3:Name>
    <ns3:Value><!-- mandatory -->string</ns3:Value>
    </ns3:AdditionalInfo>
    </ns0:GenericInquiryRequest>
    </soapenv:Body>
    </soapenv:Envelope>

    here ACTION can be "Business" or "Customer" , based on which I have to make multiple backed calls.

    Kindly help me with the switch case condition. 

    Regards
    Susant

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


  • 2.  RE: Switch case implementation - using input request XML parameter

    Posted 06/25/19 09:07 AM
    I would put in a gateway script node parse the request message for the Action and then use a simple gatewayscript test for your Switch such as '"Business" == $(message.body.action)' or something similar.

      - switch:
          title: switch
          case:
            - condition: '"Business" == $(message.body.action)'



    ------------------------------
    Devin
    IBM Champion - Cloud 2019
    ------------------------------



  • 3.  RE: Switch case implementation - using input request XML parameter

    Posted 06/25/19 01:01 PM

    The solution will be a little more involved since your input is XML.  You'll need to update your condition on the switch as follows:

    let result = false;
    let xmlDOM = XML.parse(request.body);
    let action = xmlDOM.getElementsByTagNameNS('http://www.etisalat.ae/Middleware/GenericInquiryInterface/GenericInquiryRequest.xsd', 'Action')
    if (action.length > 0 && action.item(0).textContent=== 'Business') {
      result = true;
    }
    result;

    The XML will need to be parsed and the Action Element value extracted from the XML DOM.

    If the input were JSON, then request.body.p1.p2.action syntax would work.

    Regards,

    Steve




  • 4.  RE: Switch case implementation - using input request XML parameter

    Posted 07/02/19 09:18 AM
    Thanks Devin & Stephen
    Actually I am quite new to writing the Gateway script . I understand that we can achieve it both by writing an XSLT policy or by using a gatewayScript and in both the cases I have to first parse the request. 
    can you guide me though any sample which can help me to understand how to use the Parser Policy. 

    Hi Stephen,
    I tried using the provided gateway script but it didn't work. Please guide me if there is any prerequisites that must do before implementing it. 


    Actually, I have  to parse the below sample request to read the value for Action and an XML available under <ns0:RequestDetailsAny> . Now based on action I have to map the XML available under  RequestDetailsAny to the backend WSDL.


    <soapenv:Envelope
    xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
    <soapenv:Header>
    <wsse:Security
    xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd"
    xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <wsse:UsernameToken>
    <wsse:Username></wsse:Username>
    <wsse:Password></wsse:Password>
    <wsse:Nonce EncodingType="string"></wsse:Nonce>
    <wsu:Created></wsu:Created>
    </wsse:UsernameToken>
    <wsu:Timestamp wsu:Id="string">
    <wsu:Created></wsu:Created>
    <wsu:Expires></wsu:Expires>
    </wsu:Timestamp>
    </wsse:Security>
    </soapenv:Header>
    <soapenv:Body>
    <ns0:GenericInquiryRequest
    xmlns:ns0="http://www.etisalat.ae/Middleware/GenericInquiryInterface/GenericInquiryRequest.xsd"
    xmlns:ns3="http://www.etisalat.ae/Middleware/SharedResources/Common/Common.xsd">
    <ns0:RequestedSystem>rtr</ns0:RequestedSystem>
    <ns0:Action>Business</ns0:Action>
    <ns0:ModeType>ghyg</ns0:ModeType>
    <ns0:RequestDetails>dghdg</ns0:RequestDetails>
    <ns0: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>1</ns2:TransactionID>
    <ns2:RequestedSystem>mCashier</ns2:RequestedSystem>
    <ns2:RetryLimit>1</ns2:RetryLimit>
    </ns2:ApplicationHeader>
    <ns1:DataHeader>
    <ns1:RequestID>186060639</ns1:RequestID>
    </ns1:DataHeader>
    </ns1:GetOrderPaymentDetailsRequest>
    </ns0:RequestDetailsAny>

    <ns3:AdditionalInfo>
    <ns3:Name></ns3:Name>
    <ns3:Value></ns3:Value>
    </ns3:AdditionalInfo>
    </ns0:GenericInquiryRequest>
    </soapenv:Body>
    </soapenv:Envelope>


    Regards
    Prashant Sidana

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



  • 5.  RE: Switch case implementation - using input request XML parameter

    Posted 07/08/19 04:41 PM

    Hi Sampath,

    The parse policy will simply create an XML DOM or JSON object from a string in a context.  That context can be updated in place or the parsed structure can we written to a different context.

    As for your GatewayScript, can I assume by your posts in another thread that you are past the issues you were encountering?  As I indicated elsewhere and Mohd also noted in this thread, you can simply have a map policy provide your input XML schema and it will map to your output structure without requiring a gatewayscript policy to proceed the map policy.

    Regards,

    Steve




  • 6.  RE: Switch case implementation - using input request XML parameter

    Posted 07/03/19 08:50 AM
    If you have predefined structure for your soap request, you can define objects in your definitions and use them in map policy to map to backend wsdl.

    ------------------------------
    Mohd Ahmed Siddiqui
    ------------------------------



  • 7.  RE: Switch case implementation - using input request XML parameter

    Posted 07/10/19 12:54 AM
    Edited by SAMPATH K 07/10/19 08:01 AM
    Thank you everyone , I am able to fix this problem.
    I can parse the input message now and is able to make a back end call. 

    Hi Stephen, 
    The reason why i was using the gateway script is because my input XML contains another XML string in the input request , so as to read that string I have used gateway script. 

    Please suggest if there is any other way do it. 

    Regards
    Sampath

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