用JSP调用以Web应用形式部署在Tomcat 5.5中的SCA服务组件的例子

Composite是部署的基本单元。在装配文件中,composite元素是根元素。

composite元素可以包含composite、service、component、reference等其他元素,component是非常重要的元素。

component元素可以包含0...n个Service,Reference,property 和0...1个implementation。

实现component中的implementation的方式可以有Java、BPEL、Composite等,如下图。

在这个例子中,就是使用Composite方式实现composite中包括的component的implementation。

在基于Web应用的SCA服务组件的装配文件中,是这样表示composite实现component的。

文件名为default.scdl

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

    
< component  name ="CalculatorServiceComponent" >
        
< implementation .composite name ="CalculatorComposite"  jarLocation ="lib/sample-calculator-1.0-incubator-M2.jar" />
    
</ component >
</ composite >


在发布的web应用目录的WEB-INF中,有一个lib目录,里面保存着运行SCA应用运行需要的环境,也包括包含着当前web应用需要的代码和装配文件组成的jar包 sample-calculator-1.0-incubator-M2.jar 。这个jar包的内容就是前面举例(Tuscany SCA以独立应用方式运行的简单例子 )使用的jar包,通过default.scdl应用装配文件加载到运行环境中。

与可独立运行的SCA服务组件不同的是,web应用服务组件环境的建立和装配过程是通过web.xml中servlet的组件listener和filter来完成的。

web.xml

<? xml version="1.0" encoding="UTF-8" ?>
< web-app  version ="2.4"
         xmlns
="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi
="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation
="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"   >

    
< display-name > Apache Tuscany Simple Webapp Sample </ display-name >

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

    
< filter >
        
< filter-name > TuscanyFilter </ filter-name >
        
< filter-class > org.apache.tuscany.runtime.webapp.TuscanyFilter </ filter-class >
    
</ filter >
    
< filter-mapping >
        
< filter-name > TuscanyFilter </ filter-name >
        
< url-pattern > /* </ url-pattern >
    
</ filter-mapping >

    
< listener >
        
< listener-class > org.apache.tuscany.runtime.webapp.TuscanyContextListener </ listener-class >
    
</ listener >
</ web-app >

 

web服务启动后,可以通过jsp访问SCA服务组件。

calc.jsp

<% @ page import = " calculator.CalculatorService "   %>
<% @ page import = " org.osoa.sca.CompositeContext "   %>
<% @ page import = " org.osoa.sca.CurrentCompositeContext "   %>
<% @ page contentType = " text/html;charset=UTF-8 "  language = " java "   %>
<%
    CompositeContext context 
=  CurrentCompositeContext.getContext();
    CalculatorService calc 
=  context.locateService(CalculatorService.class,  " CalculatorServiceComponent " );
%>
< html >
< head >< title > Calculator sample </ title ></ head >

< body >
< table >
    
< tr >
        
< th > Exdivssion </ th >< th > Result </ th >
    
</ tr >
    
< tr >
        
< td > 2 + 3 </ td >< td > <% =  calc.add( 2 3 %> </ td >
    
</ tr >
    
< tr >
        
< td > 3 - 2 </ td >< td > <% =  calc.subtract( 3 2 %> </ td >
    
</ tr >
</ table >
</ body >
</ html >

 

<END>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值