Simple interact between http and java components
-
Upload
domenico-schiavone -
Category
Software
-
view
67 -
download
1
Transcript of Simple interact between http and java components
![Page 1: Simple interact between http and java components](https://reader035.fdocuments.net/reader035/viewer/2022070509/589cf19a1a28abcc258b5095/html5/thumbnails/1.jpg)
Mule ESB
SIMPLE INTERACT BETWEEN HTTP AND JAVA COMPONENTS
![Page 2: Simple interact between http and java components](https://reader035.fdocuments.net/reader035/viewer/2022070509/589cf19a1a28abcc258b5095/html5/thumbnails/2.jpg)
Open Anypoint Studio
Create a File New Mule Project
Click «Finish»
![Page 3: Simple interact between http and java components](https://reader035.fdocuments.net/reader035/viewer/2022070509/589cf19a1a28abcc258b5095/html5/thumbnails/3.jpg)
• 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](https://reader035.fdocuments.net/reader035/viewer/2022070509/589cf19a1a28abcc258b5095/html5/thumbnails/4.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022070509/589cf19a1a28abcc258b5095/html5/thumbnails/5.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022070509/589cf19a1a28abcc258b5095/html5/thumbnails/6.jpg)
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](https://reader035.fdocuments.net/reader035/viewer/2022070509/589cf19a1a28abcc258b5095/html5/thumbnails/7.jpg)
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!