IBM Integration Bus, Version 9.0.0.8 Operating Systems: AIX, HP-Itanium, Linux, Solaris, Windows, z/OS

See information about the latest product version

Providing a JSONP service

Configure your IBM® Integration Bus message flow to provide a JSONP service response.

Before you start:

Before completing this task, read the following overview topics about JSON:
You can use ESQL, PHP, or Java™ to configure your message flow to provide a JSONP response.
The code examples in this task assume that the client application provides a JavaScript call in the following format:
<script type="text/javascript"
 src="http://brokerhost:7080/flowUrlPathSuffix?jsonp=scriptFn">
</script>
  1. On the Advanced tab of your HTTPInput node, select Parse Query String. This option enables you to access the JSONP script prefix that is included in the incoming URL, for example scriptFn, from the local environment tree.
  2. Insert the following code, as appropriate:
    • If your message flow uses a Compute node:
      SET OutputRoot.JSON.Padding = InputLocalEnvironment.HTTP.Input.QueryString.jsonp;
      SET OutputRoot.JSON.Data.objectName = 'thing1';
    • If your message flow uses a PHPCompute node:
      $output_assembly->JSON->Padding = 
           $input_assembly[MB_LOCAL_ENVIRONMENT]->HTTP->input->QueryString->jsonp;
      $output_assembly->JSON->Data->ObjectName = "thing1";
    • If your message flow uses a JavaCompute node:
      MbMessage outMessage = new MbMessage();
      MbElement outRoot = outMessage.getRootElement();
      MbElement outParser = outRoot.createElementAsLastChild(MbJSON.PARSER_NAME);
      String paddingString = 
          assembly.getLocalEnvironment().getRootElement().getFirstElementByPath("HTTP/Input/QueryString/jsonp").getValueAsString();
      MbElement padding = outParser.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Padding", paddingString);
      MbElement data = outParser.createElementAsLastChild(MbElement.TYPE_NAME, "Data", null);
      data.createElementAsLastChild(MbElement.TYPE_NAME_VALUE,"objectName","thing1");
    This code generates the following bit stream, sent as the HTTP reply:
    scriptFn( {"objectName":"thing1"} )

    This bit stream causes the JavaScript function scriptFn to be called with the JSON object as a parameter.


bc40100_.htm | Last updated Friday, 21 July 2017