Access Keys:
Skip to content (Access Key - 0)
community header community tab mule tab galaxy tab muleforge tab

Echo Example

Some of the links on this page go to the Mule User Guide, which requires that you log in to see the links. Registration is free and takes only a few moments.

The example demonstrates how to expose a Mule ESB component over multiple transports. In this example, the component is exposed as an Axis web service that receives messages via System.in (request) and sends them via System.out (response).

Running the Application

  1. Make sure you have met the prerequisites and installed Mule according to the Installing Mule instructions.
  2. At the command line, navigate to the examples/echo directory under your Mule home directory.
  3. Type echo.bat on Windows or ./echo on UNIX.
  4. Follow the on-screen prompts.
  5. To stop Mule, type 'CTRL-C' in the Mule console window.

The Echo Component

The Echo service is based on a POJO component that implements the EchoService interface:

public interface EchoService
{
    public String echo(String echo);
}

The component looks like this:

package org.mule.components.simple;

public class EchoComponent extends LogComponent implements EchoService
{
    public String echo(String echo) {
        return echo;
    }
}

Configuring the Service

To configure the service, you add a <service> element to your Mule XML configuration file and provide the name attribute. You specify the class of the service component with the <component> element. To reference objects from the Spring registry, you would use the nested <spring-object> element instead.

<service name="EchoUMO">
    <component class="org.mule.component.simple.EchoComponent"/>
</service>

The class attribute must be the fully qualified path name to the class. The name attribute must be a unique name for the service.

You can also use the shortcut for the Echo service component by simply specifying the following element:

<echo-component/>

Invoking the Service

Next, you need to configure endpoints on the service so that it can be invoked. When you ran the example, you were prompted to enter something at the command line. When you entered something, you were invoking the EchoUMO service by providing input data from System.in, and then the data you entered was echoed back to you via System.out. The Mule STDIO transport manages this interaction.

Following is the configuration for the EchoUMO service with the endpoints included. Note that you can have multiple inbound endpoints.

<model name="echoSample">
  <service name="EchoUMO">
    <inbound>
        <stdio:inbound-endpoint system="IN"/> 
        <vm:inbound-endpoint path="echo"/> 
    </inbound>
    <echo-component/>
    <outbound>
      <pass-through-router>
        <stdio:outbound-endpoint system="OUT"/>
      </pass-through-router>
    </outbound>
  </service>
</model>

The <inbound> element allows one or more inbound endpoints to be configured for a service. In this example, one endpoint uses the STDIO transport, and the other uses the VM transport.

The <inbound-endpoint> element specifies both the transport to use and the address, path, or resource from which this component will receive events. This example uses transport-specific endpoints, so the STDIO endpoint just specifies IN to receive messages on System.in, and the VM endpoint specifies a path. Generic endpoint configuration can also be used by specifying a URI, such as vm://echo or http://locahost:8080. For more information, see [Configuring Endpoints] in the Mule User Guide.

The <outbound> element allows one or more outbound router elements to be configured that control how and where message are sent once they have been processed by the component. In this example, all message are sent via System.out using the pass-through router.

Lastly, you can configure a connector if you want to override the default configuration used by the transport specified on an inbound endpoint. In this example, let's override the STDIO transport's default connector configuration so that it will prompt the user for input:

<stdio:connector name="SystemStreamConnector"
                 promptMessage="Please enter something: "
                 messageDelayTime="1000"/>

Thats all the configuration needed to get the component running. To see the configuration file in its entirety, open echo-config.xml in the examples/echo/conf/ directory under your Mule installation directory.

Exposing the Service as a Web Service with Axis

To expose the EchoUMO service as a web service, you simply add the inbound Axis endpoint as follows:

<model name="echoSample">
  <service name="EchoUMO">
    <inbound>
      <axis:inbound-endpoint address="http://localhost:65081/services">
        <soap:http-to-soap-request-transformer/>
      </axis:inbound-endpoint>
      <vm:inbound-endpoint path="echo" />
    </inbound>
    <echo-component/>
  </service>
</model>

This new endpoint tells Mule to use Axis to expose the component as a service on the URL 'http://localhost:65081/services/EchoUMO'.

To invoke the component as a SOAP request, open a browser and type the following in the address bar:

http://localhost:65081/services/EchoUMO?method=echo&param=Is%20there%20an%20echo%20in%20here?

You should get a response back looking something like this:

<soapenv:Envelope>
    <soapenv:Body>
        <echoResponse soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
            <echoReturn xsi:type="xsd:string">Is there an echo in here?</echoReturn>
        </echoResponse>
    </soapenv:Body>
</soapenv:Envelope>

You just made a request via the Axis transport.

Exposing the Service as a Web Service with CXF

You could also run this example via CXF. CXF has built-in support for understanding GET requests, using the following syntax:

http://host/service/OPERATION/PARAM_NAME/PARAM_VALUE

Therefore, you could run this example by entering the following URL:

http://localhost:65082/services/EchoUMO/echo/text/hello

The endpoint would be defined in the Mule configuration file like this:

<cxf:inbound-endpoint address="http://localhost:65082/services/EchoUMO"
                 serviceClass="org.mule.example.echo.Echo"/>
Adaptavist Theme Builder (3.3.3-conf210) Powered by Atlassian Confluence 2.10, the Enterprise Wiki.
Free theme builder license