From 4f6a51d428d96dbb476d8412143748e841993372 Mon Sep 17 00:00:00 2001 From: antelder Date: Mon, 20 Sep 2010 12:32:50 +0000 Subject: Copy trunk samples to sanbox to experiment with renames and moves git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@998905 13f79535-47bb-0310-9956-ffa450edef68 --- .../running-tuscany/launcher-command-line/README | 13 ++ .../running-tuscany/launcher-embedded-jse/README | 20 ++ .../launcher-embedded-jse/build.xml | 110 +++++++++++ .../running-tuscany/launcher-embedded-jse/pom.xml | 94 ++++++++++ .../main/java/calculator/CalculatorService.java | 38 ++++ .../JSELauncherBindingJSONRPCCalculator.java | 59 ++++++ .../launcher/JSELauncherBindingRMICalculator.java | 61 +++++++ .../launcher/JSELauncherBindingSCACalculator.java | 59 ++++++ .../launcher/JSELauncherBindingWSCalculator.java | 59 ++++++ .../JSELauncherImplementationJavaCalculator.java | 46 +++++ .../JSELauncherImplementationScriptCalculator.java | 59 ++++++ .../src/main/java/launcher/RuntimeIntegration.java | 43 +++++ .../java/launcher/SampleLauncherException.java | 42 +++++ .../src/test/java/launcher/LauncherTestCase.java | 48 +++++ .../launcher-embedded-osgi-base/README | 24 +++ .../launcher-embedded-osgi-base/build.xml | 94 ++++++++++ .../launcher-embedded-osgi-base/pom.xml | 71 +++++++ .../main/java/calculator/CalculatorService.java | 38 ++++ .../src/main/java/launcher/RuntimeIntegration.java | 61 +++++++ .../src/main/java/launcher/SampleJSELauncher.java | 89 +++++++++ .../java/launcher/SampleLauncherException.java | 42 +++++ .../src/test/java/launcher/LauncherTestCase.java | 39 ++++ .../running-tuscany/launcher-embedded-osgi/README | 20 ++ .../launcher-embedded-osgi/build.xml | 94 ++++++++++ .../running-tuscany/launcher-embedded-osgi/pom.xml | 76 ++++++++ .../main/java/calculator/CalculatorService.java | 38 ++++ .../src/main/java/launcher/RuntimeIntegration.java | 61 +++++++ .../src/main/java/launcher/SampleJSELauncher.java | 89 +++++++++ .../java/launcher/SampleLauncherException.java | 42 +++++ .../src/test/java/launcher/LauncherTestCase.java | 39 ++++ .../samples/running-tuscany/launcher-maven/README | 18 ++ .../samples/running-tuscany/launcher-osgi/README | 33 ++++ .../samples/running-tuscany/launcher-shell/README | 34 ++++ .../samples/running-tuscany/launcher-shell/pom.xml | 79 ++++++++ sandbox/samples/running-tuscany/launcher-shell/sca | 19 ++ .../samples/running-tuscany/launcher-shell/sca.bat | 30 +++ .../launcher-shell/scripts/test-remote.txt | 36 ++++ .../launcher-shell/scripts/test-start.txt | 18 ++ .../launcher-shell/scripts/test-status.txt | 17 ++ .../launcher-shell/scripts/test-stop.txt | 17 ++ .../launcher-shell/scripts/test.txt | 36 ++++ .../launcher-shell/src/main/java/sample/Shell.java | 203 +++++++++++++++++++++ .../src/main/java/sample/ShellServlet.java | 48 +++++ .../launcher-shell/src/main/webapp/WEB-INF/web.xml | 48 +++++ .../launcher-shell/src/main/webapp/index.html | 42 +++++ .../samples/running-tuscany/launcher-webapp/README | 29 +++ sandbox/samples/running-tuscany/pom.xml | 53 ++++++ 47 files changed, 2428 insertions(+) create mode 100644 sandbox/samples/running-tuscany/launcher-command-line/README create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/README create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/build.xml create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/pom.xml create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingJSONRPCCalculator.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingRMICalculator.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingSCACalculator.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingWSCalculator.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherImplementationJavaCalculator.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherImplementationScriptCalculator.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/RuntimeIntegration.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/SampleLauncherException.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-jse/src/test/java/launcher/LauncherTestCase.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi-base/README create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi-base/build.xml create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi-base/pom.xml create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/RuntimeIntegration.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/SampleJSELauncher.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/SampleLauncherException.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/test/java/launcher/LauncherTestCase.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi/README create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi/build.xml create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi/pom.xml create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/calculator/CalculatorService.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/RuntimeIntegration.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/SampleJSELauncher.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/SampleLauncherException.java create mode 100644 sandbox/samples/running-tuscany/launcher-embedded-osgi/src/test/java/launcher/LauncherTestCase.java create mode 100644 sandbox/samples/running-tuscany/launcher-maven/README create mode 100644 sandbox/samples/running-tuscany/launcher-osgi/README create mode 100644 sandbox/samples/running-tuscany/launcher-shell/README create mode 100644 sandbox/samples/running-tuscany/launcher-shell/pom.xml create mode 100755 sandbox/samples/running-tuscany/launcher-shell/sca create mode 100644 sandbox/samples/running-tuscany/launcher-shell/sca.bat create mode 100644 sandbox/samples/running-tuscany/launcher-shell/scripts/test-remote.txt create mode 100644 sandbox/samples/running-tuscany/launcher-shell/scripts/test-start.txt create mode 100644 sandbox/samples/running-tuscany/launcher-shell/scripts/test-status.txt create mode 100644 sandbox/samples/running-tuscany/launcher-shell/scripts/test-stop.txt create mode 100644 sandbox/samples/running-tuscany/launcher-shell/scripts/test.txt create mode 100644 sandbox/samples/running-tuscany/launcher-shell/src/main/java/sample/Shell.java create mode 100644 sandbox/samples/running-tuscany/launcher-shell/src/main/java/sample/ShellServlet.java create mode 100644 sandbox/samples/running-tuscany/launcher-shell/src/main/webapp/WEB-INF/web.xml create mode 100644 sandbox/samples/running-tuscany/launcher-shell/src/main/webapp/index.html create mode 100644 sandbox/samples/running-tuscany/launcher-webapp/README create mode 100644 sandbox/samples/running-tuscany/pom.xml (limited to 'sandbox/samples/running-tuscany') diff --git a/sandbox/samples/running-tuscany/launcher-command-line/README b/sandbox/samples/running-tuscany/launcher-command-line/README new file mode 100644 index 0000000000..bf963ea98e --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-command-line/README @@ -0,0 +1,13 @@ +To execute a sample contribution from the command line + +on Windows, from a command prompt in the samples directory, run the command ... + +..\bin\tuscany.bat "contribution-name" + +for example + +..\bin\tuscany.bat contribution-binding-sca-calculator + +or on *nix platforms, from a shell prompt in the samples directory, run the command ... + +../bin/tuscany.sh contribution-binding-sca-calculator diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/README b/sandbox/samples/running-tuscany/launcher-embedded-jse/README new file mode 100644 index 0000000000..7108333efa --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/README @@ -0,0 +1,20 @@ +JSE Sample Launcher +=================== + +This directory contains a sample java launcher for the +tuscany sample contributions. + +The README file in the /samples directory provides +general instructions about building and running sample contributions using the +tuscany sample launchers ( where distribution-unpack-dir is the directory in which you +unpacked the tuscany binary distribution archive) + +To use this sample JSE launcher with ant excute the command + +ant run- + +where run- is one of the targets in the build.xml file + +To use this sample launcher to run all of the contributions as junit test cases, +execute the command "mvn" in the launcher directory. + diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/build.xml b/sandbox/samples/running-tuscany/launcher-embedded-jse/build.xml new file mode 100644 index 0000000000..05c7ab3c49 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/build.xml @@ -0,0 +1,110 @@ + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + Please use 'ant run-name-of-sample-contribution-to-run' for example, try one of + 'ant run-contribution-binding-sca-calculator' + 'ant run-contribution-binding-ws-calculator' + 'ant run-contribution-binding-rmi-calculator' + 'ant run-contribution-implementation-java-calculator' + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/pom.xml b/sandbox/samples/running-tuscany/launcher-embedded-jse/pom.xml new file mode 100644 index 0000000000..a30d55d2e9 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/pom.xml @@ -0,0 +1,94 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-launcher-embedded-jse + Apache Tuscany SCA Sample Launcher Embedded JSE + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-core + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-webservice + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-ejava + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-script-runtime + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-binding-jsonrpc-runtime + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-databinding-json + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + + + + diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/calculator/CalculatorService.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..12d80ffd1c --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/calculator/CalculatorService.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 calculator; + +import org.oasisopen.sca.annotation.Remotable; + + +/** + * The Calculator service interface. + */ +@Remotable +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/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingJSONRPCCalculator.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingJSONRPCCalculator.java new file mode 100644 index 0000000000..3d6af9f561 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingJSONRPCCalculator.java @@ -0,0 +1,59 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import calculator.CalculatorService; + +/** + * This client program shows how to create an embedded SCA runtime, load a contribution, + * start it and locate and invoke an SCA component + */ +public class JSELauncherBindingJSONRPCCalculator { + + public static void main(String[] args) throws Exception { + JSELauncherBindingJSONRPCCalculator launcher = new JSELauncherBindingJSONRPCCalculator(); + launcher.launchBindingSCACalculator(); + } + + /* + * Using the Tuscany Node API to load a contribution. + * Using the Tuscany Node API to get a local service proxy + */ + public void launchBindingSCACalculator(){ + Node node = NodeFactory.newInstance().createNode(new Contribution("c1", "../binding-jsonrpc/contribution-calculator/target/sample-contribution-binding-jsonrpc-calculator.jar")); + node.start(); + + CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // TODO - could use JUnit assertions but don't want to have to handle JUnit dependency from Ant script + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + if (result != 5.0){ + throw new SampleLauncherException(); + } + + node.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingRMICalculator.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingRMICalculator.java new file mode 100644 index 0000000000..0c9c820ccb --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingRMICalculator.java @@ -0,0 +1,61 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import calculator.CalculatorService; + +/** + * This client program shows how to create an embedded SCA runtime, load a contribution, + * start it and locate and invoke an SCA component + */ +public class JSELauncherBindingRMICalculator { + + public static void main(String[] args) throws Exception { + JSELauncherBindingRMICalculator launcher = new JSELauncherBindingRMICalculator(); + launcher.launchBindingRMICalculator(); + } + + + public void launchBindingRMICalculator(){ + + Node node1 = NodeFactory.newInstance().createNode(new Contribution("c1", "../../sca-features//binding-rmi/contribution-calculator-service/target/classes")); + Node node2 = NodeFactory.newInstance().createNode(new Contribution("c1", "../../sca-features//binding-rmi/contribution-calculator-reference/target/classes")); + + node1.start(); + node2.start(); + + CalculatorService calculator = node2.getService(CalculatorService.class, "CalculatorServiceComponent"); + + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + if (result != 5.0){ + throw new SampleLauncherException(); + } + + + node1.stop(); + node2.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingSCACalculator.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingSCACalculator.java new file mode 100644 index 0000000000..49960a7506 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingSCACalculator.java @@ -0,0 +1,59 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import calculator.CalculatorService; + +/** + * This client program shows how to create an embedded SCA runtime, load a contribution, + * start it and locate and invoke an SCA component + */ +public class JSELauncherBindingSCACalculator { + + public static void main(String[] args) throws Exception { + JSELauncherBindingSCACalculator launcher = new JSELauncherBindingSCACalculator(); + launcher.launchBindingSCACalculator(); + } + + /* + * Using the Tuscany Node API to load a contribution. + * Using the Tuscany Node API to get a local service proxy + */ + public void launchBindingSCACalculator(){ + Node node = NodeFactory.newInstance().createNode(new Contribution("c1", "../../sca-features/binding-sca/contribution-calculator/target/sample-contribution-binding-sca-calculator.jar")); + node.start(); + + CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // TODO - could use JUnit assertions but don't want to have to handle JUnit dependency from Ant script + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + if (result != 5.0){ + throw new SampleLauncherException(); + } + + node.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingWSCalculator.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingWSCalculator.java new file mode 100644 index 0000000000..71ff526589 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherBindingWSCalculator.java @@ -0,0 +1,59 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import calculator.CalculatorService; + +/** + * This client program shows how to create an embedded SCA runtime, load a contribution, + * start it and locate and invoke an SCA component + */ +public class JSELauncherBindingWSCalculator { + + public static void main(String[] args) throws Exception { + JSELauncherBindingWSCalculator launcher = new JSELauncherBindingWSCalculator(); + launcher.launchBindingWSCalculator(); + } + + /* + * Using the Tuscany Node API to load a contribution. + * Using the Tuscany Node API to get a local service proxy + */ + public void launchBindingWSCalculator(){ + Node node = NodeFactory.newInstance().createNode(new Contribution("c1", "../../sca-features/binding-ws/contribution-calculator/target/sample-contribution-binding-ws-calculator.jar")); + node.start(); + + CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // TODO - could use JUnit assertions but don't want to have to handle JUnit dependency from Ant script + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + if (result != 5.0){ + throw new SampleLauncherException(); + } + + node.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherImplementationJavaCalculator.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherImplementationJavaCalculator.java new file mode 100644 index 0000000000..74202d5b86 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherImplementationJavaCalculator.java @@ -0,0 +1,46 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import calculator.CalculatorService; + +/** + * This client program shows how to create an embedded SCA runtime, load a contribution, + * start it and locate and invoke an SCA component + */ +public class JSELauncherImplementationJavaCalculator { + + public static void main(String[] args) throws Exception { + JSELauncherImplementationJavaCalculator launcher = new JSELauncherImplementationJavaCalculator(); + launcher.launchImplementationJavaCalculator(); + } + + public void launchImplementationJavaCalculator(){ + Node node = NodeFactory.newInstance().createNode(new Contribution("c1", "../../sca-features/implementation-java/contribution-calculator/target/classes")); + node.start(); + + node.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherImplementationScriptCalculator.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherImplementationScriptCalculator.java new file mode 100644 index 0000000000..ca652718d7 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/JSELauncherImplementationScriptCalculator.java @@ -0,0 +1,59 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +import calculator.CalculatorService; + +/** + * This client program shows how to create an embedded SCA runtime, load a contribution, + * start it and locate and invoke an SCA component + */ +public class JSELauncherImplementationScriptCalculator { + + public static void main(String[] args) throws Exception { + JSELauncherImplementationScriptCalculator launcher = new JSELauncherImplementationScriptCalculator(); + launcher.launchImplementationScriptCalculator(); + } + + /* + * Using the Tuscany Node API to load a contribution. + * Using the Tuscany Node API to get a local service proxy + */ + public void launchImplementationScriptCalculator(){ + Node node = NodeFactory.newInstance().createNode(new Contribution("c1", "../implementation-script/contribution-calculator/target/sample-contribution-implementation-script-calculator.jar")); + node.start(); + + CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + + // TODO - could use JUnit assertions but don't want to have to handle JUnit dependency from Ant script + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + if (result != 5.0){ + throw new SampleLauncherException(); + } + + node.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/RuntimeIntegration.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/RuntimeIntegration.java new file mode 100644 index 0000000000..fdff16c12c --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/RuntimeIntegration.java @@ -0,0 +1,43 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + + +/** + * Base JSE launcher function + */ +public class RuntimeIntegration { + + + public Node startNode(Contribution... contributions){ + Node node = NodeFactory.newInstance().createNode(contributions); + node.start(); + return node; + } + + public void stopNode(Node node){ + node.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/SampleLauncherException.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/SampleLauncherException.java new file mode 100644 index 0000000000..f2ed3d421d --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/main/java/launcher/SampleLauncherException.java @@ -0,0 +1,42 @@ +/* + * 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 launcher; + +/** + * This exception signals problems in the management of SCA component execution. + */ +public class SampleLauncherException extends RuntimeException { + /** + * Constructs a SampleLauncherException with no detail message. + */ + public SampleLauncherException() { + super(); + } + + /** + * Constructs a SampleLauncherException with the specified detail + * message. + * + * @param message the detail message + */ + public SampleLauncherException(String message) { + super(message); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-jse/src/test/java/launcher/LauncherTestCase.java b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/test/java/launcher/LauncherTestCase.java new file mode 100644 index 0000000000..6bbbe32a7f --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-jse/src/test/java/launcher/LauncherTestCase.java @@ -0,0 +1,48 @@ +/* + * 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 launcher; + +import org.junit.Test; + +/** + * Test sample contributions. + */ +public class LauncherTestCase { + + @Test + public void testContributionBindingSCACalculator() throws Exception { + JSELauncherBindingSCACalculator.main(null); + } + + + @Test + public void testContributionBindingWSCalculator() throws Exception { + JSELauncherBindingWSCalculator.main(null); + } + + @Test + public void testContributionBindingRMICalculator() throws Exception { + JSELauncherBindingRMICalculator.main(null); + } + + @Test + public void testContributionImplementationJavaCalculator() throws Exception { + JSELauncherImplementationJavaCalculator.main(null); + } +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/README b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/README new file mode 100644 index 0000000000..362d6032d2 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/README @@ -0,0 +1,24 @@ +OSGI Sample Launcher +=================== + +This directory contains a sample launcher for the running the +tuscany sample contributions in an OSGI environment. + +The difference between this sample and the sample with the name without the +-base suffix is that this one uses the Tuscany aggregated jar to minimize the +jars a user needs to use. + +The README file in the /samples directory provides +general instructions about building and running sample contributions using the +tuscany sample launchers. ( where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive) + +To use this sample OSGI launcher with ant excute the command + +ant run- + +where run- is one of the targets in the build.xml file + +To use this sample launcher to run all of the contributions as junit test cases, +execute the command "mvn" in the launcher directory. diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/build.xml b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/build.xml new file mode 100644 index 0000000000..139ff054f7 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/build.xml @@ -0,0 +1,94 @@ + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + Please use 'ant run-name-of-sample-contribution-to-run' for example, try one of + 'ant run-contribution-binding-sca-calculator' + + + + + + + + + + + + + + + and ant run + + + + + diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/pom.xml b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/pom.xml new file mode 100644 index 0000000000..aa0876b338 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-launcher-embedded-osgi-base + Apache Tuscany SCA Sample Launcher Embedded OSGi using base jar + + + + org.apache.tuscany.sca.shades + tuscany-base-nodep + 2.0-SNAPSHOT + + + commons-cli + commons-cli + 1.2 + + + org.eclipse + osgi + 3.5.0-v20090520 + compile + + + org.eclipse.osgi + services + 3.2.0-v20090520-1800 + compile + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + + + + diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/calculator/CalculatorService.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..a59a7c3b16 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/calculator/CalculatorService.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 calculator; + +import org.oasisopen.sca.annotation.Remotable; + + +/** + * The Calculator service interface. + */ +@Remotable +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/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/RuntimeIntegration.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/RuntimeIntegration.java new file mode 100644 index 0000000000..2c1cdf187a --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/RuntimeIntegration.java @@ -0,0 +1,61 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.equinox.launcher.LauncherException; +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; + + +/** + * OSGi launcher function + */ +public class RuntimeIntegration { + + public Node startNode(Contribution... contributions){ + NodeLauncher launcher = NodeLauncher.newInstance(); + + // TODO - why do we have 3 different versions of the Contribution class? + org.apache.tuscany.sca.node.equinox.launcher.Contribution equinoxContributions[] = + new org.apache.tuscany.sca.node.equinox.launcher.Contribution[contributions.length]; + int i = 0; + for (Contribution inContrib : contributions) { + org.apache.tuscany.sca.node.equinox.launcher.Contribution outContrib = + new org.apache.tuscany.sca.node.equinox.launcher.Contribution(inContrib.getURI(), inContrib.getLocation()); + equinoxContributions[i] = outContrib; + i++; + } + Node node = null; + + try { + node = launcher.createNode(null, equinoxContributions); + } catch (LauncherException ex) { + throw new SampleLauncherException(ex.getMessage()); + } + node.start(); + return node; + } + + public void stopNode(Node node){ + node.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/SampleJSELauncher.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/SampleJSELauncher.java new file mode 100644 index 0000000000..34ee729921 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/SampleJSELauncher.java @@ -0,0 +1,89 @@ +/* + * 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 launcher; + +import java.net.URI; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; +import org.oasisopen.sca.client.SCAClientFactory; + +import calculator.CalculatorService; + + +/** + * This client program shows how to create an embedded SCA runtime, start it, + * and locate and invoke a SCA component + */ +public class SampleJSELauncher extends RuntimeIntegration { + + public static void main(String[] args) throws Exception { + SampleJSELauncher launcher = new SampleJSELauncher(); + + String contribution = null; + + if (args == null || args.length != 1){ + System.out.println("Please provide the name of the sample contribution to run as a parameter"); + System.out.println("Running binding-sca-calculator by default"); + contribution = "contribution-binding-sca-calculator"; + } else { + contribution = args[0]; + } + + if (contribution.equals("contribution-binding-sca-calculator")){ + launcher.launchBindingSCACalculator(); + } else if (contribution.equals("contribution-binding-ws-calculator")){ + launcher.launchBindingWSCalculator(); + } else { + System.out.println("Sample contribution " + contribution + "not found"); + } + + } + + /** + * The contribution-binding-sca-calculator contribution includes a client component + * that calls the CalculatorServiceComponent from an operation marked by @Init. + */ + public void launchBindingSCACalculator(){ + Node node = startNode(new Contribution("c1", "../../sca-features/binding-sca/contribution-calculator/target/sample-contribution-binding-sca-calculator.jar")); + + stopNode(node); + } + + /* + * Using a Tuscany specific mechanism for getting at local service proxies + */ + public void launchBindingWSCalculator() throws NoSuchDomainException, NoSuchServiceException{ + Node node = startNode(new Contribution("c1", "../../sca-features/binding-ws/contribution-calculator/target/sample-contribution-binding-ws-calculator.jar")); + + CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + if (result != 5.0){ + throw new SampleLauncherException(); + } + + stopNode(node); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/SampleLauncherException.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/SampleLauncherException.java new file mode 100644 index 0000000000..1eacb94b19 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/main/java/launcher/SampleLauncherException.java @@ -0,0 +1,42 @@ +/* + * 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 launcher; + +/** + * This exception signals problems in the management of SCA component execution. + */ +public class SampleLauncherException extends RuntimeException { + /** + * Constructs a SampleLauncherException with no detail message. + */ + public SampleLauncherException() { + super(); + } + + /** + * Constructs a SampleLauncherException with the specified detail + * message. + * + * @param message the detail message + */ + public SampleLauncherException(String message) { + super(message); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/test/java/launcher/LauncherTestCase.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/test/java/launcher/LauncherTestCase.java new file mode 100644 index 0000000000..9228d33018 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi-base/src/test/java/launcher/LauncherTestCase.java @@ -0,0 +1,39 @@ +/* + * 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 launcher; + +import org.junit.Test; + + + +/** + * Test the Calculator composition. + */ +public class LauncherTestCase { + + @Test + public void testContributionBindingSCACalculator() throws Exception { + SampleJSELauncher.main(new String[] {"contribution-binding-sca-calculator"}); + } + + @Test + public void testContributionBindingWSCalculator() throws Exception { + SampleJSELauncher.main(new String[] {"contribution-binding-ws-calculator"}); + } +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi/README b/sandbox/samples/running-tuscany/launcher-embedded-osgi/README new file mode 100644 index 0000000000..01d277ae09 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi/README @@ -0,0 +1,20 @@ +OSGI Sample Launcher +=================== + +This directory contains a sample launcher for the running the +tuscany sample contributions in an OSGI environment. + +The README file in the /samples directory provides +general instructions about building and running sample contributions using the +tuscany sample launchers. ( where +distribution-unpack-dir is the directory in which you unpacked the tuscany +binary distribution archive) + +To use this sample OSGI launcher with ant excute the command + +ant run- + +where run- is one of the targets in the build.xml file + +To use this sample launcher to run all of the contributions as junit test cases, +execute the command "mvn" in the launcher directory. diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi/build.xml b/sandbox/samples/running-tuscany/launcher-embedded-osgi/build.xml new file mode 100644 index 0000000000..f08d19e472 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi/build.xml @@ -0,0 +1,94 @@ + + + + + + + ${tuscany.home} + + + + + + + + + + + + + + + + + + + + + + + + + Please use 'ant run-name-of-sample-contribution-to-run' for example, try one of + 'ant run-contribution-binding-sca-calculator' + + + + + + + + + + + + + + + and ant run + + + + + diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi/pom.xml b/sandbox/samples/running-tuscany/launcher-embedded-osgi/pom.xml new file mode 100644 index 0000000000..c3cf7e6577 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi/pom.xml @@ -0,0 +1,76 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-launcher-embedded-osgi + Apache Tuscany SCA Sample Launcher Embedded OSGi + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-core + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-webservice + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-ejava + pom + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + ${artifactId} + + + + + + diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/calculator/CalculatorService.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/calculator/CalculatorService.java new file mode 100644 index 0000000000..12d80ffd1c --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/calculator/CalculatorService.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 calculator; + +import org.oasisopen.sca.annotation.Remotable; + + +/** + * The Calculator service interface. + */ +@Remotable +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/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/RuntimeIntegration.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/RuntimeIntegration.java new file mode 100644 index 0000000000..f4a2f0780c --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/RuntimeIntegration.java @@ -0,0 +1,61 @@ +/* + * 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 launcher; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.equinox.launcher.LauncherException; +import org.apache.tuscany.sca.node.equinox.launcher.NodeLauncher; + + +/** + * OSGi launcher function + */ +public class RuntimeIntegration { + + public Node startNode(Contribution... contributions){ + NodeLauncher launcher = NodeLauncher.newInstance(); + + // TODO - why do we have 3 different versions of the Contribution class? + org.apache.tuscany.sca.node.equinox.launcher.Contribution equinoxContributions[] = + new org.apache.tuscany.sca.node.equinox.launcher.Contribution[contributions.length]; + int i = 0; + for (Contribution inContrib : contributions) { + org.apache.tuscany.sca.node.equinox.launcher.Contribution outContrib = + new org.apache.tuscany.sca.node.equinox.launcher.Contribution(inContrib.getURI(), inContrib.getLocation()); + equinoxContributions[i] = outContrib; + i++; + } + Node node = null; + + try { + node = launcher.createNode(null, equinoxContributions); + } catch (LauncherException ex) { + throw new SampleLauncherException(ex.getMessage()); + } + node.start(); + return node; + } + + public void stopNode(Node node){ + node.stop(); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/SampleJSELauncher.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/SampleJSELauncher.java new file mode 100644 index 0000000000..06b646f0d2 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/SampleJSELauncher.java @@ -0,0 +1,89 @@ +/* + * 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 launcher; + +import java.net.URI; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.oasisopen.sca.NoSuchDomainException; +import org.oasisopen.sca.NoSuchServiceException; +import org.oasisopen.sca.client.SCAClientFactory; + +import calculator.CalculatorService; + + +/** + * This client program shows how to create an embedded SCA runtime, start it, + * and locate and invoke a SCA component + */ +public class SampleJSELauncher extends RuntimeIntegration { + + public static void main(String[] args) throws Exception { + SampleJSELauncher launcher = new SampleJSELauncher(); + + String contribution = null; + + if (args == null || args.length != 1){ + System.out.println("Please provide the name of the sample contribution to run as a parameter"); + System.out.println("Running binding-sca-calculator by default"); + contribution = "contribution-binding-sca-calculator"; + } else { + contribution = args[0]; + } + + if (contribution.equals("contribution-binding-sca-calculator")){ + launcher.launchBindingSCACalculator(); + } else if (contribution.equals("contribution-binding-ws-calculator")){ + launcher.launchBindingWSCalculator(); + } else { + System.out.println("Sample contribution " + contribution + "not found"); + } + + } + + /** + * The contribution-binding-sca-calculator contribution includes a client component + * that calls the CalculatorServiceComponent from an operation marked by @Init. + */ + public void launchBindingSCACalculator(){ + Node node = startNode(new Contribution("c1", "../../sca-features/binding-sca/contribution-calculator/target/sample-contribution-binding-sca-calculator.jar")); + + stopNode(node); + } + + /* + * Using a Tuscany specific mechanism for getting at local service proxies + */ + public void launchBindingWSCalculator() throws NoSuchDomainException, NoSuchServiceException{ + Node node = startNode(new Contribution("c1", "../../sca-features/binding-ws/contribution-calculator/target/sample-contribution-binding-ws-calculator.jar")); + + CalculatorService calculator = node.getService(CalculatorService.class, "CalculatorServiceComponent"); + + double result = calculator.add(3, 2); + System.out.println("3 + 2 = " + result); + if (result != 5.0){ + throw new SampleLauncherException(); + } + + stopNode(node); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/SampleLauncherException.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/SampleLauncherException.java new file mode 100644 index 0000000000..f2ed3d421d --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/main/java/launcher/SampleLauncherException.java @@ -0,0 +1,42 @@ +/* + * 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 launcher; + +/** + * This exception signals problems in the management of SCA component execution. + */ +public class SampleLauncherException extends RuntimeException { + /** + * Constructs a SampleLauncherException with no detail message. + */ + public SampleLauncherException() { + super(); + } + + /** + * Constructs a SampleLauncherException with the specified detail + * message. + * + * @param message the detail message + */ + public SampleLauncherException(String message) { + super(message); + } + +} diff --git a/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/test/java/launcher/LauncherTestCase.java b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/test/java/launcher/LauncherTestCase.java new file mode 100644 index 0000000000..7b72ec7aee --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-embedded-osgi/src/test/java/launcher/LauncherTestCase.java @@ -0,0 +1,39 @@ +/* + * 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 launcher; + +import org.junit.Test; + + + +/** + * Test the Calculator composition. + */ +public class LauncherTestCase { + + @Test + public void testContributionBindingSCACalculator() throws Exception { + SampleJSELauncher.main(new String[] {"contribution-binding-sca-calculator"}); + } + + @Test + public void testContributionBindingWSCalculator() throws Exception { + SampleJSELauncher.main(new String[] {"contribution-binding-ws-calculator"}); + } +} diff --git a/sandbox/samples/running-tuscany/launcher-maven/README b/sandbox/samples/running-tuscany/launcher-maven/README new file mode 100644 index 0000000000..ff976c3515 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-maven/README @@ -0,0 +1,18 @@ +To execute a sample contribution from Maven + +look for contributions that have the following configuration in their pom.xml file: + + + org.apache.tuscany.maven.plugins + maven-tuscany-plugin + 2.0-SNAPSHOT + + +For contributions that have this, for example, binding-sca/contribution-calculator, do the following + +cd samples/binding-sca/contribution-calculator +mvn tuscany:run + +This will launch the contribution in the Tuscany runtime and then wait. At this point you can use +other clients to send messages to services that the running SCA applcation exposes, +for example, try calculator-scaclient. diff --git a/sandbox/samples/running-tuscany/launcher-osgi/README b/sandbox/samples/running-tuscany/launcher-osgi/README new file mode 100644 index 0000000000..6df2c1d2f2 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-osgi/README @@ -0,0 +1,33 @@ +The Tuscany runtime can be run in and OSGi container. + +Running in Equinox +------------------ + +On Windows, run +java -jar ..\..\modules\osgi-3.5.0-v20090520.jar -configuration ..\..\features\configuration -clean -console + +On *Unix, run +java -jar ../../modules/osgi-3.5.0-v20090520.jar -configuration ../../features/configuration -clean -console + +You should see the osgi console: + +osgi> + +osgi> Jun 22, 2009 1:32:27 PM org.apache.tuscany.sca.extensibility.equinox.EquinoxServiceDiscoveryActivator start +INFO: Equinox-based service discoverer is now configured. + +You can run "ss" command under the osgi> to see the status of the bundles. +osgi> ss + +Then you can install and start contributions as bundles by doing the following: + +osgi> install file:./path/to/contribution_bundle.jar + +Note that contribution_bundle.jar will need an activator in order to register the bundle as a SCA contribution +see samples/???? +TODO is this still true + +Running on Felix +---------------- + +See http://tuscany.apache.org/documentation-2x/running-tuscany-sca-2x-with-equinox-and-felix.html diff --git a/sandbox/samples/running-tuscany/launcher-shell/README b/sandbox/samples/running-tuscany/launcher-shell/README new file mode 100644 index 0000000000..9745f57ad9 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/README @@ -0,0 +1,34 @@ +Sample Tuscany Shell +==================== + +This directory contains a sample shell program supporting simple commands to +start and stop SCA composites. + +To build the sample shell do this: +mvn install + +To run it: +./sca + +at the prompt: +start myNode ../../applications/store/target/sample-store.jar + +or: +start myNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar + +also try: +status +stop myNode +bye + +Starting and stopping composites is pretty fast. To see that, try the following +two scripts, which start/stop the sample store composite 10 times. + +./sca + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + sample-launcher-shell + Apache Tuscany SCA Sample Launcher Shell + war + + + + org.apache.tuscany.sca + tuscany-feature-api + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-core + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-webservice + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-feature-web20 + pom + 2.0-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-host-webapp + 2.0-SNAPSHOT + + + + junit + junit + 4.8.1 + test + + + + + + scashell + + diff --git a/sandbox/samples/running-tuscany/launcher-shell/sca b/sandbox/samples/running-tuscany/launcher-shell/sca new file mode 100755 index 0000000000..8f6cf268b3 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/sca @@ -0,0 +1,19 @@ +#!/bin/bash +# 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 + +java -classpath target/classes:`ls target/scashell/WEB-INF/lib/*.jar | awk '{ printf "%s:", $1}'` sample.Shell + diff --git a/sandbox/samples/running-tuscany/launcher-shell/sca.bat b/sandbox/samples/running-tuscany/launcher-shell/sca.bat new file mode 100644 index 0000000000..5110effc25 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/sca.bat @@ -0,0 +1,30 @@ +@echo off +rem Licensed to the Apache Software Foundation (ASF) under one +rem or more contributor license agreements. See the NOTICE file +rem distributed with this work for additional information +rem regarding copyright ownership. The ASF licenses this file +rem to you under the Apache License, Version 2.0 (the +rem "License"); you may not use this file except in compliance +rem with the License. You may obtain a copy of the License at +rem +rem http://www.apache.org/licenses/LICENSE-2.0 +rem +rem Unless required by applicable law or agreed to in writing, +rem software distributed under the License is distributed on an +rem "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +rem KIND, either express or implied. See the License for the +rem specific language governing permissions and limitations + +rem cd to target to reduce the length of the classpath. It blows up cmd.exe without this +cd target +set _CLASSPATH=.\classes +for %%i in (.\scashell\WEB-INF\lib\*.jar) do call:setClasspath %%i +set CLASSPATH=%_CLASSPATH% +@echo on +java sample.Shell +cd .. +goto:eof + +:setClasspath +set _CLASSPATH=%_CLASSPATH%;%1 +goto:eof \ No newline at end of file diff --git a/sandbox/samples/running-tuscany/launcher-shell/scripts/test-remote.txt b/sandbox/samples/running-tuscany/launcher-shell/scripts/test-remote.txt new file mode 100644 index 0000000000..dc13e5c401 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/scripts/test-remote.txt @@ -0,0 +1,36 @@ +# 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 + +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode +start testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +stop testNode diff --git a/sandbox/samples/running-tuscany/launcher-shell/scripts/test-start.txt b/sandbox/samples/running-tuscany/launcher-shell/scripts/test-start.txt new file mode 100644 index 0000000000..2514a9058d --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/scripts/test-start.txt @@ -0,0 +1,18 @@ +# 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 + +restart testNode http://people.apache.org/~jsdelfino/tuscany/java/test/sample-store.jar +status diff --git a/sandbox/samples/running-tuscany/launcher-shell/scripts/test-status.txt b/sandbox/samples/running-tuscany/launcher-shell/scripts/test-status.txt new file mode 100644 index 0000000000..4df56e85e8 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/scripts/test-status.txt @@ -0,0 +1,17 @@ +# 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 + +status diff --git a/sandbox/samples/running-tuscany/launcher-shell/scripts/test-stop.txt b/sandbox/samples/running-tuscany/launcher-shell/scripts/test-stop.txt new file mode 100644 index 0000000000..39eb36aa77 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/scripts/test-stop.txt @@ -0,0 +1,17 @@ +# 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 + +stop testNode diff --git a/sandbox/samples/running-tuscany/launcher-shell/scripts/test.txt b/sandbox/samples/running-tuscany/launcher-shell/scripts/test.txt new file mode 100644 index 0000000000..bf489a46a5 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/scripts/test.txt @@ -0,0 +1,36 @@ +# 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 + +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode +start testNode ../../applications/store/target/sample-store.jar +stop testNode diff --git a/sandbox/samples/running-tuscany/launcher-shell/src/main/java/sample/Shell.java b/sandbox/samples/running-tuscany/launcher-shell/src/main/java/sample/Shell.java new file mode 100644 index 0000000000..d0d8fb5dfe --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/src/main/java/sample/Shell.java @@ -0,0 +1,203 @@ +/* + * 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 sample; + +import static java.lang.System.in; +import static java.lang.System.out; +import static java.util.Collections.emptyList; +import static java.util.Collections.singletonList; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.PrintWriter; +import java.io.StringWriter; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.concurrent.Callable; + +import org.apache.tuscany.sca.node.Contribution; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; + +/** + * A little SCA command shell. + */ +public class Shell { + final NodeFactory nf; + + public static class Nodeconf { + final String name; + final String cloc; + final String dcuri; + final Node node; + + Nodeconf(final String name, final String cloc, final String dcuri, final Node node) { + this.name = name; + this.cloc = cloc; + this.dcuri = dcuri; + this.node = node; + } + + public String toString() { + return name + " " + cloc + (dcuri != null? " " + dcuri : ""); + } + } + + final Map nodes = new HashMap(); + final List history = new ArrayList(); + + public Shell(NodeFactory nf) { + this.nf = nf; + } + + List start(final String name, final String cloc, final String dcuri) { + if(nodes.containsKey(name)) + return emptyList(); + final Node node = dcuri != null? nf.createNode(dcuri, new Contribution(cloc, cloc)) : nf.createNode(new Contribution(cloc, cloc)); + nodes.put(name, new Nodeconf(name, cloc, dcuri, node)); + node.start(); + return emptyList(); + } + + List stop(final String name) { + final Nodeconf ninfo = nodes.get(name); + if(ninfo == null) + return emptyList(); + ninfo.node.stop(); + nodes.remove(name); + return emptyList(); + } + + List stop() { + for(Nodeconf ninfo: nodes.values()) + ninfo.node.stop(); + nodes.clear(); + return emptyList(); + } + + List restart(final String name, final String cloc, final String dcuri) { + final Nodeconf ninfo = nodes.get(name); + if(ninfo == null) + return start(name, cloc, dcuri); + ninfo.node.stop(); + nodes.remove(name); + if (cloc == null) + return start(ninfo.name, ninfo.cloc, ninfo.dcuri); + return start(name, cloc, dcuri); + } + + List status() { + return new ArrayList(nodes.values()); + } + + List history() { + return history; + } + + List bye() { + return null; + } + + List read(final BufferedReader r) throws IOException { + final String l = r.readLine(); + history.add(l); + return l != null ? Arrays.asList(l.split(" ")) : singletonList("bye"); + } + + Callable> eval(final List toks) { + final String op = toks.get(0); + if(op.equals("start")) + return new Callable>() { + public List call() { + return start(toks.get(1), toks.get(2), toks.size() >= 4? toks.get(3) : null); + } + }; + if(op.equals("stop")) + return new Callable>() { + public List call() { + if(toks.size() == 1) + return stop(); + return stop(toks.get(1)); + } + }; + if(op.equals("restart")) + return new Callable>() { + public List call() { + return restart(toks.get(1), toks.size() >= 3? toks.get(2) : null, toks.size() >= 4? toks.get(3) : null); + } + }; + if(op.equals("status")) + return new Callable>() { + public List call() { + return status(); + } + }; + if(op.equals("history")) + return new Callable>() { + public List call() { + return history(); + } + }; + if(op.equals("bye")) + return new Callable>() { + public List call() { + return bye(); + } + }; + return new Callable>() { + public List call() { + return emptyList(); + } + }; + } + + List apply(final Callable> func) { + try { + return func.call(); + } catch(Exception e) { + StringWriter sw = new StringWriter(); + e.printStackTrace(new PrintWriter(sw)); + return singletonList(sw); + } + } + + boolean print(final List l, PrintWriter w) { + if(l == null) + return false; + for(Object o: l) + w.println(o); + return true; + } + + public Map run(final BufferedReader r, final PrintWriter w) throws IOException { + while(print(apply(eval(read(r))), w)) + ; + r.close(); + return nodes; + } + + public static void main(final String[] args) throws Exception { + new Shell(NodeFactory.newInstance()).run(new BufferedReader(new InputStreamReader(in)), new PrintWriter(out, true)); + } +} diff --git a/sandbox/samples/running-tuscany/launcher-shell/src/main/java/sample/ShellServlet.java b/sandbox/samples/running-tuscany/launcher-shell/src/main/java/sample/ShellServlet.java new file mode 100644 index 0000000000..55aadbd09b --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/src/main/java/sample/ShellServlet.java @@ -0,0 +1,48 @@ +/* + * 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 sample; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.URL; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.apache.tuscany.sca.host.webapp.WebAppHelper; + +public class ShellServlet extends HttpServlet { + static final long serialVersionUID = 1L; + + Shell shell; + + public void init() { + shell = new Shell(WebAppHelper.getNodeFactory()); + } + + public void destroy() { + shell.stop(); + } + + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { + shell.run(new BufferedReader(new InputStreamReader(new URL(req.getParameter("conf")).openStream())), resp.getWriter()); + } +} diff --git a/sandbox/samples/running-tuscany/launcher-shell/src/main/webapp/WEB-INF/web.xml b/sandbox/samples/running-tuscany/launcher-shell/src/main/webapp/WEB-INF/web.xml new file mode 100644 index 0000000000..ac1ad1cc8e --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/src/main/webapp/WEB-INF/web.xml @@ -0,0 +1,48 @@ + + + + scashell + + org.apache.tuscany.sca.host.webapp.TuscanyContextListener + + + tuscany + org.apache.tuscany.sca.host.webapp.TuscanyServletFilter + + + + tuscany + /* + + + + ShellServlet + sample.ShellServlet + + + + ShellServlet + /run + + + + index.html + + diff --git a/sandbox/samples/running-tuscany/launcher-shell/src/main/webapp/index.html b/sandbox/samples/running-tuscany/launcher-shell/src/main/webapp/index.html new file mode 100644 index 0000000000..3d41472a46 --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-shell/src/main/webapp/index.html @@ -0,0 +1,42 @@ + + + +Sample Runtime Shell + + +

It works

+ +

This Web app runs a sample Tuscany runtime shell similar to samples/launcher-shell.
+To see how it works and what configuration commands are supported, just read the Shell program's source code.

+ +

Configuration commands can be provided through a text document served from a Web location, for example:
+http://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/samples/running-tuscany/launcher-shell/scripts/test-start.txt

+ +

To run that particular configuration script just point your Web browser to:
+http://localhost:8080/scashell/run?conf=http://svn.apache.org/repos/asf/tuscany/sca-java-2.x/trunk/samples/running-tuscany/launcher-shell/scripts/test-start.txt
+To run the script again and refresh the runtime shell, just refresh that page in your Web browser. +

+ +

This script starts the Tuscany sample store application. Click here to use that application after you've started it.

+ +

Sample configuration script samples are available in the Tuscany Subversion repository there. + + + diff --git a/sandbox/samples/running-tuscany/launcher-webapp/README b/sandbox/samples/running-tuscany/launcher-webapp/README new file mode 100644 index 0000000000..4031b9c0bd --- /dev/null +++ b/sandbox/samples/running-tuscany/launcher-webapp/README @@ -0,0 +1,29 @@ +To execute sample webapp based contributions (contributions that have webapp at the end of their name) you +can build the contribution using maven and then copy the resulting war file to your container of choice + +For example, for binding-jsonrpc/contribution-calculator-webapp, do the following + +cd samples/binding-jsonrpc/contribution-calculator-webapp +mvn +cp target/sample-contribution-binding-jsonrpc-calculator-webapp.war your_container_deployment-dir + + +As an alternative sample webapp based contributions can be run within Jetty directly from Maven, look for +webapp contributions that have the following configuration in their pom.xml file: + + + org.mortbay.jetty + maven-jetty-plugin + 6.1.18 + + +For contributions that have this, for example, binding-jsonrpc/contribution-calculator-webapp, do the following + +cd samples/binding-sca/contribution-calculator +mvn jetty:run + +This will launch the contribution in the Jetty runtime and then wait. At this point you can use +HTTP clients to send messages to services that the running SCA applcation exposes. For this +example try pointing your browser at: + +http://localhost:8080/sample-contribution-binding-jsonrpc-calculator-webapp/ diff --git a/sandbox/samples/running-tuscany/pom.xml b/sandbox/samples/running-tuscany/pom.xml new file mode 100644 index 0000000000..67b6a29eb3 --- /dev/null +++ b/sandbox/samples/running-tuscany/pom.xml @@ -0,0 +1,53 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-samples + 2.0-SNAPSHOT + ../pom.xml + + tuscany-samples-running-tuscany + pom + Apache Tuscany SCA Running Tuscany Samples + + + + default + + true + + + + + launcher-embedded-jse + launcher-embedded-osgi + launcher-embedded-osgi-base + launcher-shell + + + + + -- cgit v1.2.3