DataPower

DataPower

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.

 View Only
  • 1.  Gateway script to route to different rules based on content type

    Posted 07/16/21 02:07 PM

    Hi - I am trying to write a gateway script in DataPower 10.x firmware version which could route the message to either XML rule or JSON rule based on contentType but the JSON msg is always failing in this case.

    /*

    GatewayScript to read incoming msg type & route to different rule

    */

    var hm = require('header-metadata');

    var service = require('service-metadata');

    var contentType = hm.current.get('content-type');

    console.debug('contentType: %s', contentType);

    session.input.readAsXML(

    function (readAsXMLError, data) {

    if (readAsXMLError) {

    session.input.readAsJSON(function (readAsJSONError, jsonData) {

    if (readAsJSONError) {

    session.input.readAsBuffers(function (readAsBuffersError, blob) {

    console.error('Data is neither xml nor json ', blob);

    });

    } else {

    if (contentType.includes("contentType", "*json*")) {

    // processing as json message

    session.INPUT.setVariable('callrule', 'RESTJSON-v01_Request_Handler')

    } else {

    console.error('Failed to process json message ', jsonData);

    }

    }

    });

    } else {

    if (contentType.includes("contentType", "*xml*")) {

    // processing as xml message

    session.INPUT.setVariable('callrule', 'RESTXML-v01_Request_Handler');

    } else {

    console.error("Failed to process xml message ", data);

    }

    }

    }

    );



    #DataPower
    #Support
    #SupportMigration


  • 2.  RE: Gateway script to route to different rules based on content type

    Posted 07/16/21 03:13 PM

    text/xml; charset=UTF-8



    #DataPower
    #Support
    #SupportMigration


  • 3.  RE: Gateway script to route to different rules based on content type

    Posted 07/16/21 03:17 PM

    application/json;charset=UTF-8



    #DataPower
    #Support
    #SupportMigration


  • 4.  RE: Gateway script to route to different rules based on content type

    Posted 07/16/21 03:25 PM

    Need help with fixing the gateway script since it is always going to error condition for JSON with error 'Data is neither xml nor json' even though the correct content-Type is passed to it.



    #DataPower
    #Support
    #SupportMigration


  • 5.  RE: Gateway script to route to different rules based on content type

    Posted 08/09/21 10:03 AM

    After some changes it worked for me.

    var contentType = hm.current.get('content-type'); => var contentType = hm.current.get('Content-Type');

    if (contentType.includes("contentType", "*json*")) => if (contentType.includes( "json"))

    if (contentType.includes("contentType", "*xml*")) => if (contentType.includes( "xml"))

    /Jocke D



    #DataPower
    #Support
    #SupportMigration