Ready, Set, Go Getting started with Tuscany



Similar documents
JBoss Portal 2.4. Quickstart User Guide

Upgrading User-ID. Tech Note PAN-OS , Palo Alto Networks, Inc.

Building A Very Simple Website

WebSphere Business Monitor V7.0 Script adapter lab

This tutorial provides detailed instructions to help you download and configure Internet Explorer 6.0 for use with Web Commerce application.

Test Automation Integration with Test Management QAComplete

TAMUS Terminal Server Setup BPP SQL/Alva

WIRIS quizzes web services Getting started with PHP and Java

Building A Very Simple Web Site

Application. 1.1 About This Tutorial Tutorial Requirements Provided Files

IDS 561 Big data analytics Assignment 1

Hadoop Tutorial. General Instructions

owncloud Configuration and Usage Guide

Installation Guidelines (MySQL database & Archivists Toolkit client)

Load testing with. WAPT Cloud. Quick Start Guide

POOSL IDE Installation Manual

Basics. a. Click the arrow to the right of the Options button, and then click Bcc.

Composite.Community.Newsletter - User Guide

How to install and use the File Sharing Outlook Plugin

Wakanda Studio Features

Selenium Automation set up with TestNG and Eclipse- A Beginners Guide

DocuSign for SharePoint

Installing the ASP.NET VETtrak APIs onto IIS 5 or 6

Struts Tools Tutorial. Version: M5

EMC Documentum Composer

Installing the Android SDK

How to add your Weebly website to a TotalCloud hosted Server

Tutorial 5: Add-to-Cart Button

Quick Start Guide. Installation and Setup

Deploying Intellicus Portal on IBM WebSphere

IBM Operational Decision Manager Version 8 Release 5. Getting Started with Business Rules

NSi Mobile Installation Guide. Version 6.2

Hadoop Basics with InfoSphere BigInsights

Google Trusted Stores Setup in Magento

How To Test Your Web Site On Wapt On A Pc Or Mac Or Mac (Or Mac) On A Mac Or Ipad Or Ipa (Or Ipa) On Pc Or Ipam (Or Pc Or Pc) On An Ip

Getting Started using the SQuirreL SQL Client

Before you can use the Duke Ambient environment to start working on your projects or

NetBeans IDE Field Guide

Table of Contents. 1. Content Approval...1 EVALUATION COPY

isupplier PORTAL ACCESS SYSTEM REQUIREMENTS

Table of Contents. Welcome Login Password Assistance Self Registration Secure Mail Compose Drafts...

User Guide Trust Safety Accounting Upload PC Law and SFTP Software Release: Final Date

EM L18 Managing ios and Android Mobile Devices with Symantec Mobile Management Hands-On Lab

Designing and Implementing Forms 34

Monitoring Oracle Enterprise Performance Management System Release Deployments from Oracle Enterprise Manager 12c

KeePass Getting Started on Windows

How To Install An Aneka Cloud On A Windows 7 Computer (For Free)

Setup Guide for PrestaShop and BlueSnap

1. To ensure the appropriate level of security, you will need Microsoft Windows XP or above.

Tutorial: Building a Dojo Application using IBM Rational Application Developer Loan Payment Calculator

Operational Decision Manager Worklight Integration

Instructions for Configuring a SAS Metadata Server for Use with JMP Clinical

ProSystem fx Document

Census. di Monitoring Installation User s Guide

Configure the idrac Remote Access Console

Cloud Administration Guide for Service Cloud. August 2015 E

IBM BPM V8.5 Standard Consistent Document Managment

BushSoft Accounts - Installation manual

Shopping Cart Software

RoomWizard Synchronization Software Manual Installation Instructions

UOFL SHAREPOINT ADMINISTRATORS GUIDE

Setting up VMware ESXi for 2X VirtualDesktopServer Manual

tools that make every developer a quality expert

The goal with this tutorial is to show how to implement and use the Selenium testing framework.

Appendix A How to create a data-sharing lab

Software Development Environment. Installation Guide

Oracle SOA Suite 11g Oracle SOA Suite 11g HL7 Inbound Example

How To Use Query Console

Download and Installation Instructions. Android SDK and Android Development Tools (ADT)

3. Installation and Configuration. 3.1 Java Development Kit (JDK)

MAPPING THE WEBDRIVE REFERENCE GUIDE

EVALUATION ONLY. WA2088 WebSphere Application Server 8.5 Administration on Windows. Student Labs. Web Age Solutions Inc.

CHARTER BUSINESS custom hosting faqs 2010 INTERNET. Q. How do I access my ? Q. How do I change or reset a password for an account?

System Administration Training Guide. S100 Installation and Site Management

JBoss SOAP Web Services User Guide. Version: M5

Creating Web Services Applications with IntelliJ IDEA

Initial Setup of Microsoft Outlook 2011 with IMAP for OS X Lion

Microsoft Entourage 2008 / Microsoft Exchange Server Installation and Configuration Instructions

Microsoft Outlook Web Access Handbook

UF Health SharePoint 2010 Document Libraries

Shasta College SharePoint Tutorial. Create an HTML Form

Appspace 5.X Reference Guide (Digital Signage) Updated on February 9, 2015

Migrating helpdesk to a new server

INFORMATION SYSTEMS SERVICE NETWORKS AND TELECOMMUNICATIONS SECTOR. User Guide for the RightFax Fax Service. Web Utility

Developing Web Views for VMware vcenter Orchestrator

Transferring Your Hosting Account

Eclipse installation, configuration and operation

Create e-commerce website Opencart. Prepared by : Reth Chantharoth Facebook : rtharoth@yahoo.

Developing an EJB3 Application. on WebSphere 6.1. using RAD 7.5

Deploying Physical Solutions to InfoSphere Master Data Management Server Advanced Edition v11

Smooks Dev Tools Reference Guide. Version: GA

Installing Moodle for Windows with Easy PHP Illustrated Install Guide By Floyd Collins

PDG Shopping Cart 4.0. Quick Start Guide

How to use the Eclipse IDE for Java Application Development

Sage CRM. 7.2 Mobile Guide

Table of Contents. Table of Contents

SelectSurvey.NET Developers Manual

Web Content Management Training Manualv3

To begin, visit this URL:

Transcription:

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 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. 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. From the menu bar select Window and then Preferences. The Preferences dialog will appear, in its left navigation tree select Java, followed by Build Path, and followed by User Libraries. Select the New pushbutton on the right of the New Libraries dialog to create a new user library. The user library created is empty, select the Add JARs pushbutton on the right to add all the jar s from your Tuscany installation lib folder. When completed all the jar s will appear under the TUSCANY user library. - define a new userlibrary for tuscany Since some of you maybe interested in debugging also the Tuscany runtime code we will attach the Tuscany source to the Tuscany runtime jar in the following step. In the User Libraies dialog scroll down until you see the Tuscany runtime jar and select its Source attachment. Select the Edit pushbutton on the right and in the Edit dialog use the External File pushbutton to the select the Tuscany src zip that we downloaded earlier. Select OK to complete this and the Preferences dialog, and you are done with the Tuscany setup for Eclipse.

Create your 1 st Composite Service Application The following shows the composition diagram for the composite service application you are about to create. store binding.jsonrpc currencycode Store Catalog Currency Converter http ShoppingCart binding.atom 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. package services; import org.osoa.sca.annotations.remotable; @Remotable public interface Catalog { String[] get();

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 by copy-paste of the following Java class code snippet. package services; import java.util.arraylist; import java.util.list; import org.osoa.sca.annotations.init; import org.osoa.sca.annotations.property; import org.osoa.sca.annotations.reference; public class CatalogImpl implements Catalog { @Property public String currencycode = "USD"; @Reference public CurrencyConverter currencyconverter; private List<String> catalog = new ArrayList<String>(); @Init public void init() { String currencysymbol = currencyconverter.getcurrencysymbol(currencycode); catalog.add("apple - " + currencysymbol + currencyconverter.getconversion("usd", currencycode, 2.99f)); catalog.add("orange - " + currencysymbol + currencyconverter.getconversion("usd", currencycode, 3.55f)); catalog.add("pear - " + currencysymbol + currencyconverter.getconversion("usd", currencycode, 1.55f)); public String[] get() { String[] catalogarray = new String[catalog.size()]; catalog.toarray(catalogarray); return catalogarray; 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 copypaste the following Java interface code snippet into it. package services; import org.osoa.sca.annotations.remotable; @Remotable public interface CurrencyConverter { public float getconversion(string fromcurrenyccode, String tocurrencycode, float amount); public String getcurrencysymbol(string currencycode); Next create a Java class in the services package named CurrencyConverterImpl and copypaste the following Java class code snippet into it. 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. You follow the same steps that you learned previously to create the implementation. Create a Java class in the services package named ShoppingCartImpl and copy-paste the following Java class code snippet into it. package services; import java.util.date; import java.util.hashmap; import java.util.map; import java.util.uuid; import org.apache.tuscany.sca.binding.feed.collection.collection; import org.apache.tuscany.sca.binding.feed.collection.notfoundexception; import com.sun.syndication.feed.atom.content; import com.sun.syndication.feed.atom.entry; import com.sun.syndication.feed.atom.feed; import com.sun.syndication.feed.atom.link; public class ShoppingCartImpl implements Collection { // needs to change to instance var once conversation scope works private static Map<String, Entry> cart = new HashMap<String, Entry>(); public Feed getfeed() { Feed feed = new Feed(); feed.settitle("shopping cart"); Content subtitle = new Content(); subtitle.setvalue("total : " + gettotal()); feed.setsubtitle(subtitle); feed.getentries().addall(cart.values()); return feed; public Entry get(string id) throws NotFoundException { return cart.get(id); public Entry post(entry entry) { String id = "cart-" + UUID.randomUUID().toString(); entry.setid(id); Link link = new Link(); link.setrel("edit"); link.sethref("" + id); entry.getotherlinks().add(link); link = new Link(); link.setrel("alternate"); link.sethref("" + id); entry.getalternatelinks().add(link); entry.setcreated(new Date()); cart.put(id, entry); return entry; public Entry put(string id, Entry entry) throws NotFoundException { entry.setupdated(new Date()); cart.put(id, entry); return entry; public void delete(string id) throws NotFoundException { if (id.equals("")) cart.clear(); else cart.remove(id);

private String gettotal() { float total = 0; String symbol = ""; if (!cart.isempty()) { Entry entry = cart.values().iterator().next(); String item = ((Content)entry.getContents().get(0)).getValue(); symbol = item.substring(item.indexof("-")+2, item.indexof("-")+3); for (Entry entry : cart.values()) { String item = ((Content)entry.getContents().get(0)).getValue(); total += Float.valueOf(item.substring(item.indexOf("-")+3)); return symbol + String.valueOf(total); 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 copypaste of the following html snippet. <html> <head> <title>store</title> <script type="text/javascript" src="binding-atom.js"></script> <script type="text/javascript" src="binding-jsonrpc.js"></script> <script language="javascript"> //Reference catalog = (new JSONRpcClient("../Catalog/")).Catalog; //Reference shoppingcart = new AtomClient("../ShoppingCart/");

function catalog_getresponse(items) { var catalog = ""; for (var i=0; i<items.length; i++) catalog += '<input name="items" type="checkbox" value="' + items[i] + '">' + items[i]+ ' <br>'; document.getelementbyid('catalog').innerhtml=catalog; function shoppingcart_getresponse(feed) { if (feed!= null) { var entries = feed.getelementsbytagname("entry"); var list = ""; for (var i=0; i<entries.length; i++) { var item = entries[i].getelementsbytagname("content")[0].firstchild.nodevalue; list += item + ' <br>'; document.getelementbyid("shoppingcart").innerhtml = list; if (list!= "") document.getelementbyid('total').innerhtml = feed.getelementsbytagname("subtitle")[0].firstchild.nodevalue; function shoppingcart_postresponse(entry) { shoppingcart.get("", shoppingcart_getresponse); function addtocart() { var items = document.catalogform.items; var j = 0; for (var i=0; i<items.length; i++) if (items[i].checked) { var entry = '<entry xmlns="http://www.w3.org/2005/atom">' + '<title>cart-item</title>' + '<content type="text">'+items[i].value+'</content>' + '</entry>'; shoppingcart.post(entry, shoppingcart_postresponse); items[i].checked = false; function checkoutcart() { document.getelementbyid('store').innerhtml='<h2>' + 'Thanks for Shopping With Us!</h2>'+ '<h2>your Order</h2>'+ '<form name="orderform" action="/ufs/store.html">'+ document.getelementbyid('shoppingcart').innerhtml+ '<br>'+ document.getelementbyid('total').innerhtml+ '<br>'+ '<br>'+ '<input type="submit" value="continue Shopping">'+ '</form>'; shoppingcart.delete("", null); function deletecart() { shoppingcart.delete("", null); document.getelementbyid('shoppingcart').innerhtml = ""; document.getelementbyid('total').innerhtml = ""; window.onload = function() { catalog.get(catalog_getresponse); shoppingcart.get("", shoppingcart_getresponse); </script> <link rel="stylesheet" type="text/css" href="style.css" /> </head> <body>

<h1>store</h1> <div id="store"> <h2>catalog</h2> <form name="catalogform"> <div id="catalog" ></div> <br> <input type="button" onclick="addtocart()" value="add to Cart"> </form> <br> <h2>your Shopping Cart</h2> <form name="shoppingcartform"> <div id="shoppingcart"></div> <br> <div id="total"></div> <br> <input type="button" onclick="checkoutcart()" value="checkout"> <input type="button" onclick="deletecart()" value="empty"> <a href="../shoppingcart/"> <img src="http://projects.apache.org/images/blue-icon.png" border="0"> </a> </form> </div> </body> </html> 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-jsonrpc.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 javascript snippet you find here: https://svn.apache.org/repos/asf/incubator/tuscany/java/sca/modules/bindingjsonrpc/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. function 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; Note: That we have to have the bindig-jsonrpc.js, and binding-atom.js local in our project is only temporary, so this step will be removed in the future. 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 by copy-paste of the following composite snippet. <?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"> </composite> <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> 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. Select the store project and click on the New Java Package button in the toolbar to start the package creation dialog. Use the dialog to create a new package named launch. Select the launch package. Select the New Java Class button. In the dialog enter Launch as the Name of the class, check the checkbox for creating a main method stub, 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 by copy-paste of the following Java class code snippet. package launch; import org.apache.tuscany.sca.host.embedded.scadomain; public class Launch { public static void main(string[] args) throws Exception { System.out.println("Starting..."); SCADomain scadomain = SCADomain.newInstance("store.composite"); System.out.println("store.composite ready for big business!!!"); System.out.println(); System.in.read(); scadomain.close(); After completing these steps the content of the store project will look as follows. Congratulations you completed your 1 st 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. First select the Launch class in the launch package of your store project. Right click to get the context menu, select Run As, and then Java application. The Tuscany runtime will start up adding the store composition to its domain. The Eclipse console will show the following messages. Next Launch your Web browser and enter the following address: http://localhost:8080/ufs/store.html 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. Note: When adding items for the first time you will be asked for userid and password by the browser. Enter admin for both. 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.

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.