Contact Free trial Login

Mule Components

componentComponents are message processors which execute business logic on messages. They enable you to perform specific actions without writing any Mule-specific code. You can drop a component – a POJO, Spring bean, Java bean, or script – into a flow to perform almost any customized task within your Mule application. For example, you can use a component to verify that items on an invoice are in stock in a warehouse, or to update a database with a customer’s order history.

Scripting Components

Mule includes several scripting components that you can use in flows in order to execute custom business logic. These components enable you to drop a chunk of custom-written logic into your flow to act upon messages.


The example below illustrates the use of a Groovy script component. The script uses the value of state to determine which of four sales regions to which to assign the lead.

Web Service Components

Also included are two components to facilitate exposing, consuming, and proxying Web services. The CXF component leverages the CXF framework Mule uses to support SOAP Web services; the REST component works with Jersey to support RESTful Web services; both are bound to HTTP.

rest cxf
APIkit offers a new and improved way of building a REST API. Access the APIkit Documentation to learn how to build REST APIs in a few hours or days.

HTTP Components

Further, Mule provides two HTTP components to facilitate working with calls over HTTP. Use the HTTP Response Builder to convert a message into a format consistent with HTTP responses; use the HTTP Static Resource Handler to easily serve up static content when called.


Other Components

Finally, Mule includes several other components designed to meet rather specific needs.

  • Use a Logger component to log activities in the flow as they occur.

  • Use an Expression component to evaluate a particular expression upon a message in a flow.

  • Use an Invoke component to invoke the method of an object specified with a Mule expression.

  • Use an Echo component to return the payload of a message as a call response.

  • Use a Flow Ref component to access another flow from within a flow.

  • Use a Batch Execute component to kick off processing of a batch job.


Groovy Script Component Example

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting=""


    <flow name="LookUpSalesRegionFlow" doc:name="LookUpSalesRegionFlow" doc:description="The script uses data in the state field to add a region to the payload according to location.">
        <scripting:component doc:name="Groovy">
            <scripting:script engine="Groovy">def region = "UNKNOWN"
def state = payload['state']
if (state != null) {
 state = state.toUpperCase()
println "State to lookup is: " + state
switch (state) {
        case ["CT","ME","MA","NH","VT","RI","NY","NJ","DE","DC","MD","NH"]:
            region = "North East"
        case ["AL","AR","FL", "GA","LA" ,"SC","NC","TN","TX"]:
            region = "South East"
        case ["ID","IL", "IA","KS","MT", "WY","ND","SD","OH" ]:
            region = "Mid West"
        case ["AZ","CO","OK","NM", "NV"]:
            region = "South West"
        case ["CA","HI","WA","OR", "AK"]:
            region = "West Coast"
return ["region":region]</scripting:script>
        <logger message="Region is : #[payload.region]" level="INFO" doc:name="Logger"/>


REST Component Example

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:jersey="" xmlns:http="" xmlns="" xmlns:doc="" xmlns:spring="" xmlns:xsi="" xsi:schemaLocation="">

    <flow name="rest_exampleFlow1" doc:name="rest_exampleFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
        <jersey:resources doc:name="REST">
            <component class="example.RestExampleResource"/>


package example;


public class RestExampleResource {


    public String getExampleMsg(){
        return "REST and be well.";
        //return Response.status(Status.OK).entity("Rest and be well.").build();



Echo, Logger, and HTTP Components Examples

HTTP Response Builder

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="" xmlns:tracking="" xmlns="" xmlns:doc="" xmlns:spring="" xmlns:xsi="" xsi:schemaLocation="">

    <flow name="response-Builder2Flow1" doc:name="response-Builder2Flow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="builder" doc:name="HTTP"/>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
        <choice doc:name="Choice">
            <when expression="#[payload == 'kittens']">
                <echo-component doc:name="Echo"/>
                <http:response-builder status="400" contentType="text/plain" doc:name="HTTP Response Builder"/>


XML Editor or Standalone

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:http="" xmlns="" xmlns:doc="" xmlns:spring="" xmlns:xsi="" xsi:schemaLocation="">

    <flow name="static-handlerFlow1" doc:name="statice-handlerFlow1">
        <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" path="response" doc:name="HTTP"/>
        <http:static-resource-handler resourceBase="src/main/resources/index.html" doc:name="HTTP Static Resource Handler"/>


See Also

We use cookies to make interactions with our websites and services easy and meaningful, to better understand how they are used and to tailor advertising. You can read more and make your cookie choices here. By continuing to use this site you are giving us your consent to do this.