Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Ready, Set, Go - Getting started with Tuscany

Install the Tuscany Distribution 

The first thing you do is to create a folder on you disk into which you will download the TUSCANY distribution.

...


 
Next you unzip the bin zip in place, you should see the following folder file structure on your disk after unzip is complete.

Setup Eclipse for Tuscany

Start Eclipse and create a User Library to contain the TUSCANY runtime jar's as well as their
depending jar's.

...

Select OK to complete this and the Preferences dialog, and you are done with the Tuscany setup
for Eclipse.

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 separate
folders 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 user 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 by
copy-paste of the following Java interface 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.
  

...

Code Block
package services;
public class CurrencyConverterImpl implements CurrencyConverter {
	public float getConversion(String fromCurrencyCode,
		String toCurrencyCode, float amount) {
		if (toCurrencyCode.equals("USD"))
			return amount;
		else 			if (toCurrencyCode.equals("EUR"))
				return amount*0.7256f;
		return 0;
	}
	public String getCurrencySymbol(String currencyCode) {
		if (currencyCode.equals("USD"))
			return "$";
		else
			if (currencyCode.equals("EUR"))
				return "?";
		return "?";
	}
}

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

ShoppingCart

In this step you create the ShoppingCart service implementation.

...

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.

...

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.

...

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


 

Launch Services

In this step you create the code to launch the Tuscany runtime with the new store composite
service you created.

...


Congratulations you completed your 1st composite service applications, now its time to take it into
action.

Use Services

In this step you launch and use the store composite service application you created.

...

And then you can Checkout to complete your order.

Explore the Samples from the Tuscany Distribution

The sample folder of the Tuscany distribution provides a rich set of samples ready for you to explore.

...