gembin

OSGi, Eclipse Equinox, ECF, Virgo, Gemini, Apache Felix, Karaf, Aires, Camel, Eclipse RCP

HBase, Hadoop, ZooKeeper, Cassandra

Flex4, AS3, Swiz framework, GraniteDS, BlazeDS etc.

There is nothing that software can't fix. Unfortunately, there is also nothing that software can't completely fuck up. That gap is called talent.

About Me

 

基于Tuscany的Web应用程序分析

Tuscany下典型的Web架构:

乍一看,平淡无奇,这不就是我们常用的Web目录结构么?没错!

但玄机出在Web.xml和Calculator.composite上,下面我们分别看下这两个文件:

Web.xml

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web
Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd">
<web-app>

<display-name>Apache Tuscany Calculator Web Service Sample</display-name>

<filter>
<filter-name>tuscany</filter-name>
<filter-class>org.apache.tuscany.sca.host.webapp.TuscanyServletFilter</filter-class>
</filter>

<filter-mapping>
<filter-name>tuscany</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>

<welcome-file-list id="WelcomeFileList">
<welcome-file>calc.jsp</welcome-file>
</welcome-file-list>

</web-app>

这里使用了TuscanyServletFilter过滤器,此过滤器的作用我们会在后文提到。

Calculator.composite

<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://sample"
xmlns:sample="http://sample"
name="Calculator">

<component name="CalculatorServiceComponent">
<implementation.java class="calculator.CalculatorServiceImpl"/>
<reference name="addService" target="AddServiceComponent"></reference>
<reference name="subtractService" target="SubtractServiceComponent"></reference>
<reference name="multiplyService" target="MultiplyServiceComponent"></reference>
<reference name="divideService" target="DivideServiceComponent"></reference>
</component>

<component name="AddServiceComponent">
<implementation.java class="calculator.AddServiceImpl"/>
</component>

<component name="SubtractServiceComponent">
<implementation.java class="calculator.SubtractServiceImpl"/>
</component>

<component name="MultiplyServiceComponent">
<implementation.java class="calculator.MultiplyServiceImpl"/>
</component>

<component name="DivideServiceComponent">
<implementation.java class="calculator.DivideServiceImpl"/>
</component>

</composite>
此文件类似Spring,是Tuscany的服务配置文件,在此文件中提供了组件、实现的声明及配置。

下面,再结合调用时序图,来详述Tuscany在此应用中的位置及作用。

由此时序图可知,整个流程如下:

1、应用服务器启动;

2、客户端访问calc.jsp页面,服务器调用Web.xml中的配置TuscanyServletFilter过滤器;

3、在TuscanyServletFilter过滤器中,首先得到一个WebAppServletHost实例,WebAppServletHost是在Web应用环境中使用的Tuscany功能提供者;

4、在WebAppServletHost中,得到一个SCADomain实例,并将之放入ServletContext上下文中,以后可藉由相应的key得到此SCADomain实例;

5、calc.jsp中成功取得SCADomain实例;

6、通过SCADomain实例取得CalculatorServiceComponent组件;

7、调用CalculatorServiceComponent组件的各种业务方法实施计算。

这一个完整的过程,演示了Tuscany在一个Web应用中所充当的角色,在某种意义上Tuscany和Spring是相同的,只不过粒度不一样,

Spring注重的是bean的管理,是技术层面的,粒度相对较细;而Tuscany关注 则是业务组件的管理,是业务层面的,粒度相对较粗。

从软件重用角度讲,业务重用比技术重用更加受欢迎,操作起来也更加容易。业务重用是趋势。现在的SAAS热潮更加证明,软件即服务的

时代已经到来。

posted on 2008-04-27 21:35 gembin 阅读(626) 评论(0)  编辑  收藏 所属分类: SCASOA


只有注册用户登录后才能发表评论。


网站导航:
 

导航

统计

常用链接

留言簿(6)

随笔分类(440)

随笔档案(378)

文章档案(6)

新闻档案(1)

相册

收藏夹(9)

Adobe

Android

AS3

Blog-Links

Build

Design Pattern

Eclipse

Favorite Links

Flickr

Game Dev

HBase

Identity Management

IT resources

JEE

Language

OpenID

OSGi

SOA

Version Control

最新随笔

搜索

积分与排名

最新评论

阅读排行榜

评论排行榜

free counters