SCA is a relative new technology that’s bound to take off next year. The apache Tuscany project released the 1.0 version of the java implementation in September, and Oracle will include it in the upcoming SOA Suite 11. Time for some research into this technology.
In the following example I’m using version 1.0.1 of Apache Tuscany. You can download it from the Tuscany website.
First step will be to implement a service component which consist of one service. The component endpoint will be exposed as a web service. First the service. The service consists of an interface and an implementation. The interface:
package nl.iteye.patient;
import org.osoa.sca.annotations.Remotable;
import org.osoa.sca.annotations.Service;
@Remotable
public interface PatientService {
public String ping(String message);
}
The Remotable annotation indicates that is a service which can be called remotely. The implementation is as follows:
package nl.iteye.patient;
import org.osoa.sca.annotations.Service;
@Service(PatientService.class)
public class PatientServiceImpl implements PatientService {
public PatientServiceImpl() {
}
public String ping(String message) {
System.out.println("received ping request: " + message);
return "hello: " + message;
}
}
Just a simple ping as you can see. The Service annotation indicates that this is the implementation of the previously defined remotable interface.
Next I have to define a Service Component in a composite configuration file. A composite can actually consist of a large number of components, including java services, bpel processes, etc. You use the composite configuration file to wire all these components together. This enables you to created coarse grained SOA modules, which also makes management and deployment easier than having all these components as separate deployables. Back to the configuration file, here it is:
< ?xml version="1.0" encoding="windows-1252" ?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
targetNamespace="http://patient.iteye.nl" xmlns:pws="http://patient.iteye.nl"
name="patient">
<component name="PatientServiceComponent">
<implementation .java class="nl.iteye.patient.PatientServiceImpl"/>
<service name="PatientService">
<interface .java interface="nl.iteye.patient.PatientService"/>
<binding .ws/>
</service>
</component>
</composite>
That’s it. You now have a composite application consisting of one service which is exposed as a web service.
To test the application I created the following unit test:
package tests.nl.iteye.patient;
import java.io.IOException;
import junit.framework.TestCase;
import nl.iteye.patient.PatientService;
import org.apache.tuscany.sca.host.embedded.SCADomain;
import org.junit.Test;
public class ScaContainerStarterTestCase extends TestCase {
public ScaContainerStarterTestCase() { }
@Test
public void testPing() throws IOException {
SCADomain scaDomain;
scaDomain = SCADomain.newInstance("patient.composite");
PatientService patSvc =
scaDomain.getService(PatientService.class, "PatientServiceComponent");
String result = patSvc.ping("hello world!");
System.out.println("result: " + result);
scaDomain.close();
}
}
To build the project I used the following maven pom.xml:
< ?xml version="1.0" encoding="UTF-8"?>
<project>
<modelversion>4.0.0</modelversion>
<parent>
<groupid>nl.iteye</groupid>
<artifactid>patient-example</artifactid>
<version>1.0-SNAPSHOT</version>
<relativepath>../pom.xml</relativepath>
</parent>
<repositories>
<repository>
<id>apache.incubator</id>
<url>http://people.apache.org/repo/m2-incubating-repository</url>
</repository>
</repositories>
<artifactid>patient-service</artifactid>
<name>Patient Service</name>
<dependencies>
<dependency>
<groupid>org.apache.tuscany.sca</groupid>
<artifactid>tuscany-host-embedded</artifactid>
<version>1.0.1-incubating</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupid>org.apache.tuscany.sca</groupid>
<artifactid>tuscany-implementation-java-runtime</artifactid>
<version>1.0.1-incubating</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupid>org.apache.tuscany.sca</groupid>
<artifactid>tuscany-binding-ws-axis2</artifactid>
<version>1.0.1-incubating</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupid>org.apache.tuscany.sca</groupid>
<artifactid>tuscany-host-jetty</artifactid>
<version>1.0.1-incubating</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupid>org.apache.derby</groupid>
<artifactid>derby</artifactid>
<version>10.3.1.4</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupid>junit</groupid>
<artifactid>junit</artifactid>
<version>4.4</version>
<scope>compile</scope>
</dependency>
</dependencies>
<build>
<finalname>${artifactId}</finalname>
</build>
</project>
As you can see in the pom, i have a parent project. The current project implements a service, in another project i will implement a client application. So to sum up, the service project contains the following files:

Please ignore PatientDbInstaller.java, ScaContainerStarter.java (we’ll come to this later), build.cmd (i use this to run maven), and patient-service.jpr (this is the jdeveloper project file).
Now when you run maven (mvn clean package), it will compile and package the composite application and it will also run your test class. The output (just the test part) should be something like:
-------------------------------------------------------
T E S T S
-------------------------------------------------------
Running tests.nl.iteye.patient.ScaContainerStarterTestCase
Dec 19, 2007 2:06:31 PM org.apache.tuscany.sca.http.jetty.JettyServer addServletMapping
INFO: Added Servlet mapping: http://localhost:8085/PatientServiceComponent
received ping request: hello world!
result: hello: hello world!
When you create a sca domain, the jetty web container is started to host the web service. Now you can invoke the webservices in your composite application.
Another way to test the application is to start your composite application and test it by calling the webservice, for example using soapUI. Start your application as follows:
package nl.iteye.patient;
import org.apache.tuscany.sca.host.embedded.SCADomain;
public class ScaContainerStarter {
public ScaContainerStarter() {
try {
SCADomain scaDomain;
scaDomain = SCADomain.newInstance("patient.composite");
System.in.read();
scaDomain.close();
} catch (Exception e) {
e.printStackTrace();
}
}
public static void main(String[] args) {
ScaContainerStarter scaContainerStarter = new ScaContainerStarter();
}
}
When you run this you should be able to open the wsdl of your application at http://localhost:8085/PatientServiceComponent?wsdl. Open the wsdl in soapUI and it will create a request for you which you can execute to invoke the web service. The result should look like this:

One warning, i noticed that you may get some weird exceptions when using the wrong classpath. When you download the binary version of tuscany SCA, you’ll notice a large number of jars in the directories lib and modules. Don’t put every jar on your classpath. It’s enough to include tuscany-sca-manifest.jar in the lib folder. When i included the jars in the modules folder i got some null pointer and classcast exceptions.