simple interact between http and java components
Post on 10-Feb-2017
67 Views
Preview:
TRANSCRIPT
Mule ESB
SIMPLE INTERACT BETWEEN HTTP AND JAVA COMPONENTS
Open Anypoint Studio
Create a File New Mule Project
Click «Finish»
• 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.
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
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
Configure Java component.
Transformer Class: the class that will do the logic to create a file in a local folder.
Click on SAVE.
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!
top related