This page last changed on Oct 02, 2006 by lajos@mulesource.com.

The example demonstrates how to expose a Mule component over multiple transports, in this case as an Axis web sevice and via System.in (request) and System.out (response).
Cannot resolve external resource into attachment.

Running the Application

Prerequisites

To run you will need the following -

Optional

  • If you are asked to execute any Maven commands you'll need the Maven build tool from Apache. Mule has been tested with Maven 1.0.2. (Download Maven 1.0.2)

Running

  1. Open a shell*.
  2. From the root of the Mule distribution go to examples/ant/echo or examples/maven/echo.
  3. Run 'echo.sh' or 'echo.bat'
  4. Follow the on-screen prompts.
  5. To stop Mule, type 'CTRL-C' in the Mule console window

*Shell refers to a command shell in unix or linux and command prompt in windows.

The Echo Service

The echo Service is a POJO that implements an EchoService interface -

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

The implementation (i.e the POJO to be managed by Mule) looks like -

package org.mule.components.simple;

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

Configuring the Service

Now lets look at configuring the service. To do this you need to add a <mule-descriptor> config element to your Mule Xml configuration file and provide name and implementation attributes.

<mule-descriptor name="EchoUMO"
    implementation="org.mule.components.simple.EchoComponent">
</mule-descriptor>

The implementation attribute can be a class name or if you have an Object Container configured the implementationattribute can be a key name for an object in the container. This allows you to manage Spring Beans, EJB session beans or objects from any of the supported containers. The name attribute must be a unique name for the service.

Invoking the Service

Next we need to configure endpoints on the service so that it can be invoked. When you ran the example you would have been prompted to enter something in the shell (or command prompt).
When you entered something you were invoking the EchoServiceby providing input data from System.in, then the data you enter is echoed back to you via System.out. It is the Mule Stream transport that manages this interation.

Lets have a look at the configuration for this service.

<mule-descriptor name="EchoUMO"
    implementation="org.mule.components.simple.EchoComponent">

    <inbound-router>
        <endpoint address="stream://System.in"/>
    </inbound-router>

    <outbound-router>
        <router className="org.mule.routing.outbound.FilteringOutboundRouter">
            <endpoint address="stream://System.out"/>
        </router>
    </outbound-router>
</mule-descriptor>

The <inbound-router> element allows one or more inbound endpoint to be configured for a service. As you'll see in the next section it is really easy to expose your service over other transports such as SOAP.

The <endpoint> element defines an address which is a URI on which this component will receive events. In this case its using the 'stream' connector on System.in.

The <outbound-router> element allows one or more <router> elements to be configured that control how and where the response is sent. In this case all responses are sent via System.out.

The only other bit of configuration needed is the stream connector configuration that tells it to prompt you for input. The connector configuration looks like this -

<connector name="SystemStreamConnector"
    className="org.mule.providers.stream.SystemStreamConnector">
    <properties>
        <property name="promptMessage" value="Please enter something: "/>
        <property name="messageDelayTime" value="1000"/>
    </properties>
</connector>

Thats all the configuration needed to get the component Running.

You can see the whole configuration file for this example here.

Mule knows to use this connector by looking at the scheme on the endpoint URIs. When the connector is registered it tells Mule it knows how to handle 'stream://'.

Exposing EchoService as a Web Service

To expose the EchoService as a web service you need to tell Mule to expose the service as an Axis Service. This only requires a single line of configuration to the component descriptor -

<mule-descriptor name="EchoUMO"
    implementation="org.mule.components.simple.EchoComponent">

    <inbound-router>
        <endpoint address="stream://System.in"/>
        <endpoint address="axis:http://localhost:8081/services"/>
    </inbound-router>

    <outbound-router>
        <router className="org.mule.routing.outbound.FilteringOutboundRouter">
            <endpoint address="stream://System.out"/>
        </router>
    </outbound-router>
</mule-descriptor>

This new <endpoint> element in the <inbound-router> tells Mule to use Axis to expose the component as a service on URL 'http://localhost:8081/services/EchoUMO'. Thats it, there is no additional configuration required!

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

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

You sould 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>

Great! you just made a request via the Axis transport provider. If you wanted to use WebMethods Glue instead of Axis you would just replace 'axis:' with 'glue:' on the endpoint URI.

See Axis Web Services and Mule and Glue for more information.

Mule Config Graph for the Echo Example

This is a configuration graph generated for the Echo example using the Mule Config Graph Tool.
(Click on the thumb image for a bigger picture)


Document generated by Confluence on Oct 03, 2006 09:23