From d5f1d093fe6fa491cdec392dca7137639e98d149 Mon Sep 17 00:00:00 2001 From: jsdelfino Date: Mon, 15 Sep 2008 00:26:00 +0000 Subject: Pulled a recent revision of trunk into the sca-android branch, to apply the android patches from JIRA TUSCANY-2440 to it. git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@695318 13f79535-47bb-0310-9956-ffa450edef68 --- branches/sca-android/samples/binding-echo/README | 104 ++++++++++++ .../samples/binding-echo/binding-echo.png | Bin 0 -> 7846 bytes .../samples/binding-echo/binding-echo.svg | 174 +++++++++++++++++++++ .../sca-android/samples/binding-echo/build.xml | 75 +++++++++ branches/sca-android/samples/binding-echo/pom.xml | 71 +++++++++ .../binding-echo/src/main/java/echo/Echo.java | 29 ++++ .../src/main/java/echo/EchoBindingClient.java | 51 ++++++ .../src/main/java/echo/EchoComponentImpl.java | 44 ++++++ .../src/main/resources/EchoBinding.composite | 40 +++++ .../src/test/java/echo/EchoBindingTestCase.java | 57 +++++++ 10 files changed, 645 insertions(+) create mode 100644 branches/sca-android/samples/binding-echo/README create mode 100644 branches/sca-android/samples/binding-echo/binding-echo.png create mode 100644 branches/sca-android/samples/binding-echo/binding-echo.svg create mode 100644 branches/sca-android/samples/binding-echo/build.xml create mode 100644 branches/sca-android/samples/binding-echo/pom.xml create mode 100644 branches/sca-android/samples/binding-echo/src/main/java/echo/Echo.java create mode 100644 branches/sca-android/samples/binding-echo/src/main/java/echo/EchoBindingClient.java create mode 100644 branches/sca-android/samples/binding-echo/src/main/java/echo/EchoComponentImpl.java create mode 100644 branches/sca-android/samples/binding-echo/src/main/resources/EchoBinding.composite create mode 100644 branches/sca-android/samples/binding-echo/src/test/java/echo/EchoBindingTestCase.java (limited to 'branches/sca-android/samples/binding-echo') diff --git a/branches/sca-android/samples/binding-echo/README b/branches/sca-android/samples/binding-echo/README new file mode 100644 index 0000000000..2772460cc6 --- /dev/null +++ b/branches/sca-android/samples/binding-echo/README @@ -0,0 +1,104 @@ +Binding Echo Sample Application +=============================== +This sample demonstrates how to use the new binding extension +binding-echo-extension. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +If you just want to run it to see what happens, open a command prompt, +navigate to this sample directory, and do + +ant run + +OR if you don't have ant, on Windows do + +java -cp ..\..\lib\tuscany-sca-manifest.jar;..\binding-echo-extension\target\sample-binding-echo-extension.jar;target\sample-binding-echo.jar echo.EchoBindingClient + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:../binding-echo-extension/target/sample-binding-echo-extension.jar:target/sample-binding-echo.jar echo.EchoBindingClient + +This looks like a long command. The three things we add to the classpath are + +tuscany-sca-manifest.jar - all of the standard Tuscany SCA runtime and + extension classes +sample-binding-echo-extension.jar - the new echo binding extension implementation +sample-binding-echo - the application that uses the echo binding + +Note: this sample currently is not working on Linux + +Sample Overview +--------------- +This sample contains an application (client and server code) that uses +an SCA binding that simply echoes back any messages that are sent to it. + +binding-echo/ + src/ + main/ + java/ + echo/ + Echo.java - interface definition for the sample + reference and service + EchoComponentImpl.java - sample component implementation with + echo binding reference + EchoBindingClient.java - sample client + resources/ + EchoBinding.composite - the SCA assembly for this sample + test/ + java/ + echo + EchoBindingTestCase.java - sample JUnit test case for the sample + client + binding-echo.png - 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 and run using Ant as +follows. + +cd binding-echo +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Passing thro invoker... + [java] Returned message: foo + [java] Echo reference = foo + [java] Passing thro invoker... + [java] Returned message: bar + [java] Echo service = bar + + +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 binding-echo +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running echo.EchoBindingTestCase +Passing thro invoker... +Returned message: foo +Passing thro invoker... +Returned message: bar +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.811 sec + +Results : + +Tests run: 2, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. diff --git a/branches/sca-android/samples/binding-echo/binding-echo.png b/branches/sca-android/samples/binding-echo/binding-echo.png new file mode 100644 index 0000000000..a38d985363 Binary files /dev/null and b/branches/sca-android/samples/binding-echo/binding-echo.png differ diff --git a/branches/sca-android/samples/binding-echo/binding-echo.svg b/branches/sca-android/samples/binding-echo/binding-echo.svg new file mode 100644 index 0000000000..5b5051bef5 --- /dev/null +++ b/branches/sca-android/samples/binding-echo/binding-echo.svg @@ -0,0 +1,174 @@ + + + + + + + + + + image/svg+xml + + + + + + + + EchoBinding + + + EchoComponent + + + + EchoSerivce EchoReference + + + diff --git a/branches/sca-android/samples/binding-echo/build.xml b/branches/sca-android/samples/binding-echo/build.xml new file mode 100644 index 0000000000..7689ef3a54 --- /dev/null +++ b/branches/sca-android/samples/binding-echo/build.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-android/samples/binding-echo/pom.xml b/branches/sca-android/samples/binding-echo/pom.xml new file mode 100644 index 0000000000..9c14b5d4c3 --- /dev/null +++ b/branches/sca-android/samples/binding-echo/pom.xml @@ -0,0 +1,71 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.4-SNAPSHOT + ../../pom.xml + + sample-binding-echo + Apache Tuscany SCA Echo Binding Sample Application + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + sample-binding-echo-extension + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.4-SNAPSHOT + runtime + + + + junit + junit + 4.2 + test + + + + + + ${artifactId} + + + diff --git a/branches/sca-android/samples/binding-echo/src/main/java/echo/Echo.java b/branches/sca-android/samples/binding-echo/src/main/java/echo/Echo.java new file mode 100644 index 0000000000..1d5e973f33 --- /dev/null +++ b/branches/sca-android/samples/binding-echo/src/main/java/echo/Echo.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 echo; + +/** + * Interface of our sample Echo service. + * + * @version $Rev$ $Date$ + */ +public interface Echo { + + String echo(String msg); +} diff --git a/branches/sca-android/samples/binding-echo/src/main/java/echo/EchoBindingClient.java b/branches/sca-android/samples/binding-echo/src/main/java/echo/EchoBindingClient.java new file mode 100644 index 0000000000..21bdff4011 --- /dev/null +++ b/branches/sca-android/samples/binding-echo/src/main/java/echo/EchoBindingClient.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 echo; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import echo.server.EchoServer; + +/** + * This client program shows how to create an SCA runtime, start it, + * and locate and invoke a SCA component + * @version $Rev$ $Date$ + */ +public class EchoBindingClient { + + public static void main(String[] args) throws Exception { + + SCADomain scaDomain = SCADomain.newInstance("EchoBinding.composite"); + + // Call the echo service component which will, in turn, call a reference + // with an echo binding. The echo binding will echo the given string. + Echo service = scaDomain.getService(Echo.class, "EchoComponent"); + String echoString = service.echo("foo"); + System.out.println("Echo reference = " + echoString ); + + // Call the echo server. This will dispatch the call to a service with an + // echo binding. The echo binding will pass the call to the echo component. + echoString = EchoServer.getServer().sendReceive("http://tempuri.org", "bar"); + System.out.println("Echo service = " + echoString ); + + scaDomain.close(); + + } + +} diff --git a/branches/sca-android/samples/binding-echo/src/main/java/echo/EchoComponentImpl.java b/branches/sca-android/samples/binding-echo/src/main/java/echo/EchoComponentImpl.java new file mode 100644 index 0000000000..ba68dfe908 --- /dev/null +++ b/branches/sca-android/samples/binding-echo/src/main/java/echo/EchoComponentImpl.java @@ -0,0 +1,44 @@ +/* + * 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 echo; + +import org.osoa.sca.annotations.Constructor; +import org.osoa.sca.annotations.Reference; + + +/** + * A simple client component that uses a reference with an Echo binding. + * + * @version $Rev$ $Date$ + */ +public class EchoComponentImpl implements Echo { + + private Echo echoReference; + + @Constructor + public EchoComponentImpl(@Reference(name = "echoReference", required = true) Echo echoReference) { + this.echoReference = echoReference; + } + + public String echo(String msg) { + String result = echoReference.echo(msg); + System.out.println("Returned message: "+ result); + return result; + } +} diff --git a/branches/sca-android/samples/binding-echo/src/main/resources/EchoBinding.composite b/branches/sca-android/samples/binding-echo/src/main/resources/EchoBinding.composite new file mode 100644 index 0000000000..94612fb325 --- /dev/null +++ b/branches/sca-android/samples/binding-echo/src/main/resources/EchoBinding.composite @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-android/samples/binding-echo/src/test/java/echo/EchoBindingTestCase.java b/branches/sca-android/samples/binding-echo/src/test/java/echo/EchoBindingTestCase.java new file mode 100644 index 0000000000..1a597fc80f --- /dev/null +++ b/branches/sca-android/samples/binding-echo/src/test/java/echo/EchoBindingTestCase.java @@ -0,0 +1,57 @@ +/* + * 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 echo; + +import junit.framework.TestCase; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +import echo.Echo; +import echo.server.EchoServer; + +public class EchoBindingTestCase extends TestCase { + + private SCADomain scaDomain; + + @Override + protected void setUp() throws Exception { + scaDomain = SCADomain.newInstance("EchoBinding.composite"); + } + + @Override + protected void tearDown() throws Exception { + scaDomain.close(); + } + + public void testReference() throws Exception { + // Call the echo service component which will, in turn, call a reference + // with an echo binding. The echo binding will echo the given string. + Echo service = scaDomain.getService(Echo.class, "EchoComponent"); + String echoString = service.echo("foo"); + assertEquals(echoString, "foo"); + } + + public void testService() throws Exception { + // Call the echo server. This will dispatch the call to a service with an + // echo binding. The echo binding will pass the call to the echo component. + String echoString = EchoServer.getServer().sendReceive("http://tempuri.org", "bar"); + assertEquals(echoString, "bar"); + } +} -- cgit v1.2.3