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>