7
Mule ESB SIMPLE INTERACT BETWEEN HTTP AND JAVA COMPONENTS

Simple interact between http and java components

Embed Size (px)

Citation preview

Page 1: Simple interact between http and java components

Mule ESB

SIMPLE INTERACT BETWEEN HTTP AND JAVA COMPONENTS

Page 2: Simple interact between http and java components

Open Anypoint Studio

Create a File New Mule Project

Click «Finish»

Page 3: Simple interact between http and java components

• Expand the «myfirstproject» on package explorer

Double click on myfirstproject.xml

Once file is open, show Message Flow

From Mule Palette view, search for ‘HTTP’ and ‘Java’ and select the first one.

Drag and Drop HTTP then Java component into Message Flow view.

Page 4: Simple interact between http and java components

Now we have to configure listener for our HTTP flow.

Double click on HTTP blue element.Below it will appear HTTP view.

On the General Setting let’s create and choose an HTTP Listener.

Click on Add(+) and configure:Host: default (localhost)Port: 8081

On Basic Settings define web service:Path: /filetransferAllow.Methods: GET

Click OK and SAVE

Page 5: Simple interact between http and java components

Now we have to configure the Java logic component.Create a package and a Java class under src/main/java folder.

Create a local folder to save the file.

The class will create a simple text file and write two lines.

Libraries I used:java.io.File;java.io.FileWriter;

Click on SAVE at top-left of screen

Page 6: Simple interact between http and java components

Configure Java component.

Transformer Class: the class that will do the logic to create a file in a local folder.

Click on SAVE.

Page 7: Simple interact between http and java components

Now we can start our Mule server

Right Click on project Run As Mule Application

On the Console view below server is going to start.

At the end you will see the status DEPLOYED.This means that server is up and running

Open your browser and join the HTTP path: http://localhost:8081/filetransfer

Now we can see the result: open the folder we created and look at the txt file generated.

Go Mule, go!