<implementation.web>
This module is under development. What is described here reflects unreleased trunk code and is subject to change. Your input and comments are welcome
The Tuscany Java SCA runtime supports components implemented as JEE web modules by using the <implementation.web> SCDL extension. Implementation.web is one of the SCA extensions being formalized in the OASIS Open Composite Services Architecture with a published specification document.
The web component implementation SCDL has the following format:
<implementation.web web-uri="<module name>" />
Implementation.web can be used by components such as Servlets, JSPs, and Web 2.0 style html pages. How it works depends on the way the Tuscany runtime is being used.
Using implementation.web with Servlets, Filters, and Event listeners
<component name="WebClient"> <implementation.web web-uri=""/> <reference name="service" target="HelloworldService"/> </component>
When using a JEE container with SCA integration (currently only a prototype for Tomcat, see below) Servlets, Filters, and Event listeners can use annotations to have acquire references to the services wired to the component as shown in the following Servlet code snippet:
public class HelloworldServlet extends HttpServlet { @Reference protected HelloworldService service; . . . }
When the container does not have SCA integration then injection via annotations does not work, to work around this the services need to be got from the ComponentContext which may be obtained from the application context. This is shown in the following code snippet:
public class HelloworldServlet extends HttpServlet { public void init(ServletConfig config) { ComponentContext context = (ComponentContext)config.getServletContext().getAttribute("org.osoa.sca.ComponentContext"); HelloworldService service = context .getService(HelloworldService.class, "service"); . . . } . . . }
Using implementation.web with JSPs
<component name="WebClient"> <implementation.web web-uri=""/> <reference name="service" target="HelloworldService"/> </component>
In the .jsp file:
<%@ taglib uri="http://www.osoa.org/sca/sca_jsp.tld" prefix="sca" %> <sca:reference name="service" type="sample.HelloworldService" /> <html> <body > <%= service.sayHello("world") %> </body> </html>
Using implementation.web with Web 2.0 style browser clients
<component name="WebClient"> <implementation.web web-uri=""/> <reference name="service" target="HelloworldService"> <tuscany:binding.jsonrpc /> </reference> </component>
In the html page:
<html> <head> <script type="text/javascript" src="org.osoa.sca.componentContext.js"></script> <script language="JavaScript"> function callSayHello() { componentContext.getService("service").sayHello( document.getElementById('name').value, function(reply) { document.getElementById('result').innerHTML=reply; }); } </script> </head> <body > . . . <input type="text" id="name" width="10"> <button name="submit" onclick="callSayHello()">Say hello</button> <div id='result'></div> . . . </body> </html>
Using implementation.web with the Tuscany runtime embedded within a webapp
This is the style all the current Tuscany webapp samples use. When using implementation.web with the Tuscany runtime embedded within a webapp the implementation.web web-uri attribute is ignored.
Using implementation.web with the Tuscany runtime integrated into a JEE server such as Tomcat or Geronimo
The only code that is currently working is some prototype code in the Tuscany runtime-tomcat module that supports injecting references into Servlets, Filters and Event listeners using the @Reference annotation.
Using implementation.web with the Tuscany standalone runtime
Nothing implemented yet
Using implementation.web with the Tuscany distributed domain runtime
Nothing implemented yet