Example of Using JSP to call the SCA service component deployed in Tomcat 5.5 as a web application

Source: Internet
Author: User
Tags sca

Composite is the basic unit of deployment. In the Assembly file, the composite element is the root element.

Composite elements can contain composite, service, component, reference and other elements. component is a very important element.

The component element can contain 0... N services, reference, property, and 0... 1 implementation.

The implementation methods in component can be Java, BPEL, composite, and so on.

In this example, we use the composite method to implement the implementation of the component included in composite.

In the Assembly file of SCA service components based on Web applications, composite implements component.

The file name is 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>

In the WEB-INF of the released web application directory, there is a lib directory, which stores the environment required to run the SCA application, it also includes a jar package sample-calculator-1.0-incubator-M2.jar consisting of the code and assembly files required by the current web application. The content of this jar package is the jar package used in the previous example (simple example of running Tuscany SCA in standalone application mode) and loaded to the runtime environment through the default. scdl application Assembly file.

Unlike the Independently Running SCA service components, the establishment and assembly of the Web application service component environment are completed through the servlet components listener and filter in Web. xml.

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>

 

After the Web Service is started, you can access the SCA service components through JSP.

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>

<Body>
<Table>
<Tr>
<TH> Expression </Th> <TH> result </Th>
</Tr>
<Tr>
<TD> 2 + 3 </TD> <% = Calc. Add (2, 3) %> </TD>
</Tr>
<Tr>
<TD> 3-2 </TD> <% = Calc. Subtract (3, 2) %> </TD>
</Tr>
</Table>
</Body>
</Html>

 

<End>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.