From 83355a7557cf91c455a65e0ce79ea8dd4d880052 Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 13 Jan 2010 02:16:12 +0000 Subject: Refactoring sandbox structure to accomodate 1.x versus 2.x stuff git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@898623 13f79535-47bb-0310-9956-ffa450edef68 --- .../sca-1.x/samples/calculator-jsf-webapp/README | 118 ++++ .../samples/calculator-jsf-webapp/build.xml | 137 +++++ .../calculator-jsf-webapp/calculator-web.png | Bin 0 -> 22916 bytes .../calculator-jsf-webapp/calculator-web.svg | 358 ++++++++++++ .../sca-1.x/samples/calculator-jsf-webapp/pom.xml | 77 +++ .../src/main/java/beans/Calculator.java | 78 +++ .../src/main/java/calculator/AddService.java | 28 + .../src/main/java/calculator/AddServiceImpl.java | 30 + .../src/main/java/calculator/CalculatorClient.java | 47 ++ .../main/java/calculator/CalculatorService.java | 35 ++ .../java/calculator/CalculatorServiceImpl.java | 69 +++ .../src/main/java/calculator/DivideService.java | 28 + .../main/java/calculator/DivideServiceImpl.java | 30 + .../src/main/java/calculator/MultiplyService.java | 28 + .../main/java/calculator/MultiplyServiceImpl.java | 30 + .../src/main/java/calculator/SubtractService.java | 28 + .../main/java/calculator/SubtractServiceImpl.java | 30 + .../src/main/resources/Calculator.composite | 49 ++ .../src/main/resources/wsdl/add.wsdl | 87 +++ .../src/main/webapp/META-INF/sca-contribution.xml | 24 + .../src/main/webapp/WEB-INF/faces-config.xml | 14 + .../src/main/webapp/WEB-INF/web.xml | 59 ++ .../calculator-jsf-webapp/src/main/webapp/calc.jsp | 50 ++ .../src/main/webapp/calc_jsf.jsp | 27 + .../sca-1.x/samples/expertise-atom/pom.xml | 96 +++ .../java/org/apache/tuscany/expertise/Expert.java | 67 +++ .../expertise/atom/AtomExpertiseLocator.java | 130 +++++ .../tuscany/expertise/atom/ExpertiseLocator.java | 29 + .../apache/tuscany/expertise/launch/Launch.java | 34 ++ .../main/resources/META-INF/sca-contribution.xml | 25 + .../src/main/resources/atom.composite | 36 ++ .../src/main/resources/atom.composite_diagram | 71 +++ .../src/main/resources/expertLocator.html | 110 ++++ .../sca-1.x/samples/expertise-restfull/pom.xml | 82 +++ .../java/org/apache/tuscany/expertise/Expert.java | 64 ++ .../apache/tuscany/expertise/launch/Launch.java | 34 ++ .../tuscany/expertise/restfull/ExpertRegistry.java | 37 ++ .../expertise/restfull/ExpertRegistryImpl.java | 92 +++ .../restfull/RestfulExpertiseLocator.java | 100 ++++ .../main/resources/META-INF/sca-contribution.xml | 25 + .../src/main/resources/rest.composite | 34 ++ .../src/main/resources/rest.composite_diagram | 71 +++ sandbox/lresende/sca-1.x/samples/pom.xml | 46 ++ .../sca-1.x/samples/store-distributed/README | 28 + .../sca-1.x/samples/store-distributed/build.xml | 79 +++ .../samples/store-distributed/cloud.composite | 27 + .../samples/store-distributed/domain.composite | 27 + .../sca-1.x/samples/store-distributed/pom.xml | 109 ++++ .../src/main/java/node/LaunchDomain.java | 33 ++ .../src/main/java/node/LaunchStoreNodeA.java | 28 + .../src/main/java/node/LaunchStoreNodeB.java | 28 + .../src/main/java/node/LaunchStoreNodeC.java | 28 + .../src/main/java/services/Cart.java | 28 + .../src/main/java/services/Catalog.java | 27 + .../src/main/java/services/CurrencyConverter.java | 29 + .../main/java/services/CurrencyConverterImpl.java | 38 ++ .../src/main/java/services/FruitsCatalogImpl.java | 52 ++ .../src/main/java/services/Item.java | 51 ++ .../src/main/java/services/ShoppingCartImpl.java | 112 ++++ .../src/main/java/services/Total.java | 29 + .../src/main/resources/cloud/NodeA.composite | 36 ++ .../src/main/resources/cloud/NodeB.composite | 36 ++ .../src/main/resources/cloud/NodeC.composite | 36 ++ .../resources/nodeA/META-INF/sca-contribution.xml | 24 + .../src/main/resources/nodeA/content/store.js | 510 ++++++++++++++++ .../src/main/resources/nodeA/store.composite | 46 ++ .../resources/nodeB/META-INF/sca-contribution.xml | 24 + .../src/main/resources/nodeB/content/store.js | 647 +++++++++++++++++++++ .../src/main/resources/nodeB/store.composite | 43 ++ .../resources/nodeC/META-INF/sca-contribution.xml | 24 + .../src/main/resources/nodeC/content/index.js | 66 +++ .../src/main/resources/nodeC/content/store.html | 114 ++++ .../src/main/resources/nodeC/content/store.js | 39 ++ .../src/main/resources/nodeC/store.composite | 50 ++ .../src/main/resources/nodeC/uiservices/store.html | 162 ++++++ .../src/main/resources/uiservices/store.html | 162 ++++++ .../sca-1.x/samples/store-distributed/store.png | Bin 0 -> 15670 bytes .../sca-1.x/samples/store-distributed/store.svg | 304 ++++++++++ .../samples/store-distributed/workspace.xml | 25 + sandbox/lresende/sca-1.x/samples/store-jsf/README | 2 + sandbox/lresende/sca-1.x/samples/store-jsf/pom.xml | 64 ++ .../store-jsf/src/main/java/beans/Catalog.java | 56 ++ .../store-jsf/src/main/java/beans/Product.java | 56 ++ .../src/main/webapp/WEB-INF/faces-config.xml | 31 + .../src/main/webapp/WEB-INF/lib/ajax4jsf-1.1.1.jar | Bin 0 -> 1262524 bytes .../store-jsf/src/main/webapp/WEB-INF/web.xml | 31 + .../samples/store-jsf/src/main/webapp/catalog.jsp | 82 +++ .../samples/store-secure-webapp/build-dojo.xml | 62 ++ .../sca-1.x/samples/store-secure-webapp/build.xml | 119 ++++ .../sca-1.x/samples/store-secure-webapp/pom.xml | 144 +++++ .../src/main/java/services/Catalog.java | 8 + .../src/main/java/services/CurrencyConverter.java | 12 + .../main/java/services/CurrencyConverterImpl.java | 21 + .../src/main/java/services/FruitsCatalogImpl.java | 35 ++ .../src/main/java/services/Item.java | 30 + .../java/store/security/StoreCallbackHandler.java | 50 ++ .../src/main/resources/definitions.xml | 73 +++ .../src/main/resources/store.composite | 41 ++ .../src/main/webapp/META-INF/sca-contribution.xml | 23 + .../src/main/webapp/WEB-INF/geronimo-web.xml | 73 +++ .../src/main/webapp/WEB-INF/web.xml | 60 ++ .../src/main/webapp/auth/logon.html | 20 + .../src/main/webapp/auth/logonError.html | 5 + .../store-secure-webapp/src/main/webapp/store.html | 48 ++ 104 files changed, 6891 insertions(+) create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/README create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/build.xml create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/calculator-web.png create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/calculator-web.svg create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/pom.xml create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/beans/Calculator.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/AddService.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/AddServiceImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorClient.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorServiceImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/DivideService.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/DivideServiceImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/MultiplyService.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/MultiplyServiceImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/SubtractService.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/SubtractServiceImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/resources/Calculator.composite create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/resources/wsdl/add.wsdl create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/META-INF/sca-contribution.xml create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/calc.jsp create mode 100644 sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/calc_jsf.jsp create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/pom.xml create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/Expert.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/atom/AtomExpertiseLocator.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/atom/ExpertiseLocator.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/launch/Launch.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/atom.composite create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/atom.composite_diagram create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/expertLocator.html create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/pom.xml create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/Expert.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/launch/Launch.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/ExpertRegistry.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/ExpertRegistryImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/RestfulExpertiseLocator.java create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/META-INF/sca-contribution.xml create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/rest.composite create mode 100644 sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/rest.composite_diagram create mode 100644 sandbox/lresende/sca-1.x/samples/pom.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/README create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/build.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/cloud.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/domain.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/pom.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchDomain.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeA.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeB.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeC.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Cart.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Catalog.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/CurrencyConverter.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/CurrencyConverterImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/FruitsCatalogImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Item.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/ShoppingCartImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Total.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeA.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeB.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeC.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/META-INF/sca-contribution.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/content/store.js create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/store.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/META-INF/sca-contribution.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/content/store.js create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/store.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/META-INF/sca-contribution.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/index.js create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/store.html create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/store.js create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/store.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/uiservices/store.html create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/uiservices/store.html create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/store.png create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/store.svg create mode 100644 sandbox/lresende/sca-1.x/samples/store-distributed/workspace.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-jsf/README create mode 100644 sandbox/lresende/sca-1.x/samples/store-jsf/pom.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-jsf/src/main/java/beans/Catalog.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-jsf/src/main/java/beans/Product.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/faces-config.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/lib/ajax4jsf-1.1.1.jar create mode 100644 sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/catalog.jsp create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/build-dojo.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/build.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/pom.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/Catalog.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/CurrencyConverter.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/CurrencyConverterImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/FruitsCatalogImpl.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/Item.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/store/security/StoreCallbackHandler.java create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/resources/definitions.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/resources/store.composite create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/META-INF/sca-contribution.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/WEB-INF/geronimo-web.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/auth/logon.html create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/auth/logonError.html create mode 100644 sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/store.html (limited to 'sandbox/lresende/sca-1.x/samples') diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/README b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/README new file mode 100644 index 0000000000..9f041f4ecb --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/README @@ -0,0 +1,118 @@ +Calculator Sample +================= +This sample uses the same code as the calculator sample but deploys the +sample wrapped in a web app. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +As this sample provides a web app there is a manual step where the WAR file +that contains the sample is copied to your web app container. If you just want +to give this sample a go deploy the WAR file (target/sample-calculator-webapp.war) +to you web application server. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost.localdomain:8080/sample-calculator-jsf-webapp/faces/calc_jsf.jsp + +The port and hostname will of course vary depending on your local installation. + +Sample Overview +--------------- +The sample provides a single calculator service with a default SCA (java) +binding. The CalculatorClient exercises this interface by calling add, +subtract, multiply and divide operations. This results in messages passing to +the appropriate components in the composite across the local wires. + +calculator-webapp/ + src/ + main/ + java/ + calculator/ + CalculatorService.java - As calculator sample + CalculatorServiceImpl.java + AddService.java - As calculator sample + AddServiceImpl.java + SubtractService.java - As calculator sample + SubtractServiceImpl.java + MultiplyService.java - As calculator sample + MultiplyServiceImpl.java + DivideService.java - As calculator sample + DivideServiceImpl.java + CalculatorClient.java - As calculator sample + resources/ + Calculator.composite - As calculator sample + webapp + META-INF/ + sca-contribution.xml - specifies the composite to be deployed + WEB-INF/ + web.xml - defines the listener that starts up the + Tuscany SCA runtime + calc.jsp - the web application that makes use of the + SCA application + test/ + java/ + calculator/ + CalculatorTestCase.java - JUnit test case + + calculator.png - a pictorial representation of the sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built using Ant as +follows + +cd calculator-webapp +ant package + +This should result in a war file (sample-calculator-webapp.war) in the target +directory. Copy this war file to your web app deployment directory in you +web app container. + +The process for getting the web app running will depend on which web app container +you are using. For example, if you are using Tomcat then it is simply a matter +of copying the WAR file to the webapps directory. + +Once the web app is deployed use your browser to visit the following URL; + +http://localhost:8080/sample-calculator-webapp/calc.jsp + +The port and hostname will of course vary depending on your local installation. + +You should see the following output. + +Expression Result +2 + 3 5.0 +3 - 2 1.0 +3 * 2 6.0 +3 / 2 1.5 + +Building And Running The Sample Using Maven +------------------------------------------- +With either the binary or source distributions the sample can be built and run +using Maven as follows. + +cd calculator-webapp +mvn + + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running calculator.CalculatorTestCase +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.852 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +Again this should result in a war file (sample-calculator-webapp.war) in the target +directory. Follow the steps described in the previous section for running the web +app and for the expected results. + + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/build.xml b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/build.xml new file mode 100644 index 0000000000..11b30c48d2 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/build.xml @@ -0,0 +1,137 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/calculator-web.png b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/calculator-web.png new file mode 100644 index 0000000000..896ddc4093 Binary files /dev/null and b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/calculator-web.png differ diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/calculator-web.svg b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/calculator-web.svg new file mode 100644 index 0000000000..00ed27556f --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/calculator-web.svg @@ -0,0 +1,358 @@ + + + + + + + + + + image/svg+xml + + + + + + + + Calculator + + CalculatorServiceComponent + + + CalculatorService + AddServiceComponent + + SubtractServiceComponent + + MultiplyServiceComponent + + DivideServiceComponent + addService + subtractService + multiplyService + divideService + + + + + + WebApp + + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/pom.xml b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/pom.xml new file mode 100644 index 0000000000..0354a8265a --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/pom.xml @@ -0,0 +1,77 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.7-SNAPSHOT + + sample-calculator-jsf-webapp + war + Apache Tuscany SCA Calculator Sample using JSF in a WebApp + + + + org.apache.myfaces.core + myfaces-impl + 1.1.5 + + + + org.apache.myfaces.core + myfaces-api + 1.1.5 + + + + org.apache.tuscany.sca + tuscany-host-webapp + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.7-SNAPSHOT + runtime + + + + + javax.servlet + servlet-api + 2.3 + provided + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/beans/Calculator.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/beans/Calculator.java new file mode 100644 index 0000000000..f8ca02f8db --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/beans/Calculator.java @@ -0,0 +1,78 @@ +package beans; + +import javax.faces.context.FacesContext; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import calculator.CalculatorService; + +public class Calculator { + CalculatorService calculatorService; + Double number1 = 2.0; + Double number2 = 3.0; + Double result; + String operation; + + public Double getNumber1() { + return number1; + } + + public void setNumber1(Double number1) { + this.number1 = number1; + } + + public Double getNumber2() { + return number2; + } + + public void setNumber2(Double number2) { + this.number2 = number2; + } + + public String getOperation() { + return operation; + } + + public void setOperation(String operation) { + this.operation = operation; + } + + public Calculator() { + SCADomain scaDomain = (SCADomain) FacesContext.getCurrentInstance().getExternalContext().getApplicationMap().get("org.apache.tuscany.sca.SCADomain"); + System.out.println("scaDomain: " + scaDomain); +// SCADomain scaDomain = (SCADomain) application.getAttribute("org.apache.tuscany.sca.SCADomain"); + if(scaDomain != null) { + calculatorService = (CalculatorService)scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + } + } + + public String callService() { + if(operation == null || calculatorService == null) { + result = 0.0; + } + else if(operation.equals("+")) { + result = calculatorService.add(number1, number2); + } + else if(operation.equals("-")) { + result = calculatorService.subtract(number1, number2); + } + else if(operation.equals("*")) { + result = calculatorService.multiply(number1, number2); + } + else if(operation.equals("/")) { + result = calculatorService.divide(number1, number2); + } + else { + result = 0.0; + } + return null; + } + + public Double getResult() { + return result; + } + + public void setResult(Double result) { + this.result = result; + } +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/AddService.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/AddService.java new file mode 100644 index 0000000000..a235e648c7 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/AddService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the add service + */ +public interface AddService { + + double add(double n1, double n2); + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/AddServiceImpl.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/AddServiceImpl.java new file mode 100644 index 0000000000..8b6fe066a6 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/AddServiceImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * An implementation of the Add service + */ +public class AddServiceImpl implements AddService { + + public double add(double n1, double n2) { + return n1 + n2; + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorClient.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorClient.java new file mode 100644 index 0000000000..ac76137fcb --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorClient.java @@ -0,0 +1,47 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package calculator; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + * + * (not really necessary as this sample runs in a webapp) + */ +public class CalculatorClient { + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("Calculator.composite"); + CalculatorService calculatorService = + scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // Calculate + System.out.println("3 + 2=" + calculatorService.add(3, 2)); + System.out.println("3 - 2=" + calculatorService.subtract(3, 2)); + System.out.println("3 * 2=" + calculatorService.multiply(3, 2)); + System.out.println("3 / 2=" + calculatorService.divide(3, 2)); + + scaDomain.close(); + + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorService.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..031fa8b912 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorService.java @@ -0,0 +1,35 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + + +/** + * The Calculator service interface. + */ +public interface CalculatorService { + + double add(double n1, double n2); + + double subtract(double n1, double n2); + + double multiply(double n1, double n2); + + double divide(double n1, double n2); + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorServiceImpl.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorServiceImpl.java new file mode 100644 index 0000000000..ba897fa301 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/CalculatorServiceImpl.java @@ -0,0 +1,69 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +import org.osoa.sca.annotations.Reference; + +/** + * An implementation of the Calculator service. + */ +public class CalculatorServiceImpl implements CalculatorService { + + private AddService addService; + private SubtractService subtractService; + private MultiplyService multiplyService; + private DivideService divideService; + + @Reference + public void setAddService(AddService addService) { + this.addService = addService; + } + + @Reference + public void setSubtractService(SubtractService subtractService) { + this.subtractService = subtractService; + } + + @Reference + public void setDivideService(DivideService divideService) { + this.divideService = divideService; + } + + @Reference + public void setMultiplyService(MultiplyService multiplyService) { + this.multiplyService = multiplyService; + } + + public double add(double n1, double n2) { + return addService.add(n1, n2); + } + + public double subtract(double n1, double n2) { + return subtractService.subtract(n1, n2); + } + + public double multiply(double n1, double n2) { + return multiplyService.multiply(n1, n2); + } + + public double divide(double n1, double n2) { + return divideService.divide(n1, n2); + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/DivideService.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/DivideService.java new file mode 100644 index 0000000000..497dafd4fd --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/DivideService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the divide service + */ +public interface DivideService { + + double divide(double n1, double n2); + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/DivideServiceImpl.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/DivideServiceImpl.java new file mode 100644 index 0000000000..f7ac0b7287 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/DivideServiceImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * An implementation of the Divide service. + */ +public class DivideServiceImpl implements DivideService { + + public double divide(double n1, double n2) { + return n1 / n2; + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/MultiplyService.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/MultiplyService.java new file mode 100644 index 0000000000..5290605938 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/MultiplyService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the multiply service + */ +public interface MultiplyService { + + double multiply(double n1, double n2); + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/MultiplyServiceImpl.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/MultiplyServiceImpl.java new file mode 100644 index 0000000000..b7dca792b2 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/MultiplyServiceImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * An implementation of the Multiply service. + */ +public class MultiplyServiceImpl implements MultiplyService { + + public double multiply(double n1, double n2) { + return n1 * n2; + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/SubtractService.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/SubtractService.java new file mode 100644 index 0000000000..376b3e5bb9 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/SubtractService.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * The interface for the subtract service + */ +public interface SubtractService { + + double subtract(double n1, double n2); + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/SubtractServiceImpl.java b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/SubtractServiceImpl.java new file mode 100644 index 0000000000..77b128ab8d --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/java/calculator/SubtractServiceImpl.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package calculator; + +/** + * An implementation of the subtract service. + */ +public class SubtractServiceImpl implements SubtractService { + + public double subtract(double n1, double n2) { + return n1 - n2; + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/resources/Calculator.composite b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/resources/Calculator.composite new file mode 100644 index 0000000000..ac9d010b48 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/resources/Calculator.composite @@ -0,0 +1,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/resources/wsdl/add.wsdl b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/resources/wsdl/add.wsdl new file mode 100644 index 0000000000..ae1986c588 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/resources/wsdl/add.wsdl @@ -0,0 +1,87 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/META-INF/sca-contribution.xml b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..3ce1f21836 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/WEB-INF/faces-config.xml b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000000..4670164d90 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,14 @@ + + + + + + + calculator + beans.Calculator + session + + + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/WEB-INF/web.xml b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..329e0a5bad --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,59 @@ + + + + + + + Apache Tuscany Calculator Web Service Sample + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + + org.apache.myfaces.webapp.StartupServletContextListener + + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + Faces Servlet + *.faces + + + + calc.jsp + + + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/calc.jsp b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/calc.jsp new file mode 100644 index 0000000000..4c4366747d --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/calc.jsp @@ -0,0 +1,50 @@ +<%-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--%> + +<%@ page import="org.apache.tuscany.sca.host.embedded.SCADomain"%> +<%@ page import="calculator.CalculatorService" %> + +<%@ page contentType="text/html;charset=UTF-8" language="java" %> +<% + SCADomain scaDomain = (SCADomain) application.getAttribute("org.apache.tuscany.sca.SCADomain"); + CalculatorService calculatorService = (CalculatorService)scaDomain.getService(CalculatorService.class, "CalculatorServiceComponent"); +%> + +Calculator sample + + + + + + + + + + + + + + + + + + +
ExpressionResult
2 + 3<%= calculatorService.add(2, 3) %>
3 - 2<%= calculatorService.subtract(3, 2) %>
3 * 2<%= calculatorService.multiply(3, 2) %>
3 / 2<%= calculatorService.divide(3, 2) %>
+ + diff --git a/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/calc_jsf.jsp b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/calc_jsf.jsp new file mode 100644 index 0000000000..37985724d0 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/calculator-jsf-webapp/src/main/webapp/calc_jsf.jsp @@ -0,0 +1,27 @@ +<%@taglib uri="http://java.sun.com/jsf/core" prefix="f"%><%@taglib + uri="http://java.sun.com/jsf/html" prefix="h"%><%@ page language="java" + contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> + + + + +Insert title here + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/pom.xml b/sandbox/lresende/sca-1.x/samples/expertise-atom/pom.xml new file mode 100644 index 0000000000..54840dca7e --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/pom.xml @@ -0,0 +1,96 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.7-SNAPSHOT + + sample-expertise-atom + Apache Tuscany SCA ATOM Expertise Locator + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-widget-runtime-tuscany + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-atom-abdera + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-atom-js + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-http-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-tomcat + 1.7-SNAPSHOT + runtime + + + + + ${artifactId} + + + diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/Expert.java b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/Expert.java new file mode 100644 index 0000000000..5bc3325a18 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/Expert.java @@ -0,0 +1,67 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.expertise; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.expertise.Expert; + +public class Expert implements Serializable { + private static final long serialVersionUID = 2026687637313310397L; + + private String id; + private String name; + private String location; + private List expertises = new ArrayList(); + + public Expert() { + + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public List getExpertise() { + return this.expertises; + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/atom/AtomExpertiseLocator.java b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/atom/AtomExpertiseLocator.java new file mode 100644 index 0000000000..a2fde8f938 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/atom/AtomExpertiseLocator.java @@ -0,0 +1,130 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.expertise.atom; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +import org.apache.tuscany.expertise.Expert; +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class AtomExpertiseLocator implements ExpertiseLocator { + + private Map experts = new HashMap(); + + @Init + public void init() { + Expert expert; + + expert = new Expert(); + expert.setId("1"); + expert.setName("John Smith"); + expert.setLocation("CA"); + expert.getExpertise().add("SOA"); + expert.getExpertise().add("SCA"); + expert.getExpertise().add("WAS"); + + experts.put(expert.getId(), expert); + + expert = new Expert(); + expert.setId("2"); + expert.setName("Ken Johnson"); + expert.setLocation("NY"); + expert.getExpertise().add("Search"); + + experts.put(expert.getId(), expert); + + expert = new Expert(); + expert.setId("3"); + expert.setName("Mark Smith"); + expert.setLocation("CA"); + expert.getExpertise().add("SCA"); + expert.getExpertise().add("WASCE"); + + experts.put(expert.getId(), expert); + } + + + public Entry[] getAll() { + Entry[] entries = new Entry[experts.size()]; + int i = 0; + for (Map.Entry e: experts.entrySet()) { + entries[i++] = new Entry(e.getKey(), e.getValue()); + } + return entries; + + } + + public Expert get(String key) throws NotFoundException { + Expert item = experts.get(key); + if (item == null) { + throw new NotFoundException(key); + } else { + return item; + } + } + + public String post(String key, Expert item) { + if (key == null) { + int size = experts.entrySet().size() + 1; + key = Integer.toString(size); + item.setId(key); + } + experts.put(key, item); + return key; + } + + public void put(String key, Expert item) throws NotFoundException { + if (!experts.containsKey(key)) { + throw new NotFoundException(key); + } + experts.put(key, item); + } + + public void delete(String key) throws NotFoundException { + if (key == null || key.equals("")) { + experts.clear(); + } else { + Expert expert = experts.remove(key); + if (expert == null) + throw new NotFoundException(key); + } + } + + public Entry[] query(String queryString) { + List> entries = new ArrayList>(); + if (queryString.startsWith("location=")) { + String location = queryString.substring(9); + for (Map.Entry e: experts.entrySet()) { + Expert expert = e.getValue(); + if (expert.getLocation().equals(location)) { + entries.add(new Entry(e.getKey(), e.getValue())); + } + } + } + return entries.toArray(new Entry[entries.size()]); + } +} diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/atom/ExpertiseLocator.java b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/atom/ExpertiseLocator.java new file mode 100644 index 0000000000..84683528cc --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/atom/ExpertiseLocator.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.expertise.atom; + +import org.apache.tuscany.expertise.Expert; +import org.apache.tuscany.sca.data.collection.Collection; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface ExpertiseLocator extends Collection { + +} diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/launch/Launch.java b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/launch/Launch.java new file mode 100644 index 0000000000..eb82100092 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/java/org/apache/tuscany/expertise/launch/Launch.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.expertise.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("atom.composite"); + System.out.println("atom.composite ready for big business !!!"); + System.in.read(); + System.out.println("Stopping ..."); + scaDomain.close(); + System.out.println(); + } +} diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/META-INF/sca-contribution.xml b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..c1e9be425c --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,25 @@ + + + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/atom.composite b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/atom.composite new file mode 100644 index 0000000000..75d04f1fe4 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/atom.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/atom.composite_diagram b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/atom.composite_diagram new file mode 100644 index 0000000000..50c1ccf578 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/atom.composite_diagram @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/expertLocator.html b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/expertLocator.html new file mode 100644 index 0000000000..22579cb0ce --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-atom/src/main/resources/expertLocator.html @@ -0,0 +1,110 @@ + + + +Expert Locator + + + + + + + + +

Expertise Locator

+
+

Add new Expert

+
+ Name
+
+ Location
+
+ Expertise
+ separate multiple values with commas (,)
+
+ +
+
+ +
+

Experts

+
+
+
+
+
+ + + diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/pom.xml b/sandbox/lresende/sca-1.x/samples/expertise-restfull/pom.xml new file mode 100644 index 0000000000..8d5459be84 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/pom.xml @@ -0,0 +1,82 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.7-SNAPSHOT + + sample-expertise-restfull + Apache Tuscany SCA RESTFull Expertise Locator + + + + org.apache.tuscany.sca + tuscany-sca-api + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-http-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-tomcat + 1.7-SNAPSHOT + runtime + + + + javax.servlet + servlet-api + 2.5 + provided + + + + + ${artifactId} + + + diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/Expert.java b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/Expert.java new file mode 100644 index 0000000000..61ac1c12b7 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/Expert.java @@ -0,0 +1,64 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.tuscany.expertise; + +import java.io.Serializable; +import java.util.ArrayList; +import java.util.List; + +public class Expert implements Serializable { + private static final long serialVersionUID = 2026687637313310397L; + + private String id; + private String name; + private String location; + private List expertises = new ArrayList(); + + public Expert() { + + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getLocation() { + return location; + } + + public void setLocation(String location) { + this.location = location; + } + + public List getExpertise() { + return this.expertises; + } +} diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/launch/Launch.java b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/launch/Launch.java new file mode 100644 index 0000000000..306abd5465 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/launch/Launch.java @@ -0,0 +1,34 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.expertise.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("rest.composite"); + System.out.println("rest.composite ready for big business !!!"); + System.in.read(); + System.out.println("Stopping ..."); + scaDomain.close(); + System.out.println(); + } +} diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/ExpertRegistry.java b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/ExpertRegistry.java new file mode 100644 index 0000000000..1b90df36d2 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/ExpertRegistry.java @@ -0,0 +1,37 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.expertise.restfull; + +import java.util.List; + +import org.apache.tuscany.expertise.Expert; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface ExpertRegistry { + + void addExpert(Expert expert); + + void removeExpert(Expert expert); + + List getExperts(); + + List getExpertsByExpertise(String expertise); +} \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/ExpertRegistryImpl.java b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/ExpertRegistryImpl.java new file mode 100644 index 0000000000..bf7b2ea03e --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/ExpertRegistryImpl.java @@ -0,0 +1,92 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.expertise.restfull; + +import java.util.ArrayList; +import java.util.List; + +import org.apache.tuscany.expertise.Expert; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Service; + +@Service(ExpertRegistry.class) +public class ExpertRegistryImpl implements ExpertRegistry { + private List experts = new ArrayList(); + + public ExpertRegistryImpl() { + + } + + @Init + public void init() { + Expert expert; + + expert = new Expert(); + expert.setId("1"); + expert.setName("John Smith"); + expert.setLocation("CA"); + expert.getExpertise().add("SOA"); + expert.getExpertise().add("SCA"); + expert.getExpertise().add("WAS"); + + experts.add(expert); + + expert = new Expert(); + expert.setId("2"); + expert.setName("Ken Johnson"); + expert.setLocation("NY"); + expert.getExpertise().add("Search"); + + experts.add(expert); + + expert = new Expert(); + expert.setId("3"); + expert.setName("Mark Smith"); + expert.setLocation("CA"); + expert.getExpertise().add("SCA"); + expert.getExpertise().add("WASCE"); + + experts.add(expert); + } + + public void addExpert(Expert expert) { + experts.add(expert); + } + + public void removeExpert(Expert expert) { + experts.remove(expert); + } + + public List getExperts() { + return experts; + } + + public List getExpertsByExpertise(String expertise) { + List expertsByExpertise = new ArrayList(); + + for (Expert expert : experts) { + if (expert.getExpertise().contains(expertise)) { + expertsByExpertise.add(expert); + } + } + + return expertsByExpertise; + } +} diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/RestfulExpertiseLocator.java b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/RestfulExpertiseLocator.java new file mode 100644 index 0000000000..ea3915ccb5 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/java/org/apache/tuscany/expertise/restfull/RestfulExpertiseLocator.java @@ -0,0 +1,100 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.tuscany.expertise.restfull; + +import java.io.IOException; +import java.net.URLDecoder; +import java.util.List; + +import javax.servlet.Servlet; +import javax.servlet.ServletException; +import javax.servlet.ServletOutputStream; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.expertise.Expert; +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(Servlet.class) +@Scope("COMPOSITE") +public class RestfulExpertiseLocator extends HttpServlet implements Servlet { + + private static final long serialVersionUID = 4021701701436888369L; + + @Reference + protected ExpertRegistry experts; + + + @Override + protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + String path = URLDecoder.decode(getRequestPath(request), "UTF-8"); + String expertise = path.substring(1); + + if (expertise != null && expertise.length() > 0 ) { + printExperts(response.getOutputStream(), experts.getExpertsByExpertise(expertise)); + } else { + printExperts(response.getOutputStream(), experts.getExperts()); + } + + } + + + private void printExperts(ServletOutputStream out, List experts) throws IOException { + out.print(""); + out.print("

Expertise Locator

"); + + if (experts.size() > 0) { + for (Expert expert: experts) { + out.print("Location: " + expert.getLocation() + " - " + expert.getName() +" ==> "); + for (String expertise : expert.getExpertise()) { + out.print(expertise + ";"); + } + out.print("
"); + } + } else { + out.println("No experts found"); + } + out.print(""); + } + + /** + * + * @param request + * @return + */ + private static String getRequestPath(HttpServletRequest request) { + // Get the request path + String contextPath = request.getContextPath(); + String servletPath = request.getServletPath(); + String requestURI = request.getRequestURI(); + + int contextPathLength = request.getContextPath().length(); + int servletPathLenght = servletPath.contains(contextPath) ? servletPath.length() - contextPath.length() : servletPath.length(); + + String requestPath = requestURI.substring(contextPathLength + servletPathLenght); + + return requestPath; + } + + +} diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/META-INF/sca-contribution.xml b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..96d2cc3c66 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/META-INF/sca-contribution.xml @@ -0,0 +1,25 @@ + + + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/rest.composite b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/rest.composite new file mode 100644 index 0000000000..50f19a7c79 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/rest.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/rest.composite_diagram b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/rest.composite_diagram new file mode 100644 index 0000000000..05dae0d547 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/expertise-restfull/src/main/resources/rest.composite_diagram @@ -0,0 +1,71 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/pom.xml b/sandbox/lresende/sca-1.x/samples/pom.xml new file mode 100644 index 0000000000..e481abc47a --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/pom.xml @@ -0,0 +1,46 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.7-SNAPSHOT + + tuscany-samples-lresende + pom + Apache Tuscany Samples (lresende sandbox) + + + + default + + true + + + expertise-atom + expertise-restfull + store-secure-webapp + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/README b/sandbox/lresende/sca-1.x/samples/store-distributed/README new file mode 100644 index 0000000000..d4797618ff --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/README @@ -0,0 +1,28 @@ +Store Sample +====================================== + +This is a sample store scenario that is used as a getting started guide +for Tuscany SCA. For detailed information, please see: + +http://incubator.apache.org/tuscany/getting-started-with-tuscany.html + +or + +http://incubator.apache.org/tuscany/getting-started-with-tuscany-using-tuscany-eclipse-plugin.html + + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built using Ant as follows: + +cd store +ant compile + +and then, to run: + +ant run + +Once the store application is running use your browser to visit the following +URL: + +http://localhost:8080/store/ diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/build.xml b/sandbox/lresende/sca-1.x/samples/store-distributed/build.xml new file mode 100644 index 0000000000..652afc3570 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/build.xml @@ -0,0 +1,79 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/cloud.composite b/sandbox/lresende/sca-1.x/samples/store-distributed/cloud.composite new file mode 100644 index 0000000000..7bd13d5b6f --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/cloud.composite @@ -0,0 +1,27 @@ + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/domain.composite b/sandbox/lresende/sca-1.x/samples/store-distributed/domain.composite new file mode 100644 index 0000000000..6898c454af --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/domain.composite @@ -0,0 +1,27 @@ + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/pom.xml b/sandbox/lresende/sca-1.x/samples/store-distributed/pom.xml new file mode 100644 index 0000000000..bb24b6cedd --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/pom.xml @@ -0,0 +1,109 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.7-SNAPSHOT + + sample-store-distributed + Apache Tuscany SCA Getting Started Online Store Sample + + + + org.apache.tuscany.sca + tuscany-node2-api + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-node2-launcher + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-domain-manager + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-data-api + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-implementation-widget-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-atom-abdera + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-http-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-tomcat + 1.7-SNAPSHOT + runtime + + + + junit + junit + 4.2 + test + + + + + ${artifactId} + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchDomain.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchDomain.java new file mode 100644 index 0000000000..dd19f6b49b --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchDomain.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package node; + +import org.apache.tuscany.sca.node.launcher.DomainManagerLauncher; + +/** + * This server program that loads a composite to provide simple registry function. + * This server can be replaced with any registry that is appropriate but the components + * in each node that talk to the registry should be replaced also. + */ +public class LaunchDomain { + public static void main(String[] args) throws Exception { + DomainManagerLauncher.main(args); + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeA.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeA.java new file mode 100644 index 0000000000..9016e515fb --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeA.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package node; + +import org.apache.tuscany.sca.node.launcher.NodeLauncher; + +public class LaunchStoreNodeA { + public static void main(String[] args) throws Exception { + NodeLauncher.main(new String[] {"http://localhost:9990/node-config/NodeA"}); + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeB.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeB.java new file mode 100644 index 0000000000..2b387aec82 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeB.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package node; + +import org.apache.tuscany.sca.node.launcher.NodeLauncher; + +public class LaunchStoreNodeB { + public static void main(String[] args) throws Exception { + NodeLauncher.main(new String[] {"http://localhost:9990/node-config/NodeB"}); + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeC.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeC.java new file mode 100644 index 0000000000..fb138e484f --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/node/LaunchStoreNodeC.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package node; + +import org.apache.tuscany.sca.node.launcher.NodeLauncher; + +public class LaunchStoreNodeC { + public static void main(String[] args) throws Exception { + NodeLauncher.main(new String[] {"http://localhost:9990/node-config/NodeC"}); + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Cart.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Cart.java new file mode 100644 index 0000000000..9e6226d963 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Cart.java @@ -0,0 +1,28 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services; + +import org.apache.tuscany.sca.data.collection.Collection; +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Cart extends Collection { + +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Catalog.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Catalog.java new file mode 100644 index 0000000000..2c3b19f579 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Catalog.java @@ -0,0 +1,27 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Catalog { + Item[] get(); +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/CurrencyConverter.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/CurrencyConverter.java new file mode 100644 index 0000000000..e104a0423a --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/CurrencyConverter.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface CurrencyConverter { + public double getConversion(String fromCurrenycCode, String toCurrencyCode, double amount); + + public String getCurrencySymbol(String currencyCode); +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/CurrencyConverterImpl.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/CurrencyConverterImpl.java new file mode 100644 index 0000000000..c354aed447 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/CurrencyConverterImpl.java @@ -0,0 +1,38 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services; + +public class CurrencyConverterImpl implements CurrencyConverter { + public double getConversion(String fromCurrencyCode, String toCurrencyCode, double amount) { + if (toCurrencyCode.equals("USD")) + return amount; + else if (toCurrencyCode.equals("EUR")) + return ((double)Math.round(amount * 0.7256 * 100)) /100; + return 0; + } + + public String getCurrencySymbol(String currencyCode) { + if (currencyCode.equals("USD")) + return "$"; + else if (currencyCode.equals("EUR")) + return "E"; //"€"; + return "?"; + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/FruitsCatalogImpl.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/FruitsCatalogImpl.java new file mode 100644 index 0000000000..377b3d7e59 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/FruitsCatalogImpl.java @@ -0,0 +1,52 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +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 FruitsCatalogImpl implements Catalog { + + @Property + public String currencyCode = "USD"; + + @Reference + public CurrencyConverter currencyConverter; + + private List catalog = new ArrayList(); + + @Init + public void init() { + String currencySymbol = currencyConverter.getCurrencySymbol(currencyCode); + catalog.add(new Item("Apple", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 2.99))); + catalog.add(new Item("Orange", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 3.55))); + catalog.add(new Item("Pear", currencySymbol + currencyConverter.getConversion("USD", currencyCode, 1.55))); + } + + public Item[] get() { + Item[] catalogArray = new Item[catalog.size()]; + catalog.toArray(catalogArray); + return catalogArray; + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Item.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Item.java new file mode 100644 index 0000000000..27abd4f016 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Item.java @@ -0,0 +1,51 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services; + + +public class Item { + private String name; + private String price; + + public Item() { + } + + public Item(String name, String price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/ShoppingCartImpl.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/ShoppingCartImpl.java new file mode 100644 index 0000000000..9889921a96 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/ShoppingCartImpl.java @@ -0,0 +1,112 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.UUID; + +import org.apache.tuscany.sca.data.collection.Entry; +import org.apache.tuscany.sca.data.collection.NotFoundException; +import org.osoa.sca.annotations.Init; +import org.osoa.sca.annotations.Scope; + +@Scope("COMPOSITE") +public class ShoppingCartImpl implements Cart, Total { + + private Map cart; + + @Init + public void init() { + cart = new HashMap(); + } + + public Entry[] getAll() { + Entry[] entries = new Entry[cart.size()]; + int i = 0; + for (Map.Entry e: cart.entrySet()) { + entries[i++] = new Entry(e.getKey(), e.getValue()); + } + return entries; + } + + public Item get(String key) throws NotFoundException { + Item item = cart.get(key); + if (item == null) { + throw new NotFoundException(key); + } else { + return item; + } + } + + public String post(String key, Item item) { + if (key == null) { + key ="cart-" + UUID.randomUUID().toString(); + } + cart.put(key, item); + return key; + } + + public void put(String key, Item item) throws NotFoundException { + if (!cart.containsKey(key)) { + throw new NotFoundException(key); + } + cart.put(key, item); + } + + public void delete(String key) throws NotFoundException { + if (key == null || key.equals("")) { + cart.clear(); + } else { + Item item = cart.remove(key); + if (item == null) + throw new NotFoundException(key); + } + } + + public Entry[] query(String queryString) { + List> entries = new ArrayList>(); + if (queryString.startsWith("name=")) { + String name = queryString.substring(5); + for (Map.Entry e: cart.entrySet()) { + Item item = e.getValue(); + if (item.getName().equals(name)) { + entries.add(new Entry(e.getKey(), e.getValue())); + } + } + } + return entries.toArray(new Entry[entries.size()]); + } + + public String getTotal() { + double total = 0; + String currencySymbol = ""; + if (!cart.isEmpty()) { + Item item = cart.values().iterator().next(); + currencySymbol = item.getPrice().substring(0, 1); + } + for (Item item : cart.values()) { + total += Double.valueOf(item.getPrice().substring(1)); + } + return currencySymbol + String.valueOf(total); + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Total.java b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Total.java new file mode 100644 index 0000000000..8f464e526f --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/java/services/Total.java @@ -0,0 +1,29 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Total { + + String getTotal(); + +} diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeA.composite b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeA.composite new file mode 100644 index 0000000000..f7bfd0fcb6 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeA.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeB.composite b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeB.composite new file mode 100644 index 0000000000..187c5caf1c --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeB.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeC.composite b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeC.composite new file mode 100644 index 0000000000..96c2e02acb --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/cloud/NodeC.composite @@ -0,0 +1,36 @@ + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/META-INF/sca-contribution.xml b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..f165ee0e29 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/content/store.js b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/content/store.js new file mode 100644 index 0000000000..7df50eef64 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/content/store.js @@ -0,0 +1,510 @@ +/* Apache Tuscany SCA Widget header */ + +/* + * JSON-RPC JavaScript client + * + * $Id: jsonrpc.js,v 1.36.2.3 2006/03/08 15:09:37 mclark Exp $ + * + * Copyright (c) 2003-2004 Jan-Klaas Kollhof + * Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd + * + * This code is based on Jan-Klaas' JavaScript o lait library (jsolait). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * Modifications for Apache Tuscany: + * - JSONRpcClient_createMethod changed so callback is last arg + */ + +/* escape a character */ + +alert('loading sotre.js from nodeA'); + +escapeJSONChar = +function escapeJSONChar(c) +{ + if(c == "\"" || c == "\\") return "\\" + c; + else if (c == "\b") return "\\b"; + else if (c == "\f") return "\\f"; + else if (c == "\n") return "\\n"; + else if (c == "\r") return "\\r"; + else if (c == "\t") return "\\t"; + var hex = c.charCodeAt(0).toString(16); + if(hex.length == 1) return "\\u000" + hex; + else if(hex.length == 2) return "\\u00" + hex; + else if(hex.length == 3) return "\\u0" + hex; + else return "\\u" + hex; +}; + + +/* encode a string into JSON format */ + +escapeJSONString = +function escapeJSONString(s) +{ + /* The following should suffice but Safari's regex is b0rken + (doesn't support callback substitutions) + return "\"" + s.replace(/([^\u0020-\u007f]|[\\\"])/g, + escapeJSONChar) + "\""; + */ + + /* Rather inefficient way to do it */ + var parts = s.split(""); + for(var i=0; i < parts.length; i++) { + var c =parts[i]; + if(c == '"' || + c == '\\' || + c.charCodeAt(0) < 32 || + c.charCodeAt(0) >= 128) + parts[i] = escapeJSONChar(parts[i]); + } + return "\"" + parts.join("") + "\""; +}; + + +/* Marshall objects to JSON format */ + +toJSON = function toJSON(o) +{ + if(o == null) { + return "null"; + } else if(o.constructor == String) { + return escapeJSONString(o); + } else if(o.constructor == Number) { + return o.toString(); + } else if(o.constructor == Boolean) { + return o.toString(); + } else if(o.constructor == Date) { + return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}'; + } else if(o.constructor == Array) { + var v = []; + for(var i = 0; i < o.length; i++) v.push(toJSON(o[i])); + return "[" + v.join(", ") + "]"; + } else { + var v = []; + for(attr in o) { + if(o[attr] == null) v.push("\"" + attr + "\": null"); + else if(typeof o[attr] == "function"); /* skip */ + else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr])); + } + return "{" + v.join(", ") + "}"; + } +}; + + +/* JSONRpcClient constructor */ + +JSONRpcClient = +function JSONRpcClient_ctor(serverURL, user, pass, objectID) +{ + this.serverURL = serverURL; + this.user = user; + this.pass = pass; + this.objectID = objectID; + + /* Add standard methods */ + if(this.objectID) { + this._addMethods(["listMethods"]); + var req = this._makeRequest("listMethods", []); + } else { + this._addMethods(["system.listMethods"]); + var req = this._makeRequest("system.listMethods", []); + } + var m = this._sendRequest(req); + this._addMethods(m); +}; + + +/* JSONRpcCLient.Exception */ + +JSONRpcClient.Exception = +function JSONRpcClient_Exception_ctor(code, message, javaStack) +{ + this.code = code; + var name; + if(javaStack) { + this.javaStack = javaStack; + var m = javaStack.match(/^([^:]*)/); + if(m) name = m[0]; + } + if(name) this.name = name; + else this.name = "JSONRpcClientException"; + this.message = message; +}; + +JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION = 490; +JSONRpcClient.Exception.CODE_ERR_CLIENT = 550; +JSONRpcClient.Exception.CODE_ERR_PARSE = 590; +JSONRpcClient.Exception.CODE_ERR_NOMETHOD = 591; +JSONRpcClient.Exception.CODE_ERR_UNMARSHALL = 592; +JSONRpcClient.Exception.CODE_ERR_MARSHALL = 593; + +JSONRpcClient.Exception.prototype = new Error(); + +JSONRpcClient.Exception.prototype.toString = +function JSONRpcClient_Exception_toString(code, msg) +{ + return this.name + ": " + this.message; +}; + + +/* Default top level exception handler */ + +JSONRpcClient.default_ex_handler = +function JSONRpcClient_default_ex_handler(e) { alert(e); }; + + +/* Client settable variables */ + +JSONRpcClient.toplevel_ex_handler = JSONRpcClient.default_ex_handler; +JSONRpcClient.profile_async = false; +JSONRpcClient.max_req_active = 1; +JSONRpcClient.requestId = 1; + + +/* JSONRpcClient implementation */ + +JSONRpcClient.prototype._createMethod = +function JSONRpcClient_createMethod(methodName) +{ + var fn=function() + { + var args = []; + var callback = null; + for(var i=0;i 0) { + var res = JSONRpcClient.async_responses.shift(); + if(res.canceled) continue; + if(res.profile) res.profile.dispatch = new Date(); + try { + res.cb(res.result, res.ex, res.profile); + } catch(e) { + JSONRpcClient.toplevel_ex_handler(e); + } + } + + while(JSONRpcClient.async_requests.length > 0 && + JSONRpcClient.num_req_active < JSONRpcClient.max_req_active) { + var req = JSONRpcClient.async_requests.shift(); + if(req.canceled) continue; + req.client._sendRequest.call(req.client, req); + } +}; + +JSONRpcClient.kick_async = +function JSONRpcClient_kick_async() +{ + if(JSONRpcClient.async_timeout == null) + JSONRpcClient.async_timeout = + setTimeout(JSONRpcClient._async_handler, 0); +}; + +JSONRpcClient.cancelRequest = +function JSONRpcClient_cancelRequest(requestId) +{ + /* If it is in flight then mark it as canceled in the inflight map + and the XMLHttpRequest callback will discard the reply. */ + if(JSONRpcClient.async_inflight[requestId]) { + JSONRpcClient.async_inflight[requestId].canceled = true; + return true; + } + + /* If its not in flight yet then we can just mark it as canceled in + the the request queue and it will get discarded before being sent. */ + for(var i in JSONRpcClient.async_requests) { + if(JSONRpcClient.async_requests[i].requestId == requestId) { + JSONRpcClient.async_requests[i].canceled = true; + return true; + } + } + + /* It may have returned from the network and be waiting for its callback + to be dispatched, so mark it as canceled in the response queue + and the response will get discarded before calling the callback. */ + for(var i in JSONRpcClient.async_responses) { + if(JSONRpcClient.async_responses[i].requestId == requestId) { + JSONRpcClient.async_responses[i].canceled = true; + return true; + } + } + + return false; +}; + +JSONRpcClient.prototype._makeRequest = +function JSONRpcClient_makeRequest(methodName, args, cb) +{ + var req = {}; + req.client = this; + req.requestId = JSONRpcClient.requestId++; + + var obj = {}; + obj.id = req.requestId; + if (this.objectID) + obj.method = ".obj#" + this.objectID + "." + methodName; + else + obj.method = methodName; + obj.params = args; + + if (cb) req.cb = cb; + if (JSONRpcClient.profile_async) + req.profile = { "submit": new Date() }; + req.data = toJSON(obj); + + return req; +}; + +JSONRpcClient.prototype._sendRequest = +function JSONRpcClient_sendRequest(req) +{ + if(req.profile) req.profile.start = new Date(); + + /* Get free http object from the pool */ + var http = JSONRpcClient.poolGetHTTPRequest(); + JSONRpcClient.num_req_active++; + + /* Send the request */ + if (typeof(this.user) == "undefined") { + http.open("POST", this.serverURL, (req.cb != null)); + } else { + http.open("POST", this.serverURL, (req.cb != null), this.user, this.pass); + } + + /* setRequestHeader is missing in Opera 8 Beta */ + try { http.setRequestHeader("Content-type", "text/plain"); } catch(e) {} + + /* Construct call back if we have one */ + if(req.cb) { + var self = this; + http.onreadystatechange = function() { + if(http.readyState == 4) { + http.onreadystatechange = function () {}; + var res = { "cb": req.cb, "result": null, "ex": null}; + if (req.profile) { + res.profile = req.profile; + res.profile.end = new Date(); + } + try { res.result = self._handleResponse(http); } + catch(e) { res.ex = e; } + if(!JSONRpcClient.async_inflight[req.requestId].canceled) + JSONRpcClient.async_responses.push(res); + delete JSONRpcClient.async_inflight[req.requestId]; + JSONRpcClient.kick_async(); + } + }; + } else { + http.onreadystatechange = function() {}; + } + + JSONRpcClient.async_inflight[req.requestId] = req; + + try { + http.send(req.data); + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + if(!req.cb) return this._handleResponse(http); +}; + +JSONRpcClient.prototype._handleResponse = +function JSONRpcClient_handleResponse(http) +{ + /* Get the charset */ + if(!this.charset) { + this.charset = JSONRpcClient._getCharsetFromHeaders(http); + } + + /* Get request results */ + var status, statusText, data; + try { + status = http.status; + statusText = http.statusText; + data = http.responseText; + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + JSONRpcClient.kick_async(); + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + /* Return http object to the pool; */ + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + + /* Unmarshall the response */ + if(status != 200) { + throw new JSONRpcClient.Exception(status, statusText); + } + var obj; + try { + eval("obj = " + data); + } catch(e) { + throw new JSONRpcClient.Exception(550, "error parsing result"); + } + if(obj.error) + throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg, + obj.error.trace); + var res = obj.result; + + /* Handle CallableProxy */ + if(res && res.objectID && res.JSONRPCType == "CallableReference") + return new JSONRpcClient(this.serverURL, this.user, + this.pass, res.objectID); + + return res; +}; + + +/* XMLHttpRequest wrapper code */ + +/* XMLHttpRequest pool globals */ +JSONRpcClient.http_spare = []; +JSONRpcClient.http_max_spare = 8; + +JSONRpcClient.poolGetHTTPRequest = +function JSONRpcClient_pool_getHTTPRequest() +{ + if(JSONRpcClient.http_spare.length > 0) { + return JSONRpcClient.http_spare.pop(); + } + return JSONRpcClient.getHTTPRequest(); +}; + +JSONRpcClient.poolReturnHTTPRequest = +function JSONRpcClient_poolReturnHTTPRequest(http) +{ + if(JSONRpcClient.http_spare.length >= JSONRpcClient.http_max_spare) + delete http; + else + JSONRpcClient.http_spare.push(http); +}; + +JSONRpcClient.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + +JSONRpcClient.getHTTPRequest = +function JSONRpcClient_getHTTPRequest() +{ + /* Mozilla XMLHttpRequest */ + try { + JSONRpcClient.httpObjectName = "XMLHttpRequest"; + return new XMLHttpRequest(); + } catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < JSONRpcClient.msxmlNames.length; i++) { + try { + JSONRpcClient.httpObjectName = JSONRpcClient.msxmlNames[i]; + return new ActiveXObject(JSONRpcClient.msxmlNames[i]); + } catch (e) {} + } + + /* None found */ + JSONRpcClient.httpObjectName = null; + throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object"); +}; + +//--------------------- + + +var propertyMapA = new Object(); +var referenceMapA = new Object(); + +alert("referenceMapA : " + referenceMapA); +referenceMapA.catalog = new JSONRpcClient("http://luck.ibm.com:8100/Catalog").Service; + +alert('finished loading store.js from nodeA'); + +/** End of Apache Tuscany SCA Widget */ + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/store.composite b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/store.composite new file mode 100644 index 0000000000..99d1fb5dd7 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeA/store.composite @@ -0,0 +1,46 @@ + + + + + + + USD + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/META-INF/sca-contribution.xml b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..0f8e76ccd7 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/content/store.js b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/content/store.js new file mode 100644 index 0000000000..c95a3b2f95 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/content/store.js @@ -0,0 +1,647 @@ +/* Apache Tuscany SCA Widget header */ + +/* + * JSON-RPC JavaScript client + * + * $Id: jsonrpc.js,v 1.36.2.3 2006/03/08 15:09:37 mclark Exp $ + * + * Copyright (c) 2003-2004 Jan-Klaas Kollhof + * Copyright (c) 2005 Michael Clark, Metaparadigm Pte Ltd + * + * This code is based on Jan-Klaas' JavaScript o lait library (jsolait). + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + * + */ + +/* + * Modifications for Apache Tuscany: + * - JSONRpcClient_createMethod changed so callback is last arg + */ + +/* escape a character */ + +alert('loading sotre.js from nodeB'); + +escapeJSONChar = +function escapeJSONChar(c) +{ + if(c == "\"" || c == "\\") return "\\" + c; + else if (c == "\b") return "\\b"; + else if (c == "\f") return "\\f"; + else if (c == "\n") return "\\n"; + else if (c == "\r") return "\\r"; + else if (c == "\t") return "\\t"; + var hex = c.charCodeAt(0).toString(16); + if(hex.length == 1) return "\\u000" + hex; + else if(hex.length == 2) return "\\u00" + hex; + else if(hex.length == 3) return "\\u0" + hex; + else return "\\u" + hex; +}; + + +/* encode a string into JSON format */ + +escapeJSONString = +function escapeJSONString(s) +{ + /* The following should suffice but Safari's regex is b0rken + (doesn't support callback substitutions) + return "\"" + s.replace(/([^\u0020-\u007f]|[\\\"])/g, + escapeJSONChar) + "\""; + */ + + /* Rather inefficient way to do it */ + var parts = s.split(""); + for(var i=0; i < parts.length; i++) { + var c =parts[i]; + if(c == '"' || + c == '\\' || + c.charCodeAt(0) < 32 || + c.charCodeAt(0) >= 128) + parts[i] = escapeJSONChar(parts[i]); + } + return "\"" + parts.join("") + "\""; +}; + + +/* Marshall objects to JSON format */ + +toJSON = function toJSON(o) +{ + if(o == null) { + return "null"; + } else if(o.constructor == String) { + return escapeJSONString(o); + } else if(o.constructor == Number) { + return o.toString(); + } else if(o.constructor == Boolean) { + return o.toString(); + } else if(o.constructor == Date) { + return '{javaClass: "java.util.Date", time: ' + o.valueOf() +'}'; + } else if(o.constructor == Array) { + var v = []; + for(var i = 0; i < o.length; i++) v.push(toJSON(o[i])); + return "[" + v.join(", ") + "]"; + } else { + var v = []; + for(attr in o) { + if(o[attr] == null) v.push("\"" + attr + "\": null"); + else if(typeof o[attr] == "function"); /* skip */ + else v.push(escapeJSONString(attr) + ": " + toJSON(o[attr])); + } + return "{" + v.join(", ") + "}"; + } +}; + + +/* JSONRpcClient constructor */ + +JSONRpcClient = +function JSONRpcClient_ctor(serverURL, user, pass, objectID) +{ + this.serverURL = serverURL; + this.user = user; + this.pass = pass; + this.objectID = objectID; + + /* Add standard methods */ + if(this.objectID) { + this._addMethods(["listMethods"]); + var req = this._makeRequest("listMethods", []); + } else { + this._addMethods(["system.listMethods"]); + var req = this._makeRequest("system.listMethods", []); + } + var m = this._sendRequest(req); + this._addMethods(m); +}; + + +/* JSONRpcCLient.Exception */ + +JSONRpcClient.Exception = +function JSONRpcClient_Exception_ctor(code, message, javaStack) +{ + this.code = code; + var name; + if(javaStack) { + this.javaStack = javaStack; + var m = javaStack.match(/^([^:]*)/); + if(m) name = m[0]; + } + if(name) this.name = name; + else this.name = "JSONRpcClientException"; + this.message = message; +}; + +JSONRpcClient.Exception.CODE_REMOTE_EXCEPTION = 490; +JSONRpcClient.Exception.CODE_ERR_CLIENT = 550; +JSONRpcClient.Exception.CODE_ERR_PARSE = 590; +JSONRpcClient.Exception.CODE_ERR_NOMETHOD = 591; +JSONRpcClient.Exception.CODE_ERR_UNMARSHALL = 592; +JSONRpcClient.Exception.CODE_ERR_MARSHALL = 593; + +JSONRpcClient.Exception.prototype = new Error(); + +JSONRpcClient.Exception.prototype.toString = +function JSONRpcClient_Exception_toString(code, msg) +{ + return this.name + ": " + this.message; +}; + + +/* Default top level exception handler */ + +JSONRpcClient.default_ex_handler = +function JSONRpcClient_default_ex_handler(e) { alert(e); }; + + +/* Client settable variables */ + +JSONRpcClient.toplevel_ex_handler = JSONRpcClient.default_ex_handler; +JSONRpcClient.profile_async = false; +JSONRpcClient.max_req_active = 1; +JSONRpcClient.requestId = 1; + + +/* JSONRpcClient implementation */ + +JSONRpcClient.prototype._createMethod = +function JSONRpcClient_createMethod(methodName) +{ + var fn=function() + { + var args = []; + var callback = null; + for(var i=0;i 0) { + var res = JSONRpcClient.async_responses.shift(); + if(res.canceled) continue; + if(res.profile) res.profile.dispatch = new Date(); + try { + res.cb(res.result, res.ex, res.profile); + } catch(e) { + JSONRpcClient.toplevel_ex_handler(e); + } + } + + while(JSONRpcClient.async_requests.length > 0 && + JSONRpcClient.num_req_active < JSONRpcClient.max_req_active) { + var req = JSONRpcClient.async_requests.shift(); + if(req.canceled) continue; + req.client._sendRequest.call(req.client, req); + } +}; + +JSONRpcClient.kick_async = +function JSONRpcClient_kick_async() +{ + if(JSONRpcClient.async_timeout == null) + JSONRpcClient.async_timeout = + setTimeout(JSONRpcClient._async_handler, 0); +}; + +JSONRpcClient.cancelRequest = +function JSONRpcClient_cancelRequest(requestId) +{ + /* If it is in flight then mark it as canceled in the inflight map + and the XMLHttpRequest callback will discard the reply. */ + if(JSONRpcClient.async_inflight[requestId]) { + JSONRpcClient.async_inflight[requestId].canceled = true; + return true; + } + + /* If its not in flight yet then we can just mark it as canceled in + the the request queue and it will get discarded before being sent. */ + for(var i in JSONRpcClient.async_requests) { + if(JSONRpcClient.async_requests[i].requestId == requestId) { + JSONRpcClient.async_requests[i].canceled = true; + return true; + } + } + + /* It may have returned from the network and be waiting for its callback + to be dispatched, so mark it as canceled in the response queue + and the response will get discarded before calling the callback. */ + for(var i in JSONRpcClient.async_responses) { + if(JSONRpcClient.async_responses[i].requestId == requestId) { + JSONRpcClient.async_responses[i].canceled = true; + return true; + } + } + + return false; +}; + +JSONRpcClient.prototype._makeRequest = +function JSONRpcClient_makeRequest(methodName, args, cb) +{ + var req = {}; + req.client = this; + req.requestId = JSONRpcClient.requestId++; + + var obj = {}; + obj.id = req.requestId; + if (this.objectID) + obj.method = ".obj#" + this.objectID + "." + methodName; + else + obj.method = methodName; + obj.params = args; + + if (cb) req.cb = cb; + if (JSONRpcClient.profile_async) + req.profile = { "submit": new Date() }; + req.data = toJSON(obj); + + return req; +}; + +JSONRpcClient.prototype._sendRequest = +function JSONRpcClient_sendRequest(req) +{ + if(req.profile) req.profile.start = new Date(); + + /* Get free http object from the pool */ + var http = JSONRpcClient.poolGetHTTPRequest(); + JSONRpcClient.num_req_active++; + + /* Send the request */ + if (typeof(this.user) == "undefined") { + http.open("POST", this.serverURL, (req.cb != null)); + } else { + http.open("POST", this.serverURL, (req.cb != null), this.user, this.pass); + } + + /* setRequestHeader is missing in Opera 8 Beta */ + try { http.setRequestHeader("Content-type", "text/plain"); } catch(e) {} + + /* Construct call back if we have one */ + if(req.cb) { + var self = this; + http.onreadystatechange = function() { + if(http.readyState == 4) { + http.onreadystatechange = function () {}; + var res = { "cb": req.cb, "result": null, "ex": null}; + if (req.profile) { + res.profile = req.profile; + res.profile.end = new Date(); + } + try { res.result = self._handleResponse(http); } + catch(e) { res.ex = e; } + if(!JSONRpcClient.async_inflight[req.requestId].canceled) + JSONRpcClient.async_responses.push(res); + delete JSONRpcClient.async_inflight[req.requestId]; + JSONRpcClient.kick_async(); + } + }; + } else { + http.onreadystatechange = function() {}; + } + + JSONRpcClient.async_inflight[req.requestId] = req; + + try { + http.send(req.data); + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + if(!req.cb) return this._handleResponse(http); +}; + +JSONRpcClient.prototype._handleResponse = +function JSONRpcClient_handleResponse(http) +{ + /* Get the charset */ + if(!this.charset) { + this.charset = JSONRpcClient._getCharsetFromHeaders(http); + } + + /* Get request results */ + var status, statusText, data; + try { + status = http.status; + statusText = http.statusText; + data = http.responseText; + } catch(e) { + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + JSONRpcClient.kick_async(); + throw new JSONRpcClient.Exception + (JSONRpcClient.Exception.CODE_ERR_CLIENT, "Connection failed"); + } + + /* Return http object to the pool; */ + JSONRpcClient.poolReturnHTTPRequest(http); + JSONRpcClient.num_req_active--; + + /* Unmarshall the response */ + if(status != 200) { + throw new JSONRpcClient.Exception(status, statusText); + } + var obj; + try { + eval("obj = " + data); + } catch(e) { + throw new JSONRpcClient.Exception(550, "error parsing result"); + } + if(obj.error) + throw new JSONRpcClient.Exception(obj.error.code, obj.error.msg, + obj.error.trace); + var res = obj.result; + + /* Handle CallableProxy */ + if(res && res.objectID && res.JSONRPCType == "CallableReference") + return new JSONRpcClient(this.serverURL, this.user, + this.pass, res.objectID); + + return res; +}; + + +/* XMLHttpRequest wrapper code */ + +/* XMLHttpRequest pool globals */ +JSONRpcClient.http_spare = []; +JSONRpcClient.http_max_spare = 8; + +JSONRpcClient.poolGetHTTPRequest = +function JSONRpcClient_pool_getHTTPRequest() +{ + if(JSONRpcClient.http_spare.length > 0) { + return JSONRpcClient.http_spare.pop(); + } + return JSONRpcClient.getHTTPRequest(); +}; + +JSONRpcClient.poolReturnHTTPRequest = +function JSONRpcClient_poolReturnHTTPRequest(http) +{ + if(JSONRpcClient.http_spare.length >= JSONRpcClient.http_max_spare) + delete http; + else + JSONRpcClient.http_spare.push(http); +}; + +JSONRpcClient.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + +JSONRpcClient.getHTTPRequest = +function JSONRpcClient_getHTTPRequest() +{ + /* Mozilla XMLHttpRequest */ + try { + JSONRpcClient.httpObjectName = "XMLHttpRequest"; + return new XMLHttpRequest(); + } catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < JSONRpcClient.msxmlNames.length; i++) { + try { + JSONRpcClient.httpObjectName = JSONRpcClient.msxmlNames[i]; + return new ActiveXObject(JSONRpcClient.msxmlNames[i]); + } catch (e) {} + } + + /* None found */ + JSONRpcClient.httpObjectName = null; + throw new JSONRpcClient.Exception(0, "Can't create XMLHttpRequest object"); +}; + + +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +function AtomClient(uri) { + + this.msxmlNames = [ "MSXML2.XMLHTTP.5.0", + "MSXML2.XMLHTTP.4.0", + "MSXML2.XMLHTTP.3.0", + "MSXML2.XMLHTTP", + "Microsoft.XMLHTTP" ]; + + this.uri=uri; + + this.get = function(id, responseFunction) { + var xhr = this.createXMLHttpRequest(); + xhr.onreadystatechange = function() { + if (xhr.readyState == 4) { + if (xhr.status == 200) { + var strDocument = xhr.responseText; + var xmlDocument = xhr.responseXML; + if(!xmlDocument || xmlDocument.childNodes.length==0){ + xmlDocument = (new DOMParser()).parseFromString(strDocument, "text/xml"); + } + if (responseFunction != null) responseFunction(xmlDocument); + } 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) { + var strDocument = xhr.responseText; + var xmlDocument = xhr.responseXML; + if(!xmlDocument || xmlDocument.childNodes.length==0){ + xmlDocument = (new DOMParser()).parseFromString(strDocument, "text/xml"); + } + if (responseFunction != null) responseFunction(xmlDocument); + } 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) { + var strDocument = xhr.responseText; + var xmlDocument = xhr.responseXML; + if(!xmlDocument || xmlDocument.childNodes.length==0){ + xmlDocument = (new DOMParser()).parseFromString(strDocument, "text/xml"); + } + if (responseFunction != null) responseFunction(xmlDocument); + } 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.del = 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 () { + /* Mozilla XMLHttpRequest */ + try {return new XMLHttpRequest();} catch(e) {} + + /* Microsoft MSXML ActiveX */ + for (var i=0;i < this.msxmlNames.length; i++) { + try {return new ActiveXObject(this.msxmlNames[i]);} catch (e) {} + } + alert("XML http request not supported"); + return null; + } + if (typeof DOMParser == "undefined") { + DOMParser = function () {} + + DOMParser.prototype.parseFromString = function (str, contentType) { + if (typeof ActiveXObject != "undefined") { + var d = new ActiveXObject("MSXML.DomDocument"); + d.loadXML(str); + return d; + } else if (typeof XMLHttpRequest != "undefined") { + var req = new XMLHttpRequest; + req.open("GET", "data:" + (contentType || "application/xml") + + ";charset=utf-8," + encodeURIComponent(str), false); + if (req.overrideMimeType) { + req.overrideMimeType(contentType); + } + req.send(null); + return req.responseXML; + } + } + } +} + + +alert(window.top); +alert(window.parent); +alert(window.top.document.referenceMap); +window.top.document.referenceMap.shoppingCart = new AtomClient("http://localhost:8200/ShoppingCart/Cart"); +window.top.document.referenceMap.shoppingTotal = new JSONRpcClient("http://localhost:8200/ShoppingCart/Total").Service; + +alert('finished loading store.js from nodeB'); + +/** End of Apache Tuscany SCA Widget */ + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/store.composite b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/store.composite new file mode 100644 index 0000000000..b66b937546 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeB/store.composite @@ -0,0 +1,43 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/META-INF/sca-contribution.xml b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..15bab17c1a --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/META-INF/sca-contribution.xml @@ -0,0 +1,24 @@ + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/index.js b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/index.js new file mode 100644 index 0000000000..d42dc5512d --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/index.js @@ -0,0 +1,66 @@ +/*-----------------------------------------------------------------------------+ +| Product: index.js - Ajile's default auto-loader for shared dependencies. +|+-----------------------------------------------------------------------------+ +| Author: Michael A. I. Lee [ http://ajile.iskitz.com/ ] +| +| Created: Friday, November 2, 2006 [2006.06.02 - 19:44:40 EDT] +| Modified: Saturday December 16, 2006 [2006.12.16 - 13:00:00 EST] +|+-----------------------------------------------------------------------------+ +| +| README: +| +| If you need a way to import/load a common set of scripts for every page on +| your site or in your web application, this is the file you should use. +| +| This index.js file can be used to define scripting dependencies for a page, +| site, or application in a single place for use in many places. +| +| As of Ajile 0.6.5, Ajile automatically loads the index.js file found in its +| directory. To disable this behavior, use the "mvcshareoff" load-time option +| in the src parameter of the script tag used to load Ajile. +| +| Placing your top-level Namespace, Import, and Load directives in this file +| allows Ajile to automatically load, import, and initialize all required +| modules at startup for every page that uses Ajile. +| +| By using this file as described, all scripting logic can be controlled from +| a single point separate from the page, site or application's display logic. +| +| When used within web pages (e.g. HTML, XHTML, HTA, JSP, ASP, PHP, CGI, etc.) +| only 1 SCRIPT tag is required. That SCRIPT tag must identify the location of +| the Ajile module. For example: +| +| +| +| Visit http://ajile.iskitz.com/ to start creating "Smart scripts that play nice!" +|+----------------------------------------------------------------------------*/ + +// You may copy this file into your own projects and use it to define your +// shared dependencies. This file must reside in the same location as the Ajile +// module. The logic below demonstrates how this file can be used to define an +// auto-loader. You'll most-likely use index.js to auto-load common or shared +// functionality. + +/* + + // Example options setting... + Ajile.EnableCloak(false); + Ajile.EnableDebug(); + Ajile.EnableOverride(false); + + // Define your namespace. + Namespace ("your.namespace"); + + // Import a versioned namespace. + Import ("some.namespace.*.0.6", "some/path/"); + + // Import a module's public members. + Import ("some.other.Module.*"); + + // Define a new module. + your.namespace.NewModule = new function() + { + // Your implementation here... + }; + +//*/ \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/store.html b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/store.html new file mode 100644 index 0000000000..0e3ab370b3 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/store.html @@ -0,0 +1,114 @@ + + + +Store + + + + + + + +

Store

+ + + +
+

Catalog

+
+
+
+ +
+ +
+ +

Your Shopping Cart

+
+
+
+
+
+ + + (feed) +
+
+ + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/store.js b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/store.js new file mode 100644 index 0000000000..088a80a1d1 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/nodeC/content/store.js @@ -0,0 +1,39 @@ + +function dhtmlLoadScript(url) { + var script = document.createElement('script'); + script.type = 'text/javascript'; + script.src = url; + document.getElementsByTagName('head')[0].appendChild(script); +} + +function dhtmlLoadScriptIFrame(iframeId, url) { + var iframe = document.createElement("IFRAME"); + iframe.style.display="none"; + iframe.name = iframeId; + iframe.id = iframeId; + iframe.src = url; + document.body.appendChild(iframe); + + //var iframeDocument = window.frames[iframeId].document; + //iframeDocument.write(' + + + + + + +

Store

+
+

Catalog

+
+
+
+ +
+ +
+ +

Your Shopping Cart

+
+
+
+
+
+ + + (feed) +
+
+ + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/uiservices/store.html b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/uiservices/store.html new file mode 100644 index 0000000000..45604463d1 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/src/main/resources/uiservices/store.html @@ -0,0 +1,162 @@ + + + +Store + + + + + + + + +

Store

+
+

Catalog

+
+
+
+ +
+ +
+ +

Your Shopping Cart

+
+
+
+
+
+ + + (feed) +
+
+ + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/store.png b/sandbox/lresende/sca-1.x/samples/store-distributed/store.png new file mode 100644 index 0000000000..da413edeee Binary files /dev/null and b/sandbox/lresende/sca-1.x/samples/store-distributed/store.png differ diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/store.svg b/sandbox/lresende/sca-1.x/samples/store-distributed/store.svg new file mode 100644 index 0000000000..74f8ecd36d --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/store.svg @@ -0,0 +1,304 @@ + + + + + + + + + + image/svg+xml + + + + + + + + store + ufs + + ShoppingCart + + CurrencyConverter + + + + + + + + + + CurrenyCode HTTP JSONRPC Atom + + Catalog + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-distributed/workspace.xml b/sandbox/lresende/sca-1.x/samples/store-distributed/workspace.xml new file mode 100644 index 0000000000..d6cb2bfc81 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-distributed/workspace.xml @@ -0,0 +1,25 @@ + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-jsf/README b/sandbox/lresende/sca-1.x/samples/store-jsf/README new file mode 100644 index 0000000000..79ddb03568 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-jsf/README @@ -0,0 +1,2 @@ +To access the deployed application : +http://localhost.localdomain:8080/sample-store-jsf/faces/catalog.jsp \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-jsf/pom.xml b/sandbox/lresende/sca-1.x/samples/store-jsf/pom.xml new file mode 100644 index 0000000000..fe68a0e4b5 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-jsf/pom.xml @@ -0,0 +1,64 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.7-SNAPSHOT + + sample-store-jsf + war + Apache Tuscany SCA Getting Started Online Store Sample using JSF + + + + + org.apache.myfaces.core + myfaces-impl + 1.1.5 + + + + org.apache.myfaces.core + myfaces-api + 1.1.5 + + + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/java/beans/Catalog.java b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/java/beans/Catalog.java new file mode 100644 index 0000000000..01e4a0d481 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/java/beans/Catalog.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package beans; + +import java.util.ArrayList; +import java.util.List; + +public class Catalog { + Product[] products; + + public Catalog() { + products = new Product[3]; + products[0] = new Product("Apple", 2.99); + products[1] = new Product("Orange", 3.55); + products[2] = new Product("Pear", 1.55); + } + + public Product[] getProducts() { + return products; + } + + public void setProducts(Product[] products) { + this.products = products; + } + + public List getProductsInCart() { + List productsInCart = new ArrayList(); + double total = 0.0; + for (int i = 0; i < products.length; i++) { + Product product = products[i]; + if (product.isInCart()) { + productsInCart.add(product); + total += product.getPrice(); + } + } + productsInCart.add(new Product("Total", total)); + return productsInCart; + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/java/beans/Product.java b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/java/beans/Product.java new file mode 100644 index 0000000000..9f3df2f95c --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/java/beans/Product.java @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package beans; + +public class Product { + String name; + double price; + boolean inCart; + + public Product(String name, double price) { + this.name = name; + this.price = price; + this.inCart = false; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } + + public boolean isInCart() { + return inCart; + } + + public void setInCart(boolean inCart) { + this.inCart = inCart; + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/faces-config.xml b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/faces-config.xml new file mode 100644 index 0000000000..1dd376a58f --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/faces-config.xml @@ -0,0 +1,31 @@ + + + + + + + catalog + beans.Catalog + session + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/lib/ajax4jsf-1.1.1.jar b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/lib/ajax4jsf-1.1.1.jar new file mode 100644 index 0000000000..347b0d2066 Binary files /dev/null and b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/lib/ajax4jsf-1.1.1.jar differ diff --git a/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/web.xml b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..a39a51eefc --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,31 @@ + + + + SkeletonProject + + ajax4jsf + Ajax4jsf Filter + org.ajax4jsf.Filter + + + ajax4jsf + Faces Servlet + + + Faces Servlet + javax.faces.webapp.FacesServlet + 1 + + + Faces Servlet + /faces/* + + + Faces Servlet + *.faces + + + + catalog.jsp + + diff --git a/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/catalog.jsp b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/catalog.jsp new file mode 100644 index 0000000000..d456bedcc0 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-jsf/src/main/webapp/catalog.jsp @@ -0,0 +1,82 @@ +<%-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--%> +<%@taglib uri="http://java.sun.com/jsf/html" prefix="h"%><%@taglib + uri="http://java.sun.com/jsf/core" prefix="f"%><%@taglib + uri="https://ajax4jsf.dev.java.net/ajax" prefix="a4j"%><%@ page language="java" + contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> + + + + +Basic JSF/Ajax sample + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
+ + + + + + + + + + + + + + + + + + + +
+ + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/build-dojo.xml b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/build-dojo.xml new file mode 100644 index 0000000000..6167eba10e --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/build-dojo.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/build.xml b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/build.xml new file mode 100644 index 0000000000..fce9338312 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/build.xml @@ -0,0 +1,119 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/pom.xml b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/pom.xml new file mode 100644 index 0000000000..b95dda30fd --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/pom.xml @@ -0,0 +1,144 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.7-SNAPSHOT + + sample-store-secure-webapp + war + Apache Tuscany SCA Sample Store in a WebApp + + + + org.apache.tuscany.sca + tuscany-host-webapp + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc-runtime + 1.7-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-policy-security + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy-security-http + 1.7-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-policy-security-geronimo + 1.7-SNAPSHOT + + + + + stax + stax-api + 1.0.1 + provided + + + + + javax.servlet + servlet-api + 2.3 + provided + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + + org.apache.maven.plugins + maven-antrun-plugin + + + + ant + ant-trax + 1.6.5 + + + + + copy-dojo-files + generate-resources + + run + + + + + + + + + + + + clean-dojo-files + clean + + run + + + + + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/Catalog.java b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/Catalog.java new file mode 100644 index 0000000000..0d8d3d561a --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/Catalog.java @@ -0,0 +1,8 @@ +package services; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface Catalog { + Item[] get(); +} diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/CurrencyConverter.java b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/CurrencyConverter.java new file mode 100644 index 0000000000..15b2c6e3a6 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/CurrencyConverter.java @@ -0,0 +1,12 @@ +package services; + +import org.osoa.sca.annotations.Remotable; + +@Remotable +public interface CurrencyConverter { + public double getConversion(String fromCurrenycCode, + String toCurrencyCode, + double amount); + + public String getCurrencySymbol(String currencyCode); +} diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/CurrencyConverterImpl.java b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/CurrencyConverterImpl.java new file mode 100644 index 0000000000..2bf9d8d42b --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/CurrencyConverterImpl.java @@ -0,0 +1,21 @@ +package services; + +public class CurrencyConverterImpl implements CurrencyConverter { + public double getConversion(String fromCurrencyCode, + String toCurrencyCode, + double amount) { + if (toCurrencyCode.equals("USD")) + return amount; + else if (toCurrencyCode.equals("EUR")) + return ((double)Math.round(amount * 0.7256 * 100)) /100; + return 0; + } + + public String getCurrencySymbol(String currencyCode) { + if (currencyCode.equals("USD")) + return "$"; + else if (currencyCode.equals("EUR")) + return "E"; //"€"; + return "?"; + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/FruitsCatalogImpl.java b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/FruitsCatalogImpl.java new file mode 100644 index 0000000000..4cac4ac21d --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/FruitsCatalogImpl.java @@ -0,0 +1,35 @@ +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 FruitsCatalogImpl implements Catalog { + @Property + public String currencyCode = "USD"; + @Reference + public CurrencyConverter currencyConverter; + + private List catalog = new ArrayList(); + + @Init + public void init() { + String currencySymbol = currencyConverter + .getCurrencySymbol(currencyCode); + catalog.add(new Item("Apple", currencySymbol + + currencyConverter.getConversion("USD", currencyCode, 2.99))); + catalog.add(new Item("Orange", currencySymbol + + currencyConverter.getConversion("USD", currencyCode, 3.55))); + catalog.add(new Item("Pear", currencySymbol + + currencyConverter.getConversion("USD", currencyCode, 1.55))); + } + + public Item[] get() { + Item[] catalogArray = new Item[catalog.size()]; + catalog.toArray(catalogArray); + return catalogArray; + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/Item.java b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/Item.java new file mode 100644 index 0000000000..e8bcfabfb1 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/services/Item.java @@ -0,0 +1,30 @@ +package services; + +public class Item { + private String name; + private String price; + + public Item() { + } + + public Item(String name, String price) { + this.name = name; + this.price = price; + } + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + + public String getPrice() { + return price; + } + + public void setPrice(String price) { + this.price = price; + } +} diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/store/security/StoreCallbackHandler.java b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/store/security/StoreCallbackHandler.java new file mode 100644 index 0000000000..88e3a778a0 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/java/store/security/StoreCallbackHandler.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package store.security; + +import java.io.IOException; + +import javax.security.auth.callback.Callback; +import javax.security.auth.callback.CallbackHandler; +import javax.security.auth.callback.NameCallback; +import javax.security.auth.callback.PasswordCallback; +import javax.security.auth.callback.UnsupportedCallbackException; + +/** + * @version $Rev$ $Date$ + */ +public class StoreCallbackHandler implements CallbackHandler { + + public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException { + for (int i = 0; i < callbacks.length; i++) { + if (callbacks[i] instanceof NameCallback) { + NameCallback nc = (NameCallback)callbacks[i]; + nc.setName("PWEST"); + } else if (callbacks[i] instanceof PasswordCallback) { + PasswordCallback pc = (PasswordCallback)callbacks[i]; + pc.setPassword("xxx".toCharArray()); + } else { + throw new UnsupportedCallbackException + (callbacks[i], "Unsupported Callback!"); + } + } + } + +} diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/resources/definitions.xml b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/resources/definitions.xml new file mode 100644 index 0000000000..55789c8443 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/resources/definitions.xml @@ -0,0 +1,73 @@ + + + + + + + + + + + + + + + + ldap-realm + ldap-realm + + + + + + + + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/resources/store.composite b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/resources/store.composite new file mode 100644 index 0000000000..5c567cbd15 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/resources/store.composite @@ -0,0 +1,41 @@ + + + + + + + + + USD + + + + + + + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/META-INF/sca-contribution.xml b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/META-INF/sca-contribution.xml new file mode 100644 index 0000000000..41c84c9a44 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/META-INF/sca-contribution.xml @@ -0,0 +1,23 @@ + + + + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/WEB-INF/geronimo-web.xml b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/WEB-INF/geronimo-web.xml new file mode 100644 index 0000000000..705010bf7c --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/WEB-INF/geronimo-web.xml @@ -0,0 +1,73 @@ + + + + + org.apache.tuscany + sample-store-secure-webapp + 1.0 + car + + + + org.apache.axiom + org.apache.axis2 + org.apache.commons + org.jdom + + + + /sample-store-secure-webapp + + ldap-realm + + + + + + + + + + + ldap-realm + + + + ldap-realm + org.apache.geronimo.security.realm.providers.LDAPLoginModule + + com.sun.jndi.ldap.LdapCtxFactory + ldap://dpev007.innovate.ibm.com:389 + cn=ldaproot,dc=tnc,dc=org + ldappass + simple + ou=people,dc=tnc,dc=org + uid={0} + false + ou=groups,dc=tnc,dc=org + cn + (member={0}) + false + + + + + diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/WEB-INF/web.xml b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..704c7631b0 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,60 @@ + + + sample-store-secure-webapp + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + + store.html + + + + + + FORM + ldap-realm + + /auth/logon.html + /auth/logonError.html + + + + + Application managers + manager + + + + Application users + user + + + + + Areas with authentication required + /protected/* + GET + POST + + + manager + + + + + org.apache.tuscany.sca.contribution.processor.ValidationSchemaExtensionPoint.enabled + java.lang.String + false + + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/auth/logon.html b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/auth/logon.html new file mode 100644 index 0000000000..09191f7010 --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/auth/logon.html @@ -0,0 +1,20 @@ + +

Store Authentication

+
+ + + + + + + + + + + + +
Username:
Password:
+ +
+
+ \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/auth/logonError.html b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/auth/logonError.html new file mode 100644 index 0000000000..c0c0f7b75d --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/auth/logonError.html @@ -0,0 +1,5 @@ + +

Store Authentication ERROR

+Username, password or role incorrect. +                                                         + \ No newline at end of file diff --git a/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/store.html b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/store.html new file mode 100644 index 0000000000..e4cd0ba12d --- /dev/null +++ b/sandbox/lresende/sca-1.x/samples/store-secure-webapp/src/main/webapp/store.html @@ -0,0 +1,48 @@ + + +Store + + + + + + + + + + +

Store

+
+

Catalog

+
+
+
+
+ +
+
+ + -- cgit v1.2.3