Bookmark and Share Share

Creating a Mashup Script

A mashup script is an XML file that uses the Enterprise Mashup Markup Language (EMML). They define the services and operations to be used by a mashup and the actions to apply to service responses to construct the results of the mashup.

Mashup scripts can be very simple, invoking a service and filtering the output for example. They also support virtually any level of complexity.

This task discusses how to create a mashup script. You can use any XML editor with the EMML schema in emml-install/schema/EMMLSpec.xsd.

  1. Open a new XML file in the editor of your choice and:

    1. Add <mashup> as the root element.

    2. Add the EMML namespace and optionally indicate the location of the EMML schema.

      Find the EMML schema at emml-install/schema/EMMLSchema.xsd. See EMML Namespaces for the current EMML namespace.

    3. Add a name attribute and enter the logical name for this mashup.

      Mashup names must be unique in the EMML Reference Runtime Engine where you deploy them. They must start with an ASCII letter. You may use ASCII letters or numbers in mashup names plus the underscore (_) and dash (-) characters.

    For example:

    <?xml version="1.0"?> 
    <mashup name="myMashup" 
        xlmns="www.openemml.org/2009-04-15/EMMLSchema" 
        xlmns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
        xsi:schemaLocation="www.openemml.org/2009-04-15/EMMLSchema ../schema/EMLLSchema.xsd"> 
    ... 
    </mashup>
    
  2. Add elements to invoke other services, define variables and perform actions on service results to define the mashup result. Declare any namespaces used in the script.

    The elements that you add to mashups fall into these categories:

    • Declarations for variables, parameters, data sources, namespaces, macros or metadata.

    • Statements that perform actions for the mashup. This includes statements to invoke services, control flow, act on the results or use custom statements defined in macros.

    For Use Operation Elements

    Declaring Mashup Variables and Parameters

    • <variables>: contains one or more <variable> definitions to hold the input or output for any mashup script statement.

    • <input>: defines an input parameter for this mashup.

    • <output>: defines the name and type for the result of this mashup.

    Declaring Namespaces

    xmlns attribute on <mashup> or <macro>: declares a namespace used by:

    • A service called in the mashup.

    • Macros called in the mashup. See Calling a Macro in a Mashup Script for more information.

    • Parameters or variables constructed with literal XML.

    Declaring Data Sources

    <datasource>: defines connection information to one database for use with SQL statements in this mashup.

    Invoking Component Services

    • <invoke>: reserved for future use to invoke a service that is virtually hosted and governed by another system.

    • <directinvoke>: Invokes a web service or web site at a publically accessible URL. Only HTML, RSS, REST web services or SOAP web services are supported.

    See also Controlling Service Invocation at Runtime and Web Clipping with a Mashup Script.

    Issuing SQL Statements to a Datasource

    • <sql>: to execute SQL queries to a datasource.

    • <sqlUpdate>: to execute any other SQL statement to a datasource.

    See also Invoking Stored Procedures.

    Transforming Intermediate Results

    • <assign>: copies, and optionally transforms, one variable or variable fragment to another variable. This uses XPath 2.0 expressions to identify the source nodes to copy and optionally applies XPath functions to transform the result.

      This statement can also be used to assign literal values.

    • <filter>: filters a set of nodes in a variable based on a filter expression in XPath 2.0.

    • <group>: sorts, and optionally filters, a set of nodes in a variable and constructs a result document based on those groups. This statement supports multiple levels of grouping and calculations or other transformations on groups.

    • <sort>: sorts a set of nodes in a variable based on sort keys and a sorting expression in XPath 2.0.

    • <annotate>: adds attributes or children elements to a selected node of a variable and assigns values using an XPath expression. This is typically used to add data to the mashup result or an intermediate variable.

    • <script>: defines a script to execute at runtime at the specified location in mashup processing. You can include JavaScript scripting code directly or point to an external file with any supported scripting language on the local server.

      The Mashup Engine supports both JavaScript and JRuby as scripting languages inside mashup scripts. Scripting can also access any Java class in the classpath.

    • <xslt>: defines an XSLT stylesheet to process at runtime at the specified location in mashup processing.

    Combining Component Service Results

    • <join>: joins the results of two or more services based on a join condition. This element works like a database join, where the results may be disparate but must have key nodes that determine how data is joined. You can also define the structure and nodes to include in the result of the join.

    • <merge>: merges the results of two or more services that have homogenous result models. The element works like a database union. The results of all services must have identical structures.

    Constructing the Mashup Result, Input or Intermediate Variables

    • <constructor>: creates a structure for the result of this mashup or for an intermediate variable. You define the nodes of the result and use mashup expressions to define the data from a variable to fill these nodes.

    • <appendresult>: appends a structure of nodes to the result of this mashup or to an intermediate variable. This is typically used in repeating loops to handle results with repeated sections.

      You define the nodes of the structure to append and use mashup expressions to define the data from a variable to fill these nodes.

    • <select>: creates a structure for the mashup result or for an intermediate variable with only selected nodes from a repeating set of items.

    See also <join> with a <select> child and <group>.

    Controlling Mashup Processing Flow

    • <if>: handles if-elseif-else processing for a mashup script based on a condition defined in XPath 2.0. You can include any mashup statements in any section of <if>.

    • <for>: processes a loop of any mashup statements based on a sequential count.

    • <foreach>: processes a loop of any mashup statements either iterating sequentially through each node in a set of nodes from a variable or processing each loop concurrently. The set is an XPath 2.0 'sequence' defined by an expression.

    • <while>: processes a loop of any mashup statements as long as a condition is true. The condition is defined in a XPath expression.

    • <break>: explicitly stops processing the current loop and all subsequent loops in <for>, <foreach> or <while>. This can be used in <if>, <elseif> or <else> when they are used within looping statements.

    • <parallel>: processes groups of mashup statements concurrently, as separate parallel flows. The groups of statements for each concurrent task are defined within <sequence> children, which can include variable declarations and any mashup statement.

    • SQL Transactions: using <sqlBeginTransaction>, <sqlCommit> and <sqlRollback>.

    Defining and Using Custom Mashup Statements with Macros

    Supporting Debugging

    • <display>: sends debugging messages to the log and console, optionally including the value of a variable or a portion of a variable.

    • <assert>: defines assertions that are evaluated at runtime. Failures throw exceptions.

    Adding Metadata to Mashups

    For example:

    <?xml version="1.0"?> 
    <mashup name="NewsStories" 
        xmlns="www.openemml.org/2009-04-15/EMMLSchema" 
        xsi:schemaLocation="www.openemml.org/2009-04-15/EMMLSchema 
          ../schema/EMMLSpec.xsd" 
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" > 
      <variables> 
        <variable name="stories" type="document"/> 
      </variable> 
      <output name="result" type="document"/> 
      <directinvoke endpoint="http://rss.news.yahoo.com/rss/mostviewed" 
          method="GET" outputvariable="stories"/> 
      <filter inputvariable="stories" 
          filterexpr="matches($stories/rss/channel/item/description,'Business')" 
          outputvariable="result"/> 
    </mashup>
    
  3. Save your mashup script.