首页 > 开发 > JSP > 正文

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

2020-02-05 13:59:33
字体:
来源:转载
供稿:网友
注册会员,创建你的web开发资料库,

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>expression</th><th>result</th>
    
</tr>
    
<tr>
        
<td>2 + 3</td><td><%= calc.add(23%></td>
    
</tr>
    
<tr>
        
<td>3 - 2</td><td><%= calc.subtract(32%></td>
    
</tr>
</table>
</body>
</html>

 

<end>


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表