Why Do Cool Kids Chose PHP to Build Websites?

PHP Developer's Journal

Subscribe to PHP Developer's Journal: eMailAlertsEmail Alerts newslettersWeekly Newsletters
Get PHP Developer's Journal: homepageHomepage mobileMobile rssRSS facebookFacebook twitterTwitter linkedinLinkedIn

PHP Authors: Hovhannes Avoyan, AppDynamics Blog, Trevor Parsons, Andreas Grabner, Harald Zeitlhofer

Related Topics: Apache Web Server Journal, SOA & WOA Magazine, Java Developer Magazine, PHP Developer's Journal

Apache Web Server: Article

Java Feature — What Is SCA?

A simple model for creating service-oriented applications

Remote Services
A remote service could be running in a different process on the same physical computer or on a different computer. In the loan approval example we'll now show how it can interact with remote services. We'll first expose CreditCheck as a service in its own right and then we will replace it with an externally provided CreditCheck Web service.

Exposing Components as Remote Services
Let's expand our scenario. Suppose the MostMortgage Company has a business partner who is interested in using the CreditCheck functionality. In response to that, the CreditCheck component can be made into a Web Service that can be accessed by the LoanApproval component or by the business partner. With SCA, this is surprisingly easy and involves simply splitting off the CreditCheck component into a new composite, adding a service element to this new composite file and then wiring the service element to the CreditCheck component that provides the implementation of the service (see Figure 6).

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
xmlns:wsdli="http://www.w3.org/2006/01/wsdl-instance" name="CreditComposite">

    <service name="CreditCheckWebService">
       <interface.wsdl interface="http://credit#wsdl.interface(CreditCheck)"
wsdl:wsdlLocation="http://credit wsdl/credit.wsdl" />
       <binding.ws endpoint="http://credit#wsdl.endpoint(CreditCheck
location="wsdl/credit.wsdl" />

    <component name="CreditCheckServiceComponent">
       <implementation.java class="credit.CreditCheckImpl"/>


Note that the new service element references a WSDL file to both describe the service interface and describe the binding.

Replacing Local Components with Remote Services
In the previous section we made CreditCheck a remote component. Now we show how MortgageComposite can be changed to reference this remote Web Service. All we have to do is change the SCDL file for the MortgageComposite. We add a reference element named CreditCheckReference to declare the remote CreditCheck Web Service and we rewire the creditCheck reference on the LoanApprovalComponent to this new reference.

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="MortgageComposite">

    <component name="LoanApprovalComponent">
       <reference name="creditCheck">CreditCheckReference</reference>

    <reference name="CreditCheckReference">
       <interface.java interface="mortgage.CreditCheck" />
       <binding.ws endpoint="http://credit#wsdl.endpoint(CreditCheckService/CreditCheckSoapPort)"
location="wsdl/credit.wsdl" />



Note that the reference in SCDL specifies a binding called "binding.ws". The binding information indicates the protocol used to send messages across the wire. The system integrator here has the flexibility to configure any binding that's appropriate to enable secure communication between MortgageComposite and CreditComposite. Our system diagram is now updated as shown in Figure 7.

The CreditCheck Web Service isn't required to be implemented as an SCA component. Suppose that there's an existing CreditCheck Web Service offered by a third party. We can take the same approach to call this Web Service. The only difference is that the WSDL would contain the URL of the hosted Web Service. In the next diagram, the CreditCheck Web Service is provided as an Axis2 service and is deployed in an Apache Tomcat server (see Figure 8).

<composite xmlns="http://www.osoa.org/xmlns/sca/1.0" name="MortgageComposite">

    <component name="LoanApprovalComponent">
       <reference name="creditCheck">CreditCheckReference1</reference>
    <reference name="CreditCheckReference1">
       <interface.java interface="mortgage.CreditCheck" />
       <binding.ws endpoint="http://credit#wsdl.endpoint(CreditCheckService/CreditCheckSoapPort1)"
location="wsdl/credit.wsdl" />

Multi-Language Extensions
So far we've talked about Java language components and local and remote services but we've talked very little about the alternatives. You may have realized by now that all SCA does, through its SCDL, is describe components and the way that they can be assembled. It doesn't mandate how those components will be implemented or indeed how messages will be passed along the wires that join one component to another. Runtime implementations are free to add new implementation extensions. The Apache Tuscany project has provided extension APIs to make providing new implementation-type support as easy as possible. The Apache Tuscany Java technology SCA runtime implementation currently supports the following implementation types: implementation.java, implementation.javascript, and implementation.ruby. Using the extension mechanism the Tuscany community is currently working on Spring and BPEL implementation types.

The Apache Tuscany C++ SCA runtime implementation currently supports the following implementation types: implementation.cpp, implementation.python, and implementation.ruby.

Currently the PHP SCA runtime implementation only supports SCA components implemented in PHP.

You may have noticed in Figure 8 that we've changed the MortgageCalculator component from Java to use the JavaScript container from the Apache Tuscany Java SCA runtime.

The JavaScript implementation of MortgageCalculator.getMonthlyPayment() is as follows:

function getMonthlyPayment(principal, years, interestRate) {
    var monthlyRate = interestRate / 12.0 / 100.0;
    var p = Math.pow(1 + monthlyRate, years * 12);
    var q = p / (p - 1);
    var monthlyPayment = principal * monthlyRate * q;
    return monthlyPayment;

The component-type file (no changes required):

<componentType xmlns="http://www.osoa.org/xmlns/sca/1.0"

    <service name="MortgageCalculatorService">
       <interface.java interface="mortgage.MortgageCalculator"/>


We can now change the Mortgage composite to reference the Javascript MortgageCalculator component as follows:

<component name="MortgageCalculatorJSComponent"
    <js:implementation.js script="MortgageCalculator.js" />

Bindings and Extensibility
The protocols used to transfer messages from one component to another are also extensible. As an example, the Apache Tuscany runtime provides explicit extension APIs to aid the building of new bindings. The Apache Tuscany Java SCA runtime implemen-tation currently supports the following bindings: binding.ws, binding.celtix, binding.jsonrpc, and binding.rmi.

As you have seen, SCA defines an assembly model that can leverage existing technologies. We used the Java and JavaScript languages and communicated with external Web Services. This means SCA can be introduced incrementally into an organization without having to rewrite or replace existing applications. The evolving list of implementation types and bindings available in Apache Tuscany is representative of commonly used technologies and is constantly growing. The implementation and binding extension APIs can be used to build specific extensions where support isn't provided by default.

Quality of Service and Policy
SCA cleanly separates component implementation from the mechanisms that components use to exchange messages. This separation also allows the policies for message transmission to be stated independently of component implementation. So if you require messages transmitted, for example, reliably, within a transaction context or in encrypted form then the addition of statements of policy to the SCDL files will support this. The specifications for these policy statements aren't complete yet but you can see draft versions up on the OSOA site (www.osoa.org/display/Main/Service+Component+Architecture+Specifications).

Accessing SCA Services from Non-SCA Clients
In our MostMortgage example we've already shown that our SCA-based system can expose a service interface for others to call and can call service interfaces provided by others.

In the latter case SCA can call any service that's reachable using a protocol that the SCA runtime supports. We've shown how the CreditCheck Web Service can be provided by some third party and it need not be implemented using SCA. In our example we relied on accessing the WSDL description of the service and used a Web Service (SOAP/HTTP) binding to talk to it.

We haven't demonstrated yet how a non-SCA client can talk to SCA services. In our example we used SCA to expose the CreditCheckComponent for others to call via Web Services. Any Web Service-capable client could then call our service regardless of the technology used to implement the client. SCA does however provide APIs for non-SCA clients to invoke an SCA service locally.

public class MortgageClient {
    public static void main(String[] args) throws Exception {

       // Locate the service using SCA APIs
       CompositeContext context = CurrentCompositeContext.getContext();
       LoanApproval loanApplication = context.locateService(LoanApproval.class,
       // Invoke the service
       boolean result = loanApplication.approve(customer, 200000d, 30);

Note that the SCA API class CurrentCompositeContext allows a service to be located by name. This is the component name as it appears in the composite file. The result of this location step is a service instance or proxy that implements the service interface. When a method is invoked by the client code (approve() in this case), the SCA runtime will dispatch the operation parameters to the correct method in the component implementation according to the definitions in the SCDL file.

This article has focused on how the Service Component Architecture allows components to be described and assembled into working compositions. There's also a sister technology, Service Data Objects (SDO), that describes a common API for accessing data. This is important to SCA because it allows the Apache Tuscany and PHP SCA runtimes to provide a common API for accessing the messages that arrive at, or are sent from, components. SCA and SDO work well together but can, of course, be used independently. More information and specifications for SDO can be found on the OSOA site (www.osoa.org/display/Main/Service+Data+Objects+Home).

The PHP SDO PECL extension provides an implementation of SDO for PHP. The Apache Tuscany project provides implementations of SDO for the Java language and C++. Both projects provide an implementation of a Data Access Service (DAS) that integrates the SDO data model with data storage systems such as relational databases.

SCA provides a concise and flexible model for describing and developing SOA applications and addresses the strategic requirements demanded by agile IT environments. The SCA programming model focuses on describing components and the way that they're assembled together. It's inclusive of existing technologies with a primary goal of operating well as an addition to existing heterogeneous environments. This article aimed to provide a broad perspective of Service Component Architecture to intrigue the user to explore the technology further at (www.osoa.org) and experiment with the technology through three available free open source implementations, the Apache Tuscany (http://incubator.apache.org/tuscany/), SCA runtimes for the Java language and C++, and the SCA for PHP (www.osoa.org/display/PHP/SOA+PHP+Homepage) runtime.


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 (1) View Comments

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.

Most Recent Comments
Stephan 01/23/07 05:11:58 PM EST

For people interested... you can find an SCA presentation (audio + sync'ed slides) by Michael Rowley (BEA) on Parleys.com ! Enjoy.