2016/05/28 - Apache Tuscany has been retired.

For more information, please explore the Attic.

 
 Apache Tuscany > Home > SCA Overview > SCA Java > Java SCA Documentation Menu > SCA Java Web Applications User List | Dev List | Issue Tracker  
Resources

Using Tuscany in JEE Web Applications

This page describes how to use Tuscany in JEE Web Applications.

You can use a JEE Web application as a container for running Tuscany SCA applications, and this enables building applications which combine both JEE features and SCA features. When running Tuscany in a Web application there is a single SCA domain contained entirely within the web application (see note at bottom of page).

When using Tuscany in Web applications there are three aspects to consider:

  1. Configuring the Web application
  2. Configuring the Tuscany SCA domain
  3. Accessing the SCA services within the SCA domain

Configuring the web application

All the Tuscany jar's and dependencies must be included in the WEB-INF/lib folder. Some configuration in the web.xml file is required - a ContextListener is needed when using non-HTTP based SCA services so that the Tuscany runtime is started when the Web Application starts, a Servlet Filter is required when using HTTP based SCA services. The simplest approach is to always include both ContextListener and Filter definitions in the web.xml so that everything works for all types of SCA configuration.

The following show the XML snippets show the necessary definitions for the web.xml file:

<listener>
   <listener-class>org.apache.tuscany.sca.host.webapp.TuscanyContextListener</listener-class>
</listener>
<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>

Configuring the Tuscany SCA domain

Tuscany treats the entire Web application as a single contribution and the deployable composites within the contribution can be configured in three ways:

  1. by including a META-INF/sca-contributions.xml
  2. by including deployable composite files within a folder named META-INF/sca-deployables
  3. by using what is known as an "application composite" which is a single composite file named WEB-INF/web.composite

Accessing the SCA services within the SCA domain

For JSPs you can use an SCA taglib or access the SCADomain directly. To use the taglib, declare it with:

<%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %>

and then you can define references to services with the sca:reference tag, eg:

<sca:reference name="CalculatorServiceComponent" type="calculator.CalculatorService" />

That treats the domain as one big "virtual" component with every service in the domain being available as a reference in the JSP

The Tuscany SCADomain object is stored in the Web applications ServletContext object so application code can get hold of that and use the SCADomain just like when running Tuscany applications in a standalone JSE environment. For example, a JSP can do the follow:

<%
   SCADomain scaDomain = (SCADomain) application.getAttribute("org.apache.tuscany.sca.SCADomain");
   CalculatorService calculatorService = (CalculatorService)scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent");
%>

Samples showing Tuscany in JEE Web Applications

Tuscany comes with several samples using JEE Web Applications. The simplest is the calculator-webapp which shows a JSP invoking an SCA component. Another is the calculator-ws-webapp which extends the calculator-webapp sample to use SCA Web Services, another is the alert-aggregator demo which shows a more complete application.

The OASIS SCA JEE specification
What is described on this page is Tuscany support that has been implemented ahead of on going work in the OASIS JEE specification.
The OASIS JEE specification has now made more progress and Tuscany will be updating the Web application support in line with the specification.
See the SCA-J JEE Subcommittee page and the Tuscany dev list for more information.
The Tuscany-Geronimo integration plugin
As one of the steps to supporting the OASIS JEE specification there is ongoing work integrating Tuscany into the Apache Geronimo JEE application server. More information about that is available on the plugin page.
website stats