This documentation is for WSO2 Enterprise Service Bus version 5.0.0. For the latest ESB, view the latest WSO2 Enterprise Integrator documentation.

All docs This doc

Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Table of Contents
maxLevel3
minLevel3
locationtop
styleborder:1
locationtop
typeflat
separatorpipe

...

Setup

...

The parameters available for configuring the Callout mediator are as follows. 

Parameter NameDescription
Specify As

This parameter determines whether the target external service should be configured by using either a serviceURL attribute or an endpointKey attribute.

Note

Callout mediator does not support endpoint configurations such as timeout, suspendOnFailure and markForSuspension when the endpointKey attribute is used to specify an existing endpoint.

  • URL: Select URL if you want to call the external service by specifying its URL in the Call mediator configuration.
  • Address Endpoint: Selected Address Endpoint if you want to call the external service via an Endpoint which is already saved in the Registry. This option should be selected if you want to make use of the WSO2 functionality related to endpoints such as format conversions, security etc. Note that only Leaf endpoint types (i.e.  Address WSDL Default  and  Http ) are supported for the Callout mediator.

If neither a URL or an address endpoint is specified, the To header on the request is used as the target endpoint.

URLIf you selected URL for the Specify As parameter, use this parameter to enter the URL of the external service that you want to call. This URL will be used as the End Point Reference (EPR) of the external service.
Address EndpointIf you selected Address Endpoint for the Specify As parameter, use this parameter to enter key to access the endpoint that should be used to call the external service. Click Configuration Registry or Governance Registry as relevant to select the required endpoint from the resource tree.
ActionThe SOAP action which should be appended to the service call.
Axis2 RepositoryThe path to Axis2 client repository where the services and modules are located. The purpose of this parameter is to make the Callout mediator initialize with the required client repository.
Axis2 XMLThe path to the location of the Axis2.xml configuration file. The purpose of this parameter is to make the Callout mediator initialize with the relevant Axis2 configurations.
initAxis2ClientOptionsIf this parameter is set to false, the existing Axis2 client options available in the Synapse message context will be reused when the Callout mediator is invoked. This is useful when you want to use NLTM authentication. The default value for this parameter is true.
Source

This parameter defines the payload for the request. It can be defined using one of the following options.

  • XPath - This option allows you to specify an expression that defines the location in the message.

    Info
    titleTip

    You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. 

  • Property - This option allows you to specify the payload for a request via a property included in the mediation flow.
  • Envelope - This option allows you to select the entire envelope which is available in the message flow as the source.
Target

The node or the property of the request message to which the payload (resulting from the value specified for the Source parameter) would be attached. The target can be specified using one of the following options.

  • XPath - This option allows you to specify an expression that defines the location in the message.

    Info
    titleTip

    You can click NameSpaces to add namespaces if you are providing an expression. Then the Namespace Editor panel would appear where you can provide any number of namespace prefixes and URLs used in the XPath expression. 

  • Property - This option allows you to specify a property included in the mediation flow.
WS-Security

If this check box is selected, WS-Security is enabled for the Callout mediator. This section would expand as shown below when you select this check box.

Image Modified

Specify as Inbound and Outbound Policies

If this check box is selected, you can define separate security policies for the inbound and outbound messages (flows). This is done by entering the required policy keys in the Outbound Policy Key and Inbound Policy Key parameters which are displayed as follows when this check box is selected. You can click Configuration Registry or Governance Registry to select a security policy saved in the Registry from the resource tree.

Image Modified

Policy KeyIf the Specify as Inbound and Outbound Policies check box is not selected, this parameter is used to enter a key to access a security policy which will be applied to both inbound and outbound messages. You can click Configuration Registry or Governance Registry to select a security policy saved in the Registry from the resource tree.
Info
titleNote

You can configure the mediator using XML. Click switch to source view in the Mediator window.

Examples

Following examples demonstrate the usage of the Callout mediator.

Example 1 - Performing a direct service invocation

In this example, the Callout Mediator does the direct service invocation to the StockQuoteService using the client request, gets the response, and sets the response as the first child of the SOAP message body. You can then use the Send Mediator to send the message back to the client.

Code Block
XML
XML
<callout serviceURL="http://localhost:9000/services/SimpleStockQuoteService"
         action="urn:getQuote">
    <source xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
            xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
    <target xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/"
            xmlns:s12="http://www.w3.org/2003/05/soap-envelope"
            xpath="s11:Body/child::*[fn:position()=1] | s12:Body/child::*[fn:position()=1]"/>
</callout>

...

Example 2 - Setting an HTTP method when invoking a REST service

The below example uses a Callout mediator to set a HTTP method when invoking a REST service.

Info

For this, you need to define the following property: <property name="HTTP_METHOD" expression="$axis2:HTTP_METHOD" scope="axis2-client"/>

Code Block
XML
XML
<proxy xmlns="http://ws.apache.org/ns/synapse"
       name="CalloutProxy"
       startOnLoad="true"
       statistics="disable"
       trace="disable"
       transports="http,https">
   <target>
      <inSequence>
         <property name="enableREST"
                   scope="axis2-client"
                   type="BOOLEAN"
                   value="true"/>
         <property expression="$axis2:HTTP_METHOD"
                   name="HTTP_METHOD"
                   scope="axis2-client"/>
         <callout initAxis2ClientOptions="false"
                  serviceURL="http://localhost:8280/callout/CalloutRESTApi">
            <source type="envelope"/>
            <target key="response"/>
         </callout>
         <log level="custom">
            <property expression="$ctx:response" name="MESSAGE###########################3"/>
         </log>
         <property expression="$ctx:response" name="res" type="OM"/>
         <property action="remove" name="NO_ENTITY_BODY" scope="axis2"/>
         <property name="RESPONSE" value="true"/>
         <property name="messageType" scope="axis2" value="application/xml"/>
         <header action="remove" name="To"/>
         <payloadFactory media-type="xml">
            <format>
               <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">
                  <soapenv:Header/>
                  <soapenv:Body>$1
                  </soapenv:Body>
               </soapenv:Envelope>
            </format>
            <args>
               <arg evaluator="xml" expression="$ctx:res"/>
            </args>
         </payloadFactory>
         <send/>
      </inSequence>
   </target>
   <description/>
</proxy>


Samples

  Sample 430: Callout Mediator for Synchronous Service Invocation .