com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links' is unknown.

Sample 663: Using Multiple Sequences

Note that WSO2 EI is shipped with the following changes to what is mentioned in this documentation:

  • <PRODUCT_HOME>/repository/samples/ directory that includes all Integration profile samples is changed to <EI_HOME>/samples/service-bus/.
  • <PRODUCT_HOME>/repository/samples/resources/ directory that includes all artifacts related to the Integration profile samples is changed to <EI_HOME>/samples/service-bus/resources/.

Introduction

This sample demonstrates how a complex sequence can be separated into a set of simpler sequences. In this sample, you will send a simple request to a back-end service (StockQuoteService microservice) and receive a response. If you look at the sample's XML configuration, you will see how this mediation is performed by two separate sequence definitions instead of one main sequence.

Prerequisites

For a list of prerequisites, see Prerequisites to Start the ESB Samples.

Building the sample

Expand the link given below to see the XML configuration of this sample. This configuration file (synapse_sample_663.xml) is available in the <EI_HOME>/samples/service-bus directory.

 synapse_sample_663.xml

<?xml version="1.0" encoding="UTF-8"?>
<definitions xmlns="http://ws.apache.org/ns/synapse">
<proxy name="SequenceBreakdownSampleProxy" startOnLoad="true" transports="http https">

      <description/>

      <target inSequence="StockQuoteSeq"/>

  </proxy>

  <sequence name="StockQuoteSeq" onError="StockQuoteErrorSeq">

      <log level="custom">

          <property name="Sequence" value="StockQuoteSeq"/>

          <property name="Description" value="Request recieved"/>

      </log>

      <sequence key="CallStockQuoteSeq"/>

      <sequence key="TransformAndRespondSeq"/>

  </sequence>

  <sequence name="StockQuoteErrorSeq">

      <log level="custom">

          <property name="Description" value="Error occurred in StockQuoteErrorSeq"/>

          <property name="Status" value="ERROR"/>

      </log>

  </sequence>

  <sequence name="TransformAndRespondSeq" onError="TransformAndRespondErrorSeq">

      <log level="custom">

          <property name="Sequence" value="TransformAndRespondSeq"/>

          <property name="Description" value="Response is ready to be transformed"/>

      </log>

      <payloadFactory media-type="xml">

          <format>

              <Information xmlns="">

                  <Name>$1</Name>

                  <Last>$2</Last>

                  <High>$3</High>

                  <Low>$4</Low>

              </Information>

          </format>

          <args>

              <arg evaluator="json" expression="$.name"/>

              <arg evaluator="json" expression="$.last"/>

              <arg evaluator="json" expression="$.low"/>

              <arg evaluator="json" expression="$.high"/>

          </args>

      </payloadFactory>

      <log level="custom">

          <property name="Sequence" value="TransformAndRespondSeq"/>

          <property name="Description" value="Responding back to the client with the transformed response"/>

      </log>

      <respond/>

  </sequence>

  <sequence name="TransformAndRespondErrorSeq">

      <log level="custom">

          <property name="Description" value="Error occurred in TransformAndRespondSeq"/>

          <property name="Status" value="ERROR"/>

      </log>

  </sequence>

  <sequence name="CallStockQuoteErrorSeq">

      <log level="custom">

          <property name="Description" value="Error occurred in CallStockQuoteSeq"/>

          <property name="Status" value="ERROR"/>

      </log>

  </sequence>

  <sequence name="CallStockQuoteSeq" onError="CallStockQuoteErrorSeq">

      <switch source="//symbol" xmlns:ns="http://org.apache.synapse/xsd">

          <case regex="IBM">

              <log level="custom">

                  <property name="Sequence" value="CallStockQuoteSeq"/>

                  <property name="Description" value="Calling IBM endpoint"/>

              </log>

              <call blocking="true">

                  <endpoint>

                      <http method="GET" uri-template="http://localhost:9090/stockquote/IBM"/>

                  </endpoint>

              </call>

              <log level="custom">

                  <property name="Sequence" value="CallStockQuoteSeq"/>

                  <property name="Description" value="Response received from IBM endpoint"/>

              </log>

          </case>

          <case regex="GOOG">

              <log level="custom">

                  <property name="Sequence" value="CallStockQuoteSeq"/>

                  <property name="Description" value="Calling GOOG endpoint"/>

              </log>

              <call blocking="true">

                  <endpoint>

                      <http method="GET" uri-template="http://localhost:9090/stockquote/GOOG"/>

                  </endpoint>

              </call>

              <log level="custom">

                  <property name="Sequence" value="CallStockQuoteSeq"/>

                  <property name="Description" value="Response received from GOOG endpoint"/>

              </log>

          </case>

          <case regex="AMZN">

              <log level="custom">

                  <property name="Sequence" value="CallStockQuoteSeq"/>

                  <property name="Description" value="Calling AMZN endpoint"/>

              </log>

              <call blocking="true">

                  <endpoint>

                      <http method="GET" uri-template="http://localhost:9090/stockquote/AMZN"/>

                  </endpoint>

              </call>

              <log level="custom">

                  <property name="Sequence" value="CallStockQuoteSeq"/>

                  <property name="Description" value="Response received from AMZN endpoint"/>

              </log>

          </case>

          <default>

              <log level="custom">

                  <property name="Sequence" value="CallStockQuoteSeq"/>

                  <property name="Description" value="Invalid Symbol"/>

                  <property name="Status" value="ERROR"/>

              </log>

              <drop/>

          </default>

      </switch>

  </sequence>

</definitions>

To build the sample:

  1. Start the ESB profile of WSO2 EI with the sample 663 configuration. See Starting the ESB with a sample configuration for instructions.

    The operation log keeps running until the server starts, which usually takes several seconds. Wait until the server has fully booted up and displays a message similar to "WSO2 Carbon started in n seconds."
  2. Start the StockQuoteService microservice using the MSF4j profile of WSO2 EI:
    1. Download the StockQuoteService microservice and copy the JAR file to the <EI_HOME>/wso2/msf4j/deployment/microservices directory.
    2. Open a command terminal, navigate to the <EI_HOME>/wso2/msf4j/bin directory and start the MSF4j server by executing the relevant startup script:
      • On Linux: carbon.sh
      • On Windows: carbon.bat

Executing the sample

Send the following request to invoke the sample proxy service (named SequenceBreakdownSampleProxy) in the sample.

curl -v http://localhost:8280/services/SequenceBreakdownSampleProxy -H'Content-Type:application/xml' -d'<symbol>IBM</symbol>'

When this request is sent, SequenceBreakdownSampleProxy calls the StockQuoteSeq sequence. This sequence calls CallStockQuoteSeq and TransformAndRespondSeq respectively. In CallStockQuoteSeq, according to the symbol that is sent, the endpoint that is being called is switched using the Switch mediator. Once the response is received from the endpoint, it is transformed with TransformAndRespondSeq , and sent back to the client. Also, note that an error sequence has been defined for each sequence, which will be executed in case of an error.

Analyzing the output

The output in the log for the above sample request would be as follows:

[2017-06-26 18:56:11,877] [EI-Core]  INFO - LogMediator SEQUENCE = StockQuoteSeq|DESCRIPTION = Request recieved
[2017-06-26 18:56:11,880] [EI-Core]  INFO - LogMediator SEQUENCE = CallStockQuoteSeq|DESCRIPTION = Calling IBM endpoint
[2017-06-26 18:56:11,941] [EI-Core]  INFO - LogMediator SEQUENCE = CallStockQuoteSeq|DESCRIPTION = Response received from IBM endpoint
[2017-06-26 18:56:11,942] [EI-Core]  INFO - LogMediator SEQUENCE = TransformAndRespondSeq|DESCRIPTION = Response is ready to be transformed
[2017-06-26 18:56:11,958] [EI-Core]  INFO - LogMediator SEQUENCE = TransformAndRespondSeq|DESCRIPTION = Responding back to the client with the transformed response

As shown in the above log, since the “symbol” that is sent in the request is “IBM”, the request is routed to the IBM endpoint. Once the response from the IBM endpoint is received, it is transformed according to the specified template and sent to the client. 

Shown below is the response that will be received by the client.

<Information>
   <Name>International Business Machines</Name>
   <Last>149.62</Last>
   <High>150.78</High>
   <Low>149.18</Low>
</Information>
com.atlassian.confluence.content.render.xhtml.migration.exceptions.UnknownMacroMigrationException: The macro 'next_previous_links2' is unknown.