From eed639ccf7fd95e0b31caf61787126e69592f207 Mon Sep 17 00:00:00 2001 From: ramkumar Date: Tue, 2 Dec 2008 11:17:24 +0000 Subject: Branch for 1.4 git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@722428 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/binding-notification-producer/README | 133 +++++++++++++++++++++ .../binding-notification-producer.png | Bin 0 -> 21631 bytes .../binding-notification-producer/build.xml | 75 ++++++++++++ .../samples/binding-notification-producer/pom.xml | 127 ++++++++++++++++++++ .../notification/producer/TestCaseProducer.java | 24 ++++ .../notification/producer/TrafficAdvisory.java | 30 +++++ .../producer/TrafficAdvisoryProducer.java | 36 ++++++ .../producer/TrafficAdvisoryServer.java | 57 +++++++++ .../TrafficAdvisoryNotification.componentType | 34 ++++++ .../TrafficAdvisoryNotification.composite | 44 +++++++ .../src/main/resources/wsdl/TrafficAdvisory.wsdl | 50 ++++++++ .../producer/TrafficAdvisoryTestCase.java | 78 ++++++++++++ 12 files changed, 688 insertions(+) create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/README create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/binding-notification-producer.png create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/build.xml create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/pom.xml create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TestCaseProducer.java create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisory.java create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisoryProducer.java create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisoryServer.java create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/TrafficAdvisoryNotification.componentType create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/TrafficAdvisoryNotification.composite create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/wsdl/TrafficAdvisory.wsdl create mode 100644 branches/sca-java-1.4/samples/binding-notification-producer/src/test/java/notification/producer/TrafficAdvisoryTestCase.java (limited to 'branches/sca-java-1.4/samples/binding-notification-producer') diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/README b/branches/sca-java-1.4/samples/binding-notification-producer/README new file mode 100644 index 0000000000..c5f284d4c5 --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/README @@ -0,0 +1,133 @@ +Notification Producer Binding Sample +=============================== + +This sample illustrates the use of with a +remote producer. + +The README in the samples directory (the directory above this) provides +general instructions about building and running samples. Take a look there +first. + +Sample Overview +--------------- + +This sample illustrates the use of a notification producer that is located in a +separate (and remote) composite with respect to any consumers. As such, this sample +is run in conjunction with the binding-notification-consumer sample, the +binding-notification-broker sample, or both. Take a look at the composite file +or the .svg file which shows the composite file in pictorial form. The composite +reference, referred to by the notification component, has a +that handles the remote communication. This binding includes an 'ntm' attribute +that refers to the notification type manager, which manages the connectivity of +producers, consumers and brokers, and which (for this sample) is assumed to be +running on http://localhost:8083. The ntm is a system component that is included in +and runs as part of the binding-notification module. +This sample also illustrates the use of a wsdl interface in the notification +component's . This allows messages sent and received +via to be transported as literal xml over http. + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant as +follows + +cd binding-notification-producer +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] Sep 14, 2007 10:31:45 AM org.apache.tuscany.sca.http.jetty.JettyServer addServletMapping + [java] INFO: Added Servlet mapping: http://localhost:8083/ntm/trafficAdvisory + [java] Sep 14, 2007 10:31:45 AM org.apache.tuscany.sca.http.jetty.JettyServer addServletMapping + [java] INFO: Added Servlet mapping: http://localhost:8083/producer/trafficAdvisory + +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-notification-producer +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running notification.producer.TrafficAdvisoryTestCase +Only instantiating and closing domain ... +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 1.252 sec + +Results : + +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0 + +This shows that the Junit test cases have run successfully. + +Sample Usage +------------ + +This sample is run using the tuscany binary distribution. To run it, navigate to this sample's directory and + +on Wondows, use following command: + +java -Dnotification.httpPort=8083 -cp ..\..\lib\tuscany-sca-manifest.jar;target\sample-binding-notification-producer.jar notification.producer.TrafficAdvisoryServer + +on *nix, use following command: + +java -Dnotification.httpPort=8083 -cp ../../lib/tuscany-sca-manifest.jar:target/sample-binding-notification-producer.jar notification.producer.TrafficAdvisoryServer + +this should bring up the following prompt: + +Send a report value, ^C or to end + +at this point you should be able to type a message to send, for instance: + +Traffic congestion + +Notice that before you try to send any message, you should bring up the +consumer sample or the broker sample. When you have finished using this +sample, type 'end' or ^C to end. + +Also notice that '-Dnotification.httpPort=8083' is used in the java command. +This indicates the port the sample should use. This also says that this server +is going to play the role of ntm, given our previous assumption. It is important +that the first one of the producer, consumer or broker sample that is run be the +one that uses '-Dnotification.httpPort=8083', otherwise there is no ntm to talk +to and an exception will be thrown. + +Sample directory structure: +--------------------------- + +binding-notification-producer/ + src/ + main/ + java/ + notification.producer/ + TestCaseProducer.java - interface for the producer component + TrafficAdvisory.java - remote interface referred to by the producer component + TrafficAdvisoryProducer.java - implementation for the producer component + TrafficAdvisoryServer.java - server class including main entry point + resources/ + wsdl/ + TrafficAdvisory.wsdl - remote interface for the notification component + TrafficAdvisoryNotification.componentType - the component type referred to by + + TrafficAdvisoryNotification.composite - the main composite including producer and + notification components, and composite reference + test/ + java/ + notification.producer/ + TrafficAdvisoryTestCase.java - JUnit test case + resources/ + wsdl/ + TrafficAdvisory.wsdl - remote interface for the notification component + TrafficAdvisoryNotification.componentType - the component type referred to by + + TrafficAdvisoryNotification.composite - the main composite including producer and + notification components, and composite reference + binding-notification-producer.png - a pictorial representation of the sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/binding-notification-producer.png b/branches/sca-java-1.4/samples/binding-notification-producer/binding-notification-producer.png new file mode 100644 index 0000000000..34c347c893 Binary files /dev/null and b/branches/sca-java-1.4/samples/binding-notification-producer/binding-notification-producer.png differ diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/build.xml b/branches/sca-java-1.4/samples/binding-notification-producer/build.xml new file mode 100644 index 0000000000..d13e4c8a6c --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/build.xml @@ -0,0 +1,75 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/pom.xml b/branches/sca-java-1.4/samples/binding-notification-producer/pom.xml new file mode 100644 index 0000000000..84ba74d315 --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/pom.xml @@ -0,0 +1,127 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 1.4-SNAPSHOT + ../../pom.xml + + sample-binding-notification-producer + Apache Tuscany SCA Sample Notification Binding Producer + 1.4-SNAPSHOT + A sample illustrating use of binding.notification + + + + org.apache.tuscany.sca + tuscany-implementation-notification + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-notification + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-host-embedded + 1.4-SNAPSHOT + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 1.4-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-interface-wsdl-xml + 1.4-SNAPSHOT + runtime + + + + javax.servlet + servlet-api + 2.5 + provided + + + + org.apache.tuscany.sca + tuscany-host-jetty + 1.4-SNAPSHOT + runtime + + + + junit + junit + 4.5 + test + + + + + ${artifactId} + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.5 + 1.5 + + + + org.apache.maven.plugins + maven-jar-plugin + + + + org.apache.tuscany.notification.remoteProducer.TrafficAdvisoryServer + + + + + + org.apache.maven.plugins + maven-surefire-plugin + + + + notification.httpPort + 8083 + + + + + + install + + diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TestCaseProducer.java b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TestCaseProducer.java new file mode 100644 index 0000000000..be80e71249 --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TestCaseProducer.java @@ -0,0 +1,24 @@ +/* + * 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 notification.producer; + +public interface TestCaseProducer { + + public void produceTrafficNotification(String report); +} diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisory.java b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisory.java new file mode 100644 index 0000000000..39f06d5dde --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisory.java @@ -0,0 +1,30 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package notification.producer; + +import org.osoa.sca.annotations.Remotable; + +/** + * @version $Rev$ $Date$ + */ +@Remotable +public interface TrafficAdvisory { + + void trafficNotification(String report); +} diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisoryProducer.java b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisoryProducer.java new file mode 100644 index 0000000000..7d49b00607 --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisoryProducer.java @@ -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 + * under the License. + */ +package notification.producer; + +import org.osoa.sca.annotations.Reference; +import org.osoa.sca.annotations.Scope; +import org.osoa.sca.annotations.Service; + +@Service(TestCaseProducer.class) +@Scope("COMPOSITE") +public class TrafficAdvisoryProducer implements TestCaseProducer { + + @Reference + protected TrafficAdvisory destination; + + public void produceTrafficNotification(String report) { + + destination.trafficNotification(report); + } +} diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisoryServer.java b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisoryServer.java new file mode 100644 index 0000000000..efd3657dc3 --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/java/notification/producer/TrafficAdvisoryServer.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 notification.producer; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; + +import org.apache.tuscany.sca.host.embedded.SCADomain; + +public class TrafficAdvisoryServer { + + public static void main(String[] args) { + try { + SCADomain domain = SCADomain.newInstance("TrafficAdvisoryNotification.composite"); + TestCaseProducer testCaseProducer = domain.getService(TestCaseProducer.class, "TrafficAdvisoryProducer"); + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String value = ""; + if (args.length == 1) { + value = args[0]; + } + do { + if(value == null || value.equals("end")) { + break; + } + try { + System.out.println("Send a report value, ^C or to end"); + value = reader.readLine(); + } catch (IOException e) { + e.printStackTrace(); + } + testCaseProducer.produceTrafficNotification("Report value [" + value + "]"); + } + while(true); + + domain.close(); + } catch(Throwable e) { + e.printStackTrace(); + } + } +} diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/TrafficAdvisoryNotification.componentType b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/TrafficAdvisoryNotification.componentType new file mode 100644 index 0000000000..2dc70f8ed1 --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/TrafficAdvisoryNotification.componentType @@ -0,0 +1,34 @@ + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/TrafficAdvisoryNotification.composite b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/TrafficAdvisoryNotification.composite new file mode 100644 index 0000000000..2db6ea655b --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/TrafficAdvisoryNotification.composite @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/wsdl/TrafficAdvisory.wsdl b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/wsdl/TrafficAdvisory.wsdl new file mode 100644 index 0000000000..b823bbebcc --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/src/main/resources/wsdl/TrafficAdvisory.wsdl @@ -0,0 +1,50 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/branches/sca-java-1.4/samples/binding-notification-producer/src/test/java/notification/producer/TrafficAdvisoryTestCase.java b/branches/sca-java-1.4/samples/binding-notification-producer/src/test/java/notification/producer/TrafficAdvisoryTestCase.java new file mode 100644 index 0000000000..d3901ee407 --- /dev/null +++ b/branches/sca-java-1.4/samples/binding-notification-producer/src/test/java/notification/producer/TrafficAdvisoryTestCase.java @@ -0,0 +1,78 @@ +/* + * 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 notification.producer; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import notification.producer.TestCaseProducer; + +import org.apache.tuscany.sca.host.embedded.SCADomain; +//import org.apache.tuscany.sca.notification.remoteProducer.TestCaseProducer; + +import junit.framework.TestCase; + +public class TrafficAdvisoryTestCase extends TestCase { + + private SCADomain domain; + + public void testTrafficAdvisoryNotification() throws Exception { + System.out.println("Only instantiating and closing domain ..."); + TestCaseProducer testCaseProducer = domain.getService(TestCaseProducer.class, "TrafficAdvisoryProducer"); + + /* Uncomment to test with consumer + BufferedReader reader = new BufferedReader(new InputStreamReader(System.in)); + String value = "foo"; + do { + try { + System.out.println("Send a report value, ^C or to end"); + value = reader.readLine(); + } catch (Exception e) { + e.printStackTrace(); + } + if(value == null || value.equals("end")) { + break; + } + testCaseProducer.produceTrafficNotification("Report value [" + value + "]"); + value = "end"; + } + while(true); + */ + } + + @Override + protected void setUp() throws Exception { + try { + domain = SCADomain.newInstance("TrafficAdvisoryNotification.composite"); + } catch(Throwable e) { + e.printStackTrace(); + if (e instanceof Exception) { + throw (Exception)e; + } + else { + throw new Exception(e); + } + } + } + + @Override + protected void tearDown() throws Exception { + domain.close(); + } +} -- cgit v1.2.3