SCA Java Web Applications (TUSCANY) edited by ant
Page:
http://cwiki.apache.org/confluence/display/TUSCANY/SCA+Java+Web+Applications
Changes:
http://cwiki.apache.org/confluence/pages/diffpagesbyversion.action?pageId=106453&originalVersion=4&revisedVersion=5
Content:
---------------------------------------------------------------------
{section:border=false}
{column:width=15%}
{include: SCA Java Subproject Menu}
{include: Java SCA Menu New}
{column}
{column:width=85%}
h3. 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 you build applications combining both JEE
features and SCA features. When running Tuscany in a Web applications 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:
# Configuring the web application
# Configuring the Tuscany SCA domain
# Accessing the SCA services within the SCA domain
h3. 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 neededed 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 SCA configurations.
The following show the XML snippets show the necessary definitions for the
web.xml file:
{code}
<listener>
<listener-class>org.apache.tuscany.sca.host.webapp.TuscanyContextListener</listener-class>
</listener>
{code}
{code}
<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>
{code}
h3. 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:
# by including a META-INF/sca-contributions.xml
# by including deployable composite files within a folder named
META-INF/sca-deployables
# by using what is known as an "application composite" which is a single
composite file named WEB-INF/web.composite
h3. 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:
{code}<%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca"
%>{code}
and then you can define references to services with the sca:reference tag, eg:
{code}<sca:reference name="CalculatorServiceComponent"
type="calculator.CalculatorService" />{code}
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:
{code}
<%
SCADomain scaDomain = (SCADomain)
application.getAttribute("org.apache.tuscany.sca.SCADomain");
CalculatorService calculatorService =
(CalculatorService)scaDomain.getService(CalculatorService.class,
"CalculatorServiceComponent");
%>
{code}
h3. Samples showing Tuscany in JEE Web Applications
Tuscany comes with several samples using JEE Web Applications. The simplest is
the [calculator-webapp |
https://svn.apache.org/repos/asf/tuscany/tags/java/sca/1.3.2/samples/calculator-webapp/]
which shows a JSP invoking an SCA component. Another is the
[calculator-ws-webapp |
https://svn.apache.org/repos/asf/tuscany/tags/java/sca/1.3.2/samples/calculator-ws-webapp/]
which extends the calculator-webapp sample to use SCA Web Services, another is
the
[alert-aggregator|https://svn.apache.org/repos/asf/tuscany/tags/java/sca/1.3.2/demos/alert-aggregator-webapp/]
demo which shows a more complete application.
{column}
{section}
---------------------------------------------------------------------
CONFLUENCE INFORMATION
This message is automatically generated by Confluence
Unsubscribe or edit your notifications preferences
http://cwiki.apache.org/confluence/users/viewnotifications.action
If you think it was sent incorrectly contact one of the administrators
http://cwiki.apache.org/confluence/administrators.action
If you want more information on Confluence, or have a bug to report see
http://www.atlassian.com/software/confluence