Mule Example SpellChecker - Basic Studio Tutorial
2013-07-04 16:06
579 查看
Basic Studio Tutorial
ContentsThis exercise is designed to introduce you to Mule Studio and help you get comfortable building applications.
We're
going to build a simple, single-flow spell checker application. The app calls the Google Spell Checker APIwhich performs the spell check, then
returns suggestions for misspelled words. When you have finished building it, you can submit XML files to the application to spell check the contents.
Quick Version of Tutorial
Launching Studio
If you have already launched Studio as part of the installation process, and it is now running, skip the rest of this section and proceed directly to: Creatinga New Project.
Navigate to the directory on your local drive in which you installed Studio.
Double-click the executable file to launch Studio.
MuleStudio.exein Windows
MuleStudio.appin Mac OS
MuleStudioin Linux
When Studio presents the Workspace Launcher dialog, click OK to accept the default workspace.
If this is the first time you have launched Studio, you may see a Welcome screen as per below. Click Go to Mule Studio to dismiss the
screen.
Creating a New Project
From the Studio application menu, click File > New > Mule Project.Studio opens the New Mule Project wizard. Fill in the Name field with the value
Spell Checker.
Click anywhere in the Description text box, then type comments pertaining to the project, if you wish.
Note that Studio populates the Server Runtime field with the server which comes bundled with Studio.
Click Next to proceed.
Studio prompts you to create a new flow in your new project. It auto-fills the flow Name field and flow File Name field using the name
of the Mule project you entered. Adjust the field values and add a description of the flow if you wish, then click Finish.
In the Package Explorer,
Spell Checker.mflowappears under the
flowsfolder and
mule-project.xmlappears under
the
srcfolder. The
.mflowfile stores flow information for the visual editor.
Setting Up Folders
The Spell Checker application requires the creation of two new folders:an
InXMLfolder to accept end user spell check requests
an
OutXMLfolder to return the spell check suggestions to the end user.
The Spell Checker application polls the
InXMLfolder every three seconds for end user file submissions. When it finds one, it processes the request (i.e. performs the spell check through the Google API), then puts the spell-checked file in the
OutXMLfolder
for the end user to view. As an end user, using this application is like feeding a document into the "IN" slot of a machine, then receiving the changed document in the machine's "OUT" tray.
Navigate to your folder on your local drive where you installed Mule Studio.
Navigate to the
Examples>
SpellCheckerfolder.
In the
SpellCheckerfolder, create two new folders, one labeled
InXML, one labeled
OutXML.
Modeling a Mule Flow
This first step in creating an application involves "modeling" the flow on your canvas. Drag and drop the flow's building blocks into place on the canvas to visual construct, or model, your flow. Then, with all the pieces in place in the order you want, youcan individually configure each building.
Click and drag a File endpoint, which resides in the palette's Endpoints group, onto the canvas.
Click and drag an HTTP endpoint onto the canvas, dropping it next to the File endpoint. An arrow appears which indicates the direction of the message
flow between the File component and the HTTP component.
Place an Echo component (in the palette's Component group) next to the HTTP endpoint, then place another File endpoint
next to the Echo component.
Configuring the Flow Components
Nearly all Mule components provide configuration options, which you can set in one of two ways:via the building block Properties dialogs in Studio's visual editor
via XML code in Studio's XML editor
The steps below details the procedure to configure the building blocks in the visual editor.
File Inbound Endpoint
Double-click the first File endpoint in your flow to open the Properties dialog (see image below). Note that Studio has automatically identified thisbuilding block as an Inbound Endpoint.
In the Display Name field, you have the option to enter a descriptive name for the endpoint such as
Incoming File,
which will appear directly under the File endpoint icon on the canvas.
In the Path field, enter the filepath of the
InXMLfolder you created such as,
Users/aaron/MuleStudio/examples/SpellChecker/InXML.
This tells the application where to look for new files from the end user.
In the Polling Frequency field, change the value from
1000to
3000. This tells the application how
often to poll the folder for new files; in this case, every 3000 milliseconds, or 3 seconds.
Click OK to complete the File endpoint configuration.
HTTP Endpoint
This endpoint retrieves information from a the Google Spell Checker API.Double-click the HTTP Enpoint to open the Properties dialog.
Optionally, enter a Display Name for the HTTP endpoint, such as
Invoke API.
In the Host field, type the URL of the Google Spell Check API:
www.google.com/tbproxy/spell?lang=en
In the Port field, type the port number the Google Spell Check server uses:
80
Use the drop-down menu in the Method field to select the method for communicating with the Google Spell Check server:
POST
Click OK to complete the HTTP endpoint configuration.
Are you behind a corporate firewall? Configure an HTTP Connector to inter-operate with your company's proxy server. |
Echo Component
The Echo Component, which displays the API's messages in the Studio console when the application runs, requires no configuration. Optionally, you can open the Properties dialog, then enter a Display Name for the component.
File Outbound Endpoint
Double-click the last File endpoint in your flow to open the Properties dialog.Optionally, enter a Display Name for the endpoint such as,
Outgoing File.
In the Path field, enter the file path of the
OutXMLfolder you created such as,
Users/aaron/MuleStudio/examples/SpellChecker/OutXML.
This tells the application where to save files.
In the Output pattern field, enter
#[function:datestamp:dd-MM-yy]_#[function:systime].xmlThis instructs Mule to combine a date stamp and
a time stamp when creating a file name for the output data it writes to the
OutXMLdirectory.
Click OK to complete the endpoint configuration.
Click Save to save the changes to the Spell Checker project.
Click the Configuration XML tab at the base of the canvas to switch from the visual editor to the XML editor. If you edit the XML code, Studio reflects your changes in the visual editor. This is known as "two-way editing". |
Running the Application
Having built, configured and saved your new application, you must run it on the Mule server (included as part of the bundled download of Mule Studio) before you use it.In the Package Explorer pane, right-click the
SpellChecker.mflowfile, then select Run As > Mule
Application.
Mule immediately kicks into gear, starting your application and letting it run. When startup is complete, Studio displays a message in the console that reads,
Started app 'spell_checker'.
Using the Application
Mule is now polling your InXMLfolder for XML files. To start a flow process, you need to copy an XML file into this folder (i.e. submit a file to be checked for spelling). Conveniently, an XML file with misspelled content is included with the
bundled download of Mule Studio. The following steps details how to submit this file to the Spell Check app to check for spelling.
Navigate to the Spell Checker folder on your local drive. For example,
Users/aaron/MuleStudio/examples/SpellChecker).
The
spellcheck.xmlfile in that folder contains some purposefully misspelled text: "
Creeating mi fiirst Mulle Studio aplication!"
Copy this file, then paste it into the
InXMLfolder. Notice that as soon as you do this:
the Studio console displays numerous messages (it's processing your file!)
a new file appears in the
OutXMLfolder
the new file name includes the date-and-time stamp pattern we specified in the outbound endpoint configuration
Double-click to open the new file in the
OutXMLfolder. The file contains suggested spelling corrections for the misspelled words the
Google API found in the inbound XML file.
The Spell Checker application continues to run, polling the
InXMLfolder, processing the
spellcheck.xmlfile every three seconds, and creating
a new file in the
OutXMLfolder, until you remove the file from the
InXMLfolder or stop the application.
What you submit:
What you receive:
Stopping the Application
To stop the application, click the red, square Terminate icon above the console panel.相关文章推荐
- 一步步了解ESB (二) Mule ESB-Basic Studio Tutorial
- Mule ESB-Basic Studio Tutorial
- Mule ESB-Basic Studio Tutorial
- Mule ESB-Basic Studio Tutorial
- Servlet JSP Tutorial -- 1.4 Java Servlet Filter Example Tutorial
- 解题报告:Spell checker 模拟/string
- Struts2 Hibernate Integration Example Tutorial
- tensorflow 学习笔记(3)-basic_example
- poj_1035 Spell checker(字符串处理)
- Basic Spring Step by Step Hello World Example
- Java Program to print Prime numbers in Java - Example Tutorial and Code
- [ solr扩展 ] Solr Spellchecker internals (now with tests!)
- 【学习笔记】OGRE Basic Tutorial 2
- Spell checker(poj 1035)
- JSP Custom tags with example – JSP Tutorial
- POJ1035-Spell checker(java版)
- POJ 1035 Spell checker (模拟)
- spellchecker inspection helps locate typeos and misspelling in your code, comments and literals, and fix them in one click
- MyBatis DAO Example Code Tutorial
- 字符串 模拟 Spell checker (poj 1035)