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 User Guide > SCA Java implementation.web User List | Dev List | Issue Tracker  
Resources

<implementation.web>

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

JEE Servlets, Filters, and Event listeners may acquire references to the services wired to a component which use implementation.web as shown in the following code snippets.

<component name="WebClient">
   <implementation.web web-uri=""/>
   <reference name="service" target="HelloworldService"/>
</component>

Then when using a JEE container with SCA integration Servlets, Filters, and Event listeners can use annotations to acquire references to the services wired to the component as shown in the following Servlet code snippet (note the Servlet field name 'service' matches the reference name in the SCDL):

public class HelloworldServlet extends HttpServlet {

    @Reference
    protected HelloworldService service;

  . . .
}

When the container does not have SCA integration then injection via annotations does not work, so to work around this the services need to be manually 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");
       . . .
    }

  . . .
}

See the helloworld-servlet sample for the complete code of the above Servlet example.

Using implementation.web with JSPs

A JSP tag library is available to expose SCA components in JSP pages. To use SCA references within a JSP use a taglib to include the SCA tags and define the reference field with the reference tag.

<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>

See the helloworld-jsp sample for the complete code of the above JSP example.

Using implementation.web with Web 2.0 style browser clients

Web 2.0 style pages can invoke SCA services by making RPC calls from the remote browser client to the service-side SCA service. To do this the HTML page includes Javascript code to import the SCA ComponentContext and then gets service proxys from that ComponentContext. The org.osoa.sca.componentContext.js script is generated by Tuscany when a component uses implementation.web.

In the SCDL the reference needs to specify one of the Tuscany Web2.0 bindings such as binding.jsonrpc or binding.dwr.
(TODO: could this be avoided - something like make binding.jsonrpc the default sca binding for web2.0 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>

See the helloworld-web sample for the complete code of the above example.

The following on Web 2.0 callbacks is not yet fully implemented, describing here to encourage feedback

Tuscany Web 2.0 clients using implementation.web support SCA asynchronous callbacks using what is known as Comet or Reverse Ajax. The only Tuscany binding that currently supports this in binding.dwr.

The following shows the previous sample changed to use callbacks to receive the replies. A callback binding is added to the reference in the SCDL and the callback function is defined as a seperate Javascript function defined by the client and attached to the service proxy object.

<component name="WebClient">
    <implementation.web web-uri=""/>
    <reference name="service" target="HelloworldService">
        <tuscany:binding.dwr />
        <callback>
            <tuscany:binding.dwr />
        </callback>
    </reference>
</component>

In the html page:

<html>
  <head>

    <script type="text/javascript" src="org.osoa.sca.componentContext.js"></script>

    <script language="JavaScript">

       componentContext.getService("service").sayHelloCallback = 
          function(reply) {
             document.getElementById('result').innerHTML=reply;
          };
    
       function callSayHello() {
          componentContext.getService("service").sayHello(document.getElementById('name').value);
       }

    </script>

  </head>
  <body >

    . . . 

     <input type="text" id="name" width="10">

     <button name="submit" onclick="callSayHello()">Say hello</button>

     <div id='result'></div>

    . . . 

  </body>
</html>

See the helloworld-web-callback sample for the complete code of the above example.

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

website stats