您的位置:首页 > 其它

Mule Example SpellChecker - Basic Studio Tutorial

2013-07-04 16:06 579 查看


Basic Studio Tutorial

Contents

This 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: Creating
a New Project.

Navigate to the directory on your local drive in which you installed Studio.
Double-click the executable file to launch Studio.

MuleStudio.exe
in Windows
MuleStudio.app
in Mac OS
MuleStudio
in 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.mflow
appears under the
flows
folder and
mule-project.xml
appears under
the
src
folder. The
.mflow
file stores flow information for the visual editor.




Setting Up Folders

The Spell Checker application requires the creation of two new folders:

an
InXML
folder to accept end user spell check requests
an
OutXML
folder to return the spell check suggestions to the end user.

The Spell Checker application polls the
InXML
folder 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
OutXML
folder
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
>
SpellChecker
folder.
In the
SpellChecker
folder, 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, you
can 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 this
building 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
InXML
folder 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
1000
to
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
OutXML
folder 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].xml
This instructs Mule to combine a date stamp and
a time stamp when creating a file name for the output data it writes to the
OutXML
directory.
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.mflow
file, 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
InXML
folder 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.xml
file in that folder contains some purposefully misspelled text: "
Creeating mi fiirst Mulle Studio aplication!
"
Copy this file, then paste it into the
InXML
folder. 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
OutXML
folder
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
OutXML
folder. 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
InXML
folder, processing the
spellcheck.xml
file every three seconds, and creating
a new file in the
OutXML
folder, until you remove the file from the
InXML
folder 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.

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: