Send data to remote REST web application using Mule ESB

In this tutorial I am going to show you how to send data from Mule application to remote web application which is basically a REST webservice application.

Eclipse, JDK 1.8, JAX-RS jars 2.23.2
Have maven installed and configured
JAX-RS dependencies in pom.xml

For this tutorial we will create a web maven project in Eclipse. If you already have an idea on how to create a maven project in Eclipse will be great otherwise I will tell you here how to create a maven project in Eclipse.

Step 1. Create a web maven project in Eclipse

Go to File -> New -> Other. On popup window under Maven select Maven Project. Then click on Next. Select the workspace location – either default or browse the location. Click on Next. Now in next window select the row as highlighted from the below list of archtypes and click on Next button.

Now enter the required fields (Group Id, Artifact Id) as shown below
Group Id : com.roytuts
Artifact Id : rest
Step 2. Modify the pom.xml file as shown below.

<project xmlns="" xmlns:xsi=""
	<name>rest Maven Webapp</name>

Step 3. If you see JRE System Library[J2SE-1.5] then change the version by below process

Do right-click on the project and go to Build -> Configure build path, under Libraries tab click on JRE System Library[J2SE-1.5], click on Edit button and select the appropriate jdk 1.8 from the next window. Click on Finish then Ok.

Step 4. Modify web.xml file to use the jersey servlet

 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "" >
	<display-name>REST Service</display-name>
	<!-- Map /rest/* to Jersey -->

Step 5. Create a REST resource class as shown below

public class HelloRestService {
	public void sayHello(String message) {
		System.out.println("Message received : " + message);

Step 6. Now run the application on Tomcat 8.

Mule Application

Let’s see how you can use an HTTP outbound endpoint to POST data to a URL. Using HTTP as a message source is just as easy.

Now we will create Mule application which will read data from file, convert to string and send to above remote REST application.


Mule Studio 3.x(Anypoint Studio) (Download from
Maven 3.2.1 (Download from
JDK 1.7 (Download from
Configure JDK, Maven and Mule Studio

Step 1. First install JDK
Step 2. Add the Java_Home/bin directory to your system’s PATH.
Step 3. After downloading Maven, extract it to a drive
Step 4. Add the M2_Home/bin directory to your system’s PATH.
Step 5. Download and extract Mule Studio to a drive
Step 6. Now start Mule Studio by clicking on AnypointStudio exe icon in the folder <physical drive>/AnypointStudio
Step 7. Once started, close the startup page
Step 8. In Mule Studio, go to Window -> Preferences. Expand Java, then click on Installed JREs. Add JDK 1.7 and select it. In expanded Java, click on Compiler and select the compiler level as 1.7
Step 9. Now expand Anypoint Studio and click on Maven Settings. Then select appropriate Maven installation home directory using Browse button.
Step 10. If you want you can input Default groupId for new projects, it will save your time every time when you want to create a new project.

Create Mule project in Mule Studio
Now we will see how to create a new project in Mule Studio(Anypoint Studio).

Step 1. In Anypoint Studio, go to File -> New -> Mule Project
Step 2. Input Project Name: mule, Runtime is by default selected, tick on Use Maven; here the artifactId is automatically picked up from the Project Name:, the Group Id is picked up from the Default groupId for new projects and version is also a default value.
Step 3. Click Next and verify the JDK, mainly select Use default JRE(currently ‘jdk1.7.0_x’)
Step 4. Click on Next and click on Finish.


The below screen-shot shows the graphical representation of the Mule flow

Step 1. Create the post-data-with-http-transport.xml file under src/main/app directory and put the below file connector. While you create the xml file you will see on red mark on each file connector. Do not worry, red mark will be disappeared once you modify the xml file as given in Step 3.

mule post data to remote application

Step 2. Open the post-data-with-http-transport.xml file and click on Configuration XML view in the Editor
Step 3. Modify the post-data-with-http-transport.xml file as shown below

<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:file=""
	xmlns:http="" xmlns:tracking=""
	xmlns="" xmlns:doc=""
	xmlns:spring="" version="EE-3.5.1"
	<flow name="post-data-with-http-transport-flow" doc:name="post-data-with-http-transport-flow">
		<file:inbound-endpoint path="D:mule_workspaceinput_files"
			responseTimeout="10000" doc:name="File" />
			doc:name="File to String" />
		<http:outbound-endpoint exchange-pattern="one-way"
			host="${}" port="${rest.service.port}" path="${rest.service.path}"
			method="POST" doc:name="HTTP" />

In the above configuration we a Mule flow named as post-data-with-http-transport-flow and inside this flow there are one file connector, which is acting as inboud-endpoint, a file-to-string transformer, which transforms file data into string and another one is http transport as outbound-endpoint, which is responsible for sending data to remote REST service.

Step 4. Open the file src/main/app/ and put the below key/value pairs

Step 6. Create hello.txt file and put it under D:mule_workspaceinput_files with below content inside the file.

Hello, World!

Running the application

Now do a right-click on the post-data-with-http-transport.xml file and click on Run As -> Mule Application. Then you will see something like below in Console when the application runs

INFO  2016-09-25 07:50:52,874 [main] org.mule.DefaultMuleContext:
* Application: mule                                                  *
* OS encoding: Cp1252, Mule encoding: UTF-8                          *
*                                                                    *
* Agents Running:                                                    *
*   DevKit Extension Information                                     *
*   Batch module default engine                                      *
*   Clustering Agent                                                 *
*   JMX Agent                                                        *
INFO  2016-09-25 07:50:52,874 [main] org.mule.module.launcher.MuleDeploymentService:
+ Started app 'mule'                                       +
INFO  2016-09-25 07:50:52,877 [main] org.mule.module.launcher.DeploymentDirectoryWatcher:
+ Mule is up and kicking (every 5000ms)                    +
INFO  2016-09-25 07:50:59,843 [[mule].connector.file.mule.default.receiver.01] org.mule.transport.file.FileMessageReceiver: Lock obtained on file: D:mule_workspaceinput_fileshello.txt
INFO  2016-09-25 07:50:59,909 [[mule].connector.http.mule.default.dispatcher.01] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO  2016-09-25 07:50:59,914 [[mule].connector.http.mule.default.dispatcher.01] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default response transformer: org.mule.transport.http.transformers.MuleMessageToHttpResponse
INFO  2016-09-25 07:50:59,929 [[mule].connector.http.mule.default.dispatcher.01] org.mule.transport.service.DefaultTransportServiceDescriptor: Loading default outbound transformer: org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest
INFO  2016-09-25 07:50:59,930 [[mule].connector.http.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Initialising: 'connector.http.mule.default.dispatcher.11971339'. Object is: HttpClientMessageDispatcher
INFO  2016-09-25 07:50:59,934 [[mule].connector.http.mule.default.dispatcher.01] org.mule.lifecycle.AbstractLifecycleManager: Starting: 'connector.http.mule.default.dispatcher.11971339'. Object is: HttpClientMessageDispatcher
INFO  2016-09-25 07:50:59,955 [[mule].connector.http.mule.default.dispatcher.01] org.mule.transport.http.transformers.ObjectToHttpClientMethodRequest: Content-Type not set on outgoing request, defaulting to: text/plain

Once the application is up and running put the hello.txt file under D:mule_workspaceinput_files, you will receive the message “Message received : Hello, World!” in the REST webservice Eclipse console.

Thanks for reading.

Leave a Reply

Your email address will not be published. Required fields are marked *