Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3
Section
borderfalse
Column
width15%
Include Page
Menus
Menus
Column
width85%

Web Application Integration story goals

  • Simplify the web application as a client application story
  • Use a simple approach, familiar to all web application developers

Integrating using ServletContextLister

This approach register a context listener on the application web.xml that will bootstrap the runtime when the web-app is started, and closes the runtime when the web-app is shutdown.

Necessary updates in web.xml

Code Block
<listener>
 <listener-class>org.apache.tuscany.sca.webapp.TuscanyContextListener</listener-class>
</listener>

Then, once this integration part is defined, developers only need to get a reference to the SCADomain in their JSP and then get a reference to a service and start consuming it
Below, you can find the JSP code snippet to get a SCARuntime reference :

Code Block
SCADomain domain = (SCADomain) application.getAttribute("org.apache.tuscany.sca.SCADomain");

In order to use this approach, you will need to specify a sca-contribution.xml inside the META-INF directory of your web-app, this file will be used to identify the root of the contribution as well as the list of deployable composites.

Here is a sample sca-contribution.xml used in the calculator-web application:

Code Block
<?xml version="1.0" encoding="UTF-8"?>
<contribution xmlns="http://www.osoa.org/xmlns/sca/1.0">
   <deployable composite="Calculator"/>
</contribution>

Tuscany also supports the scenario where you would drop the SCA composite files inside the META-INF\sca-deployables directory, and this would also be used to identify the root of the contribution and the list of deployable composites.

pros: Consistent programming model between JSP and Servlets
cons: require web.xml integration and sca-contribution.xml, although the trend is to make web apps simpler and web.xml is optional in newer specs of J2EE

Integrating using pure JSP code

Integration using useBean tag: This approach would be very simple, and would basically ask the developer to add a useBean to instantiate the domain, and a setProperty to set the deployableComposite/

Code Block
<jsp:useBean id="SCADomain" class="org.apache.tuscany.host.embedded.SCADomainBean" scope="application">
 <jsp:setProperty property="deployableComposite" value="Calculator.composite" />
</jsp:useBean>
...
<%
 SCADomain domain = (SCADomain) application.getAttribute("SCADomain");
 CalculatorService calculatorService = domain.getService(CalculatorService.class, "CalculatorServiceComponent");
%>

Optional attributes can be defined by using the <jsp:setProperty> calls, if no attributes are specified, the sca-contribution.xml will be used to hint the root of the contribution as well as to find the deployable composites.

In this scenario, the SCADomain is stopped when the application goes out of scope and the garbage collection process the termination of the SCADomain.

pros: simple, does not involve changes on web.xml
cons: leaves toping the sca domain/runtime to when garbage collection process the application scope bean, also introduce different programming model between JSP and Servlets.

References

http://java.sun.com/j2ee/1.4/docs/tutorial/doc/
http://java.sun.com/products/jsp/docs.html#syntax
http://java.sun.com/products/jsp/tags/11/syntaxref11.fm14.html
http://java.sun.com/products/javabeans/docs/spec.html