Open Services Gateway initiative


OSGi Authors: XebiaLabs Blog, RealWire News Distribution, Si Chen, Tad Anderson, Elizabeth White

Related Topics: Apache Web Server Journal, OSGi, SOA & WOA Magazine

Apache Web Server: Article

Building SOA with Tuscany SCA

A simple service-oriented infrastructure

Based solely on this information Tuscany SCA makes three things available automatically;

•  The Catalog JSONRPC service
•  The JSONRPC service description (SMD)
•  A generated JavaScript JSONRPC proxy for accessing this service

A browser-based application can access this service directly using either the generated JSONRPC proxy or whatever JSONRPC client the application developer is familiar with, for example, the store sample uses the following JavaScript to access the Catalog service:

catalog = (new JSONRpcClient("../Catalog")).Catalog;

Clearly this pattern can be extended to any service your Web 2.0 style application is required to communicate with. The full range of SCA features is then available to these services. For example, our Catalog service could easily be exposed as a Web service ( by extending the SCA configuration description of the service.

<service name="Catalog">

Note that no changes to the Catalog component code are required. The Tuscany SCA runtime is doing all the hard work.

SCA has provided services to the Web 2.0 application with very little effort on behalf of the developer. What effort is expended is not particular to supporting Web 2.0 applications as the services are now part of the wider enterprise service orientation approach.

Tuscany SCA supports other modes of operation that will be of interest to Web 2.0 application developers. For example, the Tuscany Java SCA Chat sample [9] uses binding.dwr to implement a Direct Web Remoting [10] connection between a JavaScript browser-based application and an SCA service. Using this binding, service-to-browser communication is supported alongside browser to service communication (see Figure 3).

Data Integration
In a typical enterprise, business data comes from many different sources and is presented in many different formats. Tuscany SCA provides a databinding framework that seamlessly handles data format mapping and therefore frees the developers from such concerns.

Let's look at a simple scenario that deals with aggregation of XML data from different sources. This demo will be available in a future release of Tuscany. The business function here calculates the total value of all the accounts (checking, savings and stock) that a customer owns (see Figure 4).

In this scenario, data is received from various data sources and manipulated as XML. The following data exchanges are occurring.

  1. Use an RSS feed to retrieve currency exchange rates from the Web.
  2. Load the account data for a customer from an XML file or database.
  3. Invoke a live Web service to get quotes for a list of symbols.
  4. Calculate the total value by joining the XML data from 2 and 3.

The handling of different data formats in the enterprise can be complex. For example, business data may be represented in many different ways, even if they are for the same infoset. A Customer business object can be defined as JavaBean, SDO, JAXB, XMLBeans, or DOM. At the same time, protocol implementation stacks require different data representations. For example, in the Web service domain, Axis1 uses DOM, Axis2 uses AXIOM, and JAX-WS uses JAXB. Implementation technologies may also impose requirements on the data as well; for example, the Apache ODE BPEL engine consumes/produces data using DOM and the SAXON XQuery engine consumes/produces data using NodeInfo.

Application developers should have the freedom to choose their preferred data representation without being restricted by the above concerns and worrying about the mappings. Tuscany SCA automatically handles this for them. Tuscany provides the most popular databindings including SDO, JAXB, XMLBeans, AXIOM, JSON, DOM, SAX, and StAX. There are more than 50 transformers to convert data between the databindings. With the transformer graph, Tuscany SCA supports point-to-point transformations as well as multiple-hop transformations. This approach greatly reduces the number of transformers required and makes it possible to transform data without direct transformation logic.

In the sample, the exchange rate is retrieved (step 1) using the feed binding (binding.rss) as follows.

<reference name="exchangeRate">
uri=",CNY,EUR&T=F&S=O&I=S" />

Step 3 uses the Web service binding ( to retrieve stock from the Internet.

<reference name="StockQuoteReference" promote="AccountService/stockQuote">
    < wsdlElement="" />

The Java interface is interesting. The example uses StAX to streamline XML data exchange over Web services. The Tuscany SCA databinding framework allows component developers to choose their preferred XML Java databinding technology such as JAXB, SDO, DOM, or StAX no matter how the SOAP message is represented in the Web services stack (AXIOM is used by Axis2).

public interface StockQuote {
    public XMLStreamReader GetStockQuotes(XMLStreamReader input);

The various XML data are joined together using XQuery (implementation.xquery) in step 4. With the help of the databinding framework, XQuery mediates data from many services. The capability of XQuery can be extended by invoking other SCA components.

public interface StockValue {
    double calculate(XMLStreamReader quotes, XMLStreamReader accounts);

More Stories By Haleh Mahbod

Haleh Mahbod is a program director with IBM, managing the team contributing to the Apache Tuscany as well as SOA for PHP open source. She has extensive development experience with database technologies and integration servers.

More Stories By Raymond Feng

Raymond Feng is a senior software engineer with IBM. He is now working on the Service Component Architecture (SCA) runtime implementation in Apache Tuscany project as a committer. Raymond has been developing SOA for more than 4 years and he was a key developer and team lead for WebSphere Process Server products since 2002.

More Stories By Simon Laws

Simon Laws is a member of the IBM Open Source SOA project team working with the open source Apache and PHP communities to build Java, C++, and PHP implementations of the Service Component Architecture (SCA) and Service Data Object (SDO) specifications. Prior to this role he was working in the distributed computing space building service-oriented solutions for customers with a particular interest in grid computing and virtualization.

Comments (2)

Share your thoughts on this story.

Add your comment
You must be signed in to add a comment. Sign-in | Register

In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.