Channels ▼

Web Development

Integrating Composite Applications on the Cloud Using SCA

Building Composite Applications

Components are the most basic structures in SCA applications. At their simplest level, components may be classes exposed as an interface. A group of components can be combined to perform a more complex functionality; such structures are called "composites". A set of composites will be encapsulated into a domain which will provide the SCA runtime.

Our distributed application consists of domains hosted on separate machines (or infrastructures in this case), consisting of one or more composites which encompass its own set of components. A simple distributed application, which fulfills all the aforementioned requirements, will be created in this section. This application will consist primarily of two separate domains hosted on a hybrid infrastructure. Domain 1, consists of a set of components interacting with each other within a single composite. A set of functionalities will be exposed as services from this domain. Domain 2, will consist of a reference component will use the services exposed by Domain 1 to perform certain tasks. Domain 1 will be hosted on an instance running on the Cloud. Domain 2 will be on the enterprise infrastructure.

[Click image to view at full size]
Figure 2 The Service: Domain 1: HelloWorldService

Figure 2 illustrates the design layout of Domain 1. The composite helloworldws consists of three components -- ComponentOne, ComponentTwo, and HelloWorldServiceComponent. These components consists of a class (Compo1Impl or Compo2Impl) which implements the Compo1 and Compo2 interfaces, thereby exposing them as services. The methods present inside these classes (sayCompo1 and sayCompo2) take in a simple String object and returns a modified String.

public class Compo1Impl implements Compo1 {
    public String sayCompo1(String name){
        return "Hi "+name+". This message is from Component1.";

Class 1: Compo1Impl

public class Compo2Impl implements Compo2 {
    public String sayCompo2(String name){
        return "Hi "+name+". This message is from Component2.";

Class 2: Compo2Impl

The class HelloWorldImpl implements the interface HelloWorldService which exposes the methods getGreetings, getCompo1, and getCompo2 as services. The annotation @Service indicates that this is a service class. The interfaces Compo1 and Compo2 are used to create objects compo1 and compo2. The two methods setCompo1Service and setCompo2Service are mapped to the composite and hence will get the objects from the components Compo1Impl and Compo2Impl, the annotation (@Reference) indicates this. This will be detailed later in this article when the helloworldws.composite file is created.

public class HelloWorldImpl implements HelloWorldService {

        private Compo1 compo1;
        private Compo2 compo2;

    public void setCompo1Service(Compo1 compo1) {
        this.compo1 = compo1;
    public void setCompo2Service(Compo2 compo2) {
        this.compo2 = compo2;
    public String getGreetings(String name) {
        return "Hello " + name+". Now you are accessing an SCA Application hosted on a Eucalyptus Instance through a through a secure VPN.";
    public String getCompo2(String name){
        return compo2.sayCompo2(name);
    public String getCompo1(String name){
        return compo1.sayCompo1(name);

Class 1: HelloWorldImpl

<composite xmlns=""

    <component name="HelloWorldServiceComponent">
        < class="helloworld.HelloWorldImpl" />
            <reference name="compo1Service" target="ComponentOne" />
            <reference name="compo2Service" target="ComponentTwo" />
            <service name="HelloWorldService">
                <interface.wsdl interface="http://helloworld#wsdl.interface(HelloWorld)" />
                < uri="http://localhost:8085/HelloWorldService"/>
  <component name="ComponentOne">
    < class="helloworld.Compo1Impl"/>
  <component name="ComponentTwo">
    < class="helloworld.Compo2Impl"/>

Composite: helloworldws.composite

The reference annotations (@Reference) specified before the setter methods in the HelloWorldService class are being referenced here :

<reference name="compo1Service" target="ComponentOne" />

The component which services this request is named as the target here -- ComponentOne. This component implements a Java class helloworld.Compo1Impl.

[Click image to view at full size]
Figure 3 The Reference: Domain2: HelloWorldServiceComponent

Figure 3 shows the design layout of Domain 1. The composite helloworldwsclient consists of one component, HelloWorldServiceComponent.

The component HelloWorldServiceComponent implements HelloWorldService, which provides in interface for referencing the methods getGreetings, getCompo2, and getCompo1. The composite helloworldwsclient works in the backend getting the web services required from the Service provider Domain ( i.e Domain 1).

 * The HelloWorld service implementation
public class HelloWorldServiceComponent implements HelloWorldService {

    HelloWorldService helloWorldService;

    public String getGreetings(String name) {
        System.out.println("Called getGreetings");
        return helloWorldService.getGreetings(name);
        public String getCompo2(String name){
                return helloWorldService.getCompo2(name);
        public String getCompo1(String name){
                return helloWorldService.getCompo1(name);
    public HelloWorldService getHelloWorldService() {
        System.out.println("Got Injected helloWorldService");
        return helloWorldService;
    public void setHelloWorldService(HelloWorldService helloWorldService) {
        System.out.println("Injected helloWorldService");
        this.helloWorldService = helloWorldService;

<composite xmlns=""

    <!-- A component with a reference promoted as a composite reference connecting to an external webservice The wsdl interface for the reference is derived from the information specified by the 'wsdlElement'
    <component name="HelloWorldServiceComponent">
      < class="helloworld.HelloWorldServiceComponent"/>

    <reference name="HelloWorldService" promote="HelloWorldServiceComponent/helloWorldService">

        < interface="helloworld.HelloWorldService" />
        < wsdlElement="http://helloworld#wsdl.port(HelloWorldService/HelloWorldSoapPort)"/>

Composite: helloworldwsclient.composite

The component HelloWorldServiceComponent gets attributes from the reference HelloWorldService which derives its attributes from an external WebService (hosted in Domain1). Thus a web service binding will be established between Domain1 and Domain2.

Related Reading

More Insights

Currently we allow the following HTML tags in comments:

Single tags

These tags can be used alone and don't need an ending tag.

<br> Defines a single line break

<hr> Defines a horizontal line

Matching tags

These require an ending tag - e.g. <i>italic text</i>

<a> Defines an anchor

<b> Defines bold text

<big> Defines big text

<blockquote> Defines a long quotation

<caption> Defines a table caption

<cite> Defines a citation

<code> Defines computer code text

<em> Defines emphasized text

<fieldset> Defines a border around elements in a form

<h1> This is heading 1

<h2> This is heading 2

<h3> This is heading 3

<h4> This is heading 4

<h5> This is heading 5

<h6> This is heading 6

<i> Defines italic text

<p> Defines a paragraph

<pre> Defines preformatted text

<q> Defines a short quotation

<samp> Defines sample computer code text

<small> Defines small text

<span> Defines a section in a document

<s> Defines strikethrough text

<strike> Defines strikethrough text

<strong> Defines strong text

<sub> Defines subscripted text

<sup> Defines superscripted text

<u> Defines underlined text

Dr. Dobb's encourages readers to engage in spirited, healthy debate, including taking us to task. However, Dr. Dobb's moderates all comments posted to our site, and reserves the right to modify or remove any content that it determines to be derogatory, offensive, inflammatory, vulgar, irrelevant/off-topic, racist or obvious marketing or spam. Dr. Dobb's further reserves the right to disable the profile of any commenter participating in said activities.

Disqus Tips To upload an avatar photo, first complete your Disqus profile. | View the list of supported HTML tags you can use to style comments. | Please read our commenting policy.