Mule Example SpellChecker - Basic Studio Tutorial

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.

  1. Navigate to the directory on your local drive in which you installed Studio.
  2. Double-click the executable file to launch Studio.
    • MuleStudio.exe in Windows
    • MuleStudio.app in Mac OS
    • MuleStudio in Linux
       
  3. When Studio presents the Workspace Launcher dialog, click OK to accept the default workspace. 

  4. 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

  1. From the Studio application menu, click File > New > Mule Project.
  2. Studio opens the New Mule Project wizard. Fill in the Name field with the value Spell Checker.
  3. 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. 



  4. Click Next to proceed.
  5. 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.
  6. In the Package ExplorerSpell Checker.mflow appears under the flows folder and mule-project.xml appears under the srcfolder. 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.

  1. Navigate to your folder on your local drive where you installed Mule Studio.
  2. Navigate to the Examples > SpellChecker folder.
  3. 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.

  1. Click and drag a File endpoint, which resides in the palette's Endpoints group, onto the canvas.
  2. 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. 

  3. 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

  1. 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.
  2. 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.
  3. 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.
  4. 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.
  5. Click OK to complete the File endpoint configuration. 

HTTP Endpoint

This endpoint retrieves information from a the Google Spell Checker API.

  1. Double-click the HTTP Enpoint to open the Properties dialog.
  2. 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
  3. 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

  1. Double-click the last File endpoint in your flow to open the Properties dialog.
  2. Optionally, enter a Display Name for the endpoint such as, Outgoing File.
  3. 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.
  4. 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.
  5. Click OK to complete the endpoint configuration. 

  6. 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.

  1. In the Package Explorer pane, right-click the SpellChecker.mflow file, then select Run As > Mule Application.
  2. 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.

  1. Navigate to the Spell Checker folder on your local drive. For example, Users/aaron/MuleStudio/examples/SpellChecker).
  2. The spellcheck.xml file in that folder contains some purposefully misspelled text: "Creeating mi fiirst Mulle Studio aplication!"
  3. 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
  4. 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.
  5. 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:
<?xml version= "1.0" encoding= "utf-8" ?>
<spellrequest textalreadyclipped= "0" ignoredups= "0" ignoredigits= "1" ignoreallcaps= "1" >
     <text>Creeating mi fiirst Mulle Studio aplication!</text>
</spellrequest>

 

What you receive:
<?xml version= "1.0" encoding= "UTF-8" ?><spellresult error= "0" clipped= "0" charschecked= "44" >
<c o= "0" l= "9" s= "0" >Creating   Crating Greeting    Cremating   Curating</c>
<c o= "13" l= "6" s= "0" >first foist   fist    fiesta  fest</c>
<c o= "20" l= "5" s= "0" >Muller    Mlle    Mule    Mull    Miller</c>
<c o= "33" l= "10" s= "0" >application  applications    allocation  placation   implication</c></spellresult>

 

Stopping the Application

To stop the application, click the red, square Terminate icon above the console panel. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
数据来源:中经数据库 主要指标110多个(全部都是纯粹的 市辖区 指标),大致是: GDP GDP增速 第一产业增加值占GDP比重 第二产业增加值占GDP比重 第三产业增加值占GDP比重 人均GDP 社会消费品零售总额 固定资产投资(不含农户) 新设外商投资企业数_外商直接投资 实际利用外资金额(美元) 一般公共预算收入 一般公共预算支出 一般公共预算支出_教育 一般公共预算支出_科学技术 金融机构人民币各项存款余额_个人储蓄存款 金融机构人民币各项存款余额 金融机构人民币各项贷款余额 规模以上工业企业单位数 规模以上工业企业单位数_内资企业 规模以上工业企业单位数_港澳台商投资企业 规模以上工业企业单位数_外商投资企业 规模以上工业总产值 规模以上工业总产值_内资企业 规模以上工业总产值_港澳台商投资企业 规模以上工业总产值_外商投资企业 规模以上工业企业流动资产合计 规模以上工业企业固定资产合计 规模以上工业企业利润总额 规模以上工业企业应交增值税 规模以上工业企业主营业务税金及附加 户籍人口数 年均户籍人口数 户籍人口自然增长率 第一产业就业人员占全部城镇单位就业人员比重 第二产业就业人员占全部城镇单位就业人员比重 第三产业就业人员占全部城镇单位就业人员比重 城镇非私营单位就业人员数 城镇非私营单位就业人员数_第一产业 城镇非私营单位就业人员数_第二产业 城镇非私营单位就业人员数_第三产业 城镇非私营单位就业人员数_农、林、牧、渔业 城镇非私营单位就业人员数_采矿业 城镇非私营单位就业人员数_制造业 城镇非私营单位就业人员数_电力、热力、燃气及水生产和供应业 城镇非私营单位就业人员数_建筑业 城镇非私营单位就业人员数_批发和零售业 城镇非私营单位就业人员数_交通运输、仓储和邮政业 城镇非私营单位就业人员数_住宿和餐饮业 城镇非私营单位就业人员数_信息传输、软件和信息技术服务业 城镇非私营单位就业人员数_金融业 城镇非私营单位就业人员数_房地产业 城镇非私营单位就业人员数_租赁和商务服务业 城镇非私营单位就业人员数_科学研究和技术服务业 城镇非私营单位就业人员数_水利、环境和公共设施管理业 城镇非私营单位就业人员数_居民服务、修理和其他服务业 城镇非私营单位就业人员数_教育 城镇非私营单位就业人员数_卫生和社会工作 城镇非私营单位就业人员数_文化、体育和娱乐业 城镇非私营单位就业人员数_公共管理、社会保障和社会组织 城镇非私营单位在岗职工平均人数 城镇就业人员数_私营企业和个体 城镇非私营单位在岗职工工资总额 城镇非私营单位在岗职工平均工资 城镇登记失业人员数 建成区面积 建设用地面积 建设用地面积_居住用地 液化石油气供气总量 液化石油气供气总量_居民家庭 人工煤气、天然气供气总量 人工煤气、天然气供气总量_居民家庭 液化石油气用气人口 人工煤气、天然气用气人口 城市公共汽电车运营车辆数 城市出租汽车运营车辆数 城市公共汽电车客运总量 道路面积 排水管道长度 建成区绿化覆盖面积 建成区绿化覆盖率 绿地面积 公园绿地面积 维护建设资金支出 土地面积 生活用水供水量 供水总量 全社会用电量 城乡居民生活用电量 工业生产用电量 房地产开发投资 房地产开发投资_住宅 限额以上批发和零售业法人单位数 限额以上批发和零售业商品销售总额 普通中学学校数 中等职业教育学校数 普通小学学校数 普通高等学校专任教师数 普通中学专任教师数 中等职业教育专任教师数 普通小学专任教师数 普通高等学校在校生数 普通中学在校生数 中等职业教育在校生数 普通小学在校生数 电视节目综合人口覆盖率 公共图书馆总藏量_图书 医疗卫生机构数_医院和卫生院 卫生人员数_执业(助理)医师 医疗卫生机构床位数_医院和卫生院 城镇职工基本养老保险参保人数 职工基本医疗保险参保人数 失业保险参保人数

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值