Wednesday, October 3, 2007

Developing an SCA application with Apache Tuscany and Eclipse

I'm working on Apache Tuscany. Tuscany implements the Service Component Architecture (SCA) specification.

The last few months I spent a lot of time in Eclipse developing SCA samples and demos for Tuscany. I found myself tweaking my various Eclipse workspaces again and again to do the following:

- Define a Tuscany User Library containing all the Tuscany JARs to make it easier to add them to my project buildpath.

- Associate .composite files with the XML editor and register the SCA and Tuscany XML schemas to get code-assist in the editor and validation of my composite files.

- Write programs to launch Tuscany configured with my various composites... wishing that I could just right-click on the .composite and select a Run As / Tuscany...

Finally, I got tired of repeating these steps again and again and decided to put together a small tool made of two simple Eclipse plugins to package Tuscany in a Library and take care of all that configuration.

I'm thinking that it could be useful to others as well so here's a brief description of how to use it.

The tool works with Eclipse 3.3 Europa. It can be installed on top of the Europa "Eclipse IDE for Java Developers" distro. Here's how to install it:

From the Eclipse Workbench menu bar select Help - Software Updates - Find and Install. The Install - Feature Updates dialog will open.

Select "Search for new features to install", press Next. The "Update sites to visit" dialog will appear.

Press New Remote site.

In the New Update site dialog enter,
Name: Tuscany
Press OK.

Make sure that Tuscany is selected in the list of sites to visit as shown here:

Now press Finish, the Updates - Search results dialog will appear. Select Tuscany as shown below:

Press Next. In the Feature license dialog, accept the license agreement then press Next. Press Next again, the following Installation dialog will appear:

Press Finish to download the Tuscany plugins. The download is about 35Mb as it includes the Tuscany runtime plus all the dependencies for all the SCA implementation types and bindings supported by Tuscany. But I found having everything in one download more convenient as it saves you from having to solve the JAR dependency puzzle and fish for all the required JARs...

After the download completes you should see the following dialog:

You're now ready to install the Tuscany plugins. Press Install All, the plugins will be installed:

Restart your Workbench.

You're now equipped with a tool to help you write, test, and run an SCA application in Eclipse!

To show how to use the tool let's develop a simple HelloWorld application with an SCA Java component providing a Service with two bindings, a Web Service binding and a JSONRPC binding. It should just take about 5 minutes :)

First let's create a Java project. From the Workbench menu bar select New - Java Project. In the New Java Project dialog, enter a name for the project as follows:

Press Next. In the Java Settings dialog, select the Libraries tab.

Now you need to add the Tuscany library to the project. Click Add then in the Add Library dialog select the Tuscany library as follows:

Press Next then Finish. The Tuscany library should be on your project's build path, as shown here:

Press Finish to create the Project.

Now let's create a Java interface and a Java implementation class for our Hello SCA component.

Right click on the src folder, then select New - Interface. In the New Java Interface dialog, enter
Package: hello
Name: Hello

Press Finish to create the Hello interface. The Java editor will open, add the following method to the Hello interface:

String hey(String name);

Press Ctrl+S to save the file.

The editor and the contents of the file are shown here:

Now let's create the HelloImpl Java implementation class. Right click the Hello interface, then select New - Class. In the New Java Class dialog, enter
Name: HelloImpl
Make sure that hello.Hello is listed in the list of interfaces.

Press Finish to create the Hello interface. The Java editor will open, add the following code to the HelloImpl.hey(...) method:

return "Hey " + name;

Press Ctrl+S to save the file.

The editor and the contents of the file are shown here:

Now let's turn the HelloImpl class into an SCA component. To do that we need to create an SCA Composite file describing the component its services and their binding configuration.

From the workbench menu bar, select New - Other, in the New Wizard dialog select the Tuscany - Composite wizard, as shown here:

Press Next, you're about to create your first SCA composite :) In the New SCA Composite dialog, make sure that Hello/src is selected as parent folder then enter,
File name: Hello.composite

Press Finish, Hello.composite will open in the XML editor. You should be able to use code assist in the XML editor to edit your SCA composite, as shown below:

Add the following to your SCA composite:

<component name="Hello">
< class="hello.HelloImpl"/>
<service name="Hello">
< uri="hello-there"/>
<t:binding.jsonrpc uri="hello-nicer"/>

This declares an SCA component implemented by the HelloImpl class, providing our little Hello Service over two bindings, Web Service (SOAP) and JSONRPC.

Press Ctrl+S to save the file.

The editor and the contents of the file are shown here:

That's it for coding! Let's try to run this SCA Composite now...

It's pretty simple. Right click Hello.composite then from the popup-menu select Run As - Tuscany.

The Tuscany Runtime should start the Hello composite and you'll see the following in the Console view:

Your SCA composite is now up and running, providing a Hello Web Service at http://localhost:8085/hello-there and a JSONRPC service at http://localhost:8080/hello-nicer.

You can click these links to check that the services are running OK and get their WSDL and SMD descriptions, as shown below:

The WSDL describing the Web Service:

The SMD describing the JSONRPC service:

That's all for today... If you got to the end of this post, I hope you'll find this little Tuscany tool useful.


jr said...

Hi, this looks pretty awesome and i like SCA but the plugin thems to be a bit outdated. Do you know about a newer version? I know the Post is pretty old, but i still love this way (and i dont see any better atm for eclipse to build smart webservices in a abstract way)

Jean-Sebastien Delfino said...

Right, this is a very old post from Oct 2007 :)

The latest version of the plugins comes with Tuscany SCA release 1.5.1, including an Eclipse update site and some documentation.

You may also want to check out the Eclipse SCA Tools project, they have a pretty cool SCA composite graphical editor and integration with Tuscany.

For more info you can post questions or issues to the and mailing lists.

The postings on this site are my own and don’t necessarily represent positions, strategies or opinions of my employer IBM.