Versions Compared

Key

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

...

The first thing you do is to create a folder on you disk into which you will download the TUSCANY distribution.
Next you download the latest release distribution. Launch your browser and enter one of the
following URL's.
Latest Release - http://cwiki.apache.org/TUSCANY/sca-java-releases.html
Download both the bin zip as well as the src zip to the folder that you created on your disk. Once
you completed the download you should see the following on your disk.
!release_zips.png!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

...

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

ShoppingCart

In this step you create the ShoppingCart service implementation.

...

http://svn.apache.org/repos/asf/incubator/tuscany/java/sca/modules/binding-jsonrpc/src/main/resources/org/apache/tuscany/sca/binding/jsonrpc/jsonrpc.js

Next select the "ufservices" package again. Right click to get the context menu, select New, and
then File. In the New File dialog enter "binding-atom.js" for the File name, and then select Finish
to complete the dialog.

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

Code Block
 functionfunction AtomClient(uri) {
	this.uri=uri;
	this.get = function(id, responseFunction) {
		var xhr = this.createXMLHttpRequest();
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					if (responseFunction != null)
						responseFunction(xhr.responseXML);
				} else {
				alert("get - Error getting data from the server");
				}
			}
		}
		xhr.open("GET", uri + id, true);
		xhr.send(null);
	}
	this.post = function (entry, responseFunction) {
	var xhr = this.createXMLHttpRequest();
	xhr.onreadystatechange = function() {
		if (xhr.readyState == 4) {
			if (xhr.status == 201) {
				if (responseFunction != null)
					responseFunction(xhr.responseXML);
				} else {
					alert("post - Error getting data from the server");
				}
			}
		}
		xhr.open("POST", uri, true);
		xhr.setRequestHeader("Content-Type", "application/atom+xml");
		xhr.send(entry);
	}
	this.put = function (id, entry, responseFunction) {
		var xhr = this.createXMLHttpRequest();
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					if (responseFunction != null)
						responseFunction(xhr.responseXML);
				} else {
					alert("put - Error getting data from the server");
				}
			}
		}
		xhr.open("PUT", uri + id, true);
		xhr.setRequestHeader("Content-Type", "application/atom+xml");
		xhr.send(entry);
	}
	this.delete = function (id, responseFunction) {
		var xhr = this.createXMLHttpRequest();
		xhr.onreadystatechange = function() {
			if (xhr.readyState == 4) {
				if (xhr.status == 200) {
					if (responseFunction != null) responseFunction();
				} else {
					alert("delete - Error getting data from the server");
				}
			}
		}
		xhr.open("DELETE", uri + id, true);
		xhr.send(null);
	}
	this.createXMLHttpRequest = function () {
		try {return new XMLHttpRequest();} catch(e) {}
		try {return new ActiveXObject("Msxml2.XMLHTTP");} catch(e) {}
		try {return new ActiveXObject("Microsoft.XMLHTTP");} catch(e) {}
		alert("XML http request not supported");
		return null;
	}
}

...

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

Code Block
 <<?xml version="1.0" encoding="UTF-8"?>
<composite xmlns="http://www.osoa.org/xmlns/sca/1.0"
	xmlns:t="http://tuscany.apache.org/xmlns/sca/1.0"
	xmlns:s="http://store"
	name="store">
	<component name="ufs">
		<t:implementation.resource location="ufservices"/>
		<service name="Resource">
			<t:binding.http/>
		</service>
	</component>
	<component name="Catalog">
		<implementation.java class="services.CatalogImpl"/>
		<property name="currencyCode">USD</property>
		<service name="Catalog">
			<t:binding.jsonrpc/>
		</service>
		<reference name="currencyConverter" target="CurrencyConverter"/>
	</component>
	<component name="ShoppingCart">
		<implementation.java class="services.ShoppingCartImpl"/>
		<service name="Collection">
			<t:binding.atom/>
		</service>
	</component>
	<component name="CurrencyConverter">
		<implementation.java class="services.CurrencyConverterImpl"/>
	</component>
</composite>

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.

...

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


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

...

 Use the browser back button to get back to the Store page.

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.


 
In Eclipse create a New Java Project, specify the project name, select Create project from
existing source, and specify the folder that contains the sample source.


 
Use Next to get to the next page in the New Java Project dialog. There go to the Libraries tab, use
the Add Library... pushbutton to add the JUnit library and the user library TUSCANY.


 
Finish the New Java Project dialog. You now have the sample project available in the Eclipse
workbench.


 
For the calculator sample that we've chosen go to its CalculatorClient class and select Run As ->
Java Application. You will see the following output in the console.

...