Install the Latest Tuscany Eclipse Plugin

A quick Step by Step walk through of downloading, installing, and verifying the Tuscany Eclipse Plugins.

This section shows you how to install the lastest Tuscany Eclipse plugin. The plugin gives you the ability to run an SCA composite file from the Package Explorer. You will see a "Run As Tuscany" menu item when you bring up the context menu on composite files.

Start Eclipse and go to Help -> Software Updates -> Find and Install. Select "Search for new features to install" and then click next

Select the "Apache Tuscany SCA Tools" and click "Next", and then, on the next dialog, click "Finish". Accept the "Plugin License" and next click on "Install All".

When asked to "restart eclipse", click the "yes" button.

Create your 1st Composite Service Application

The following shows the composition diagram for the composite service application you are about
to create.

The composite service application you will create is a composition of four services. The composed
service provided is that of an on-line store.
There is a Catalog service which you can ask for catalog items, and depending on its currency
code property configuration it will provide the item prices in USD or EUR. The Catalog service is not
doing the currency conversion itself it references a CurrencyConverter service to do that task. Then
there is the ShoppingCart service into which items chosen from the catalog can be added, it is
implemented as a REST service. The Catalog is bound using the JSONRPC binding, and the
ShoppingCart service is bound using the ATOM binding. Finally there is the Store user facing
service that provides the browser based user interface of the store. The Store service makes use of
the Catalog and ShoppingCart service using the JSONRPC, and ATOM binding respectively.

Create a Java Project

In this step you create a Java Project in Eclipse to hold the composite service application.
Click on the New Java Project button in the toolbar to launch the project creation dialog.
Next you enter "store" as the Project name, and for Project Layout select Create separatefolders for sources and class files.

Hit the Next button, and on the following page go to the Libraries tab. Use the Add Library...
button on the right to add the Tuscany Library library to the project.

Hit the Finish button to complete the New Java Project dialog to create the "store" java project.

Construct Services

First you create two package folders into which later in this step you place service implementations.
Select the "store" project and click on the New Java Package button in the toolbar to launch
the package creation dialog.

Next you enter "services" as the package Name, and press the Finish button to complete the
dialog.

Repeat the previous step to create another package named "ufservices". The store project now
should look as follows.

In the following you will place in the "services" package the regular services, and in the "ufservices"
package the user facing services of the composite service application you create.

Catalog

In this step you create the Catalog service interface and implementation.
Select the "services" package. Next you click on the dropdown arrow next to the New Java Class
button and select the New Java Interface option from the dropdown list. In the dialog
enter "Catalog" as the Name of the interface and select the Finish button to complete the dialog.
The Java editor will open on the new created Java interface. Replace the content of the editor bycopy-paste of the following Java interface code snippet.

Select the "services" package again. Select the New Java Class button . In the dialog enter
"CatalogImpl" as the Name of the class, add "Catalog" as the interface this class implements, and
then select Finish to complete the dialog.

The Java editor will open on the new created Java class. Replace the content of the editor bycopy-paste of the following Java class code snippet.

After completing these steps the content of the "store" project will look as follows.

Note: CatalogImpl is red x'ed because it makes use of the CurrencyConverter interface that we
have not implemented yet.

CurrencyConverter

In this step you create the CurrencyConverter service interface and implementation.
You follow the same steps that you learned previously to create the interface and implementation.
First create a Java interface in the "services" package named "CurrencyConverter" and copy-paste
the following Java interface code snippet into it.

After completing these steps the content of the "store" project will look as follows.

ShoppingCart

In this step you create the Item model object, the Cart and Total service interfaces and the ShoppingCart service implementation.
You follow the same steps that you learned previously to create the interface and implementation.

Create a Java class in the "services" package named "Item" and copy-paste the
following code snippet into it.

Note: Since the Tuscany conversational support is not ready yet the cart is realized through a hack.
The cart field is defined as static.

After completing these steps the content of the "store" project will look as follows.

Store

In this step you create the user facing Store service that will run in a Web browser and provide the
user interface to the other services you created.

Select the "ufservices" package. Right click to get the context menu, select New, and then File. In
the New File dialog enter "store.html" for the File name, and then select Finish to complete the
dialog.

The Text editor will open on the new created html file. Replace the content of the editor by copy-paste
of the following html snippet.

After completing these steps the content of the "store" project will look as follows.

Compose Services

Now that you have all the required service implementations you compose them together to provide
the store composite service. The composition is stored in a .composite file.

Select the "src" folder of the "store" project. Right click to get the context menu, select New, and
then File. In the New File dialog enter "store.composite" for the File name, and then select Finish
to complete the dialog.

The Text editor will open on the new created composite file. Replace the content of the editor bycopy-paste of the following composite snippet.

You get to the Store user facing service of the composite service application.

You can select items from the Catalog and add them to your Shopping Cart.

Since the ShoppingCart service is bound using the ATOM binding, you can also look at the
shopping card content in ATOM feed form by clicking on the feed icon . You get the browsers default rendering for ATOM feeds.