From 9425990f532b1152c2d73db96c0f07ef5216a3d1 Mon Sep 17 00:00:00 2001 From: lresende Date: Thu, 12 Nov 2009 00:43:48 +0000 Subject: Moving 2.x contribs git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835178 13f79535-47bb-0310-9956-ffa450edef68 --- .../samples/helloworld-ws-service-jms/README | 119 ++++++++++++++++ .../samples/helloworld-ws-service-jms/build.xml | 72 ++++++++++ .../helloworld-ws-service.png | Bin 0 -> 6531 bytes .../helloworld-ws-service.svg | 150 +++++++++++++++++++++ .../samples/helloworld-ws-service-jms/pom.xml | 87 ++++++++++++ .../src/main/java/helloworld/HelloWorldImpl.java | 33 +++++ .../src/main/java/helloworld/HelloWorldServer.java | 60 +++++++++ .../main/java/helloworld/HelloWorldService.java | 31 +++++ .../src/main/resources/definitions.xml | 66 +++++++++ .../src/main/resources/helloworldwsjms.composite | 35 +++++ .../main/resources/helloworldwsjmspolicy.composite | 34 +++++ .../src/main/resources/wsdl/helloworld.wsdl | 92 +++++++++++++ .../HelloWorldJmsPolicyServerTestCase.java | 68 ++++++++++ .../helloworld/HelloWorldJmsServerTestCase.java | 72 ++++++++++ 14 files changed, 919 insertions(+) create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/README create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/build.xml create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/helloworld-ws-service.png create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/helloworld-ws-service.svg create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/pom.xml create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldImpl.java create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldServer.java create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldService.java create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/definitions.xml create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/helloworldwsjms.composite create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/helloworldwsjmspolicy.composite create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/wsdl/helloworld.wsdl create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java create mode 100644 sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCase.java (limited to 'sca-java-2.x/contrib/samples/helloworld-ws-service-jms') diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/README b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/README new file mode 100644 index 0000000000..26272b1d91 --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/README @@ -0,0 +1,119 @@ +Hello World SOAP/JMS Service Sample +=================================== +This sample demonstrates an SCA service that uses a web service binding using +a SOAP/JMS protocol + +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;target\sample-helloworld-ws-service-jms.jar helloworld.HelloWorldServer + +and on *nix do + +java -cp ../../lib/tuscany-sca-manifest.jar:target/sample-helloworld-ws-service-jms.jar helloworld.HelloWorldServer + +Now the server is started you can use the helloworld-ws-reference-jms sample to +exercise it. + +Sample Overview +--------------- +The sample provides a single component that is wired to a service with a +web service binding. + +helloworld-ws-service-jms/ + src/ + main/ + java/ + helloworld/ + HelloWorldService.java - interface description for + HelloWorldServiceComponent + HelloWorldImpl.java - component implementation + HelloWorldServer.java - starts the SCA Runtime and + deploys the helloworldwsjms + .composite and then waits for the + service to be called via web services + resources/ + wsdl/ + helloworld.wsdl - the service description that describes + the exposed service + helloworldwsjms.composite - the SCA assembly for this sample + helloworldwsjmspolicy.composite - shows how the protocol can be + selected using policy. Not run + by the sample + test/ + java/ + helloworld/ + HelloWorldJMSServerTestCase.java- JUnit test case + HelloWorldJMSPolicyServerTestCase.java- JUnit test case + helloworld-ws-service.png - a pictorial representation of the + sample .composite file + build.xml - the Ant build file + pom.xml - the Maven build file + +Building And Running The Sample Using Ant +----------------------------------------- +With the binary distribution the sample can be built and run using Ant using the +following commands + +cd helloworld-ws-service-jms +ant compile +ant run + +You should see the following output from the run target. + +run: + [java] log4j:WARN No appenders could be found for logger (org.apache.axiom. +om.util.StAXUtils). + [java] log4j:WARN Please initialize the log4j system properly. + [java] HelloWorld server started (press enter to shutdown) + +As this point the SCA service is exposed as a web service by a web server +started automatically by the SCA runtime. To stop the server just press +enter. + +To exercise the service run up the helloworld-ws-reference-jms sample. Take a look at +the README in that sample and you will see you need the following commands + +cd helloworld-ws-reference-jms +ant run + +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. When using Maven you don't need to run the helloworld- +ws-reference-jms sample as Maven includes a simple ping test to make sure that the +service is available + +cd helloworld-ws-service-jms +mvn + +You should see the following output from the test phase. + +------------------------------------------------------- + T E S T S +------------------------------------------------------- +Running helloworld.HelloWorldJmsPolicyServerTestCase +08-Jan-2008 10:41:17 org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceProvide +r start +INFO: Axis2 JMS URL=jms:/HelloWorldServiceComponent?java.naming.factory.initial= +org.apache.activemq.jndi.ActiveMQInitialContextFactory&java.naming.provider.url= +tcp://localhost:61619&transport.jms.ConnectionFactoryJNDIName=QueueConnectionFac +tory +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 6.984 sec +Running helloworld.HelloWorldJmsServerTestCase +08-Jan-2008 10:41:22 org.apache.tuscany.sca.binding.ws.axis2.Axis2ServiceProvide +r start +INFO: Axis2 JMS URL=jms:/queue.sample?transport.jms.ConnectionFactoryJNDIName=Qu +eueConnectionFactory&java.naming.factory.initial=org.apache.activemq.jndi.Active +MQInitialContextFactory&java.naming.provider.url=tcp://localhost:61619 +Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 5.266 sec + +This shows that the Junit test cases have run successfully. diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/build.xml b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/build.xml new file mode 100644 index 0000000000..330de7f7e5 --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/build.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/helloworld-ws-service.png b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/helloworld-ws-service.png new file mode 100644 index 0000000000..eab29d0bcd Binary files /dev/null and b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/helloworld-ws-service.png differ diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/helloworld-ws-service.svg b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/helloworld-ws-service.svg new file mode 100644 index 0000000000..8d2ae98c82 --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/helloworld-ws-service.svg @@ -0,0 +1,150 @@ + + + + + + + + + + image/svg+xml + + + + + + + + helloworldws + + HelloWorldServiceComponent + + HelloWorldWebService + + diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/pom.xml b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/pom.xml new file mode 100644 index 0000000000..90f3e7f297 --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/pom.xml @@ -0,0 +1,87 @@ + + + + 4.0.0 + + org.apache.tuscany.sca + tuscany-sca + 2.0-SNAPSHOT + ../../pom.xml + + sample-helloworld-ws-service-jms + Apache Tuscany SCA HelloWorld Web Service JMS Sample + + + + apache.incubator + http://people.apache.org/repo/m2-incubating-repository + + + + + + org.apache.tuscany.sca + tuscany-host-jetty + 2.0-SNAPSHOT + compile + + + + org.apache.tuscany.sca + tuscany-host-embedded + 2.0-SNAPSHOT + compile + + + + org.apache.activemq + activemq-core + 4.1.1 + compile + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + 2.0-SNAPSHOT + runtime + + + + org.apache.tuscany.sca + tuscany-binding-ws-axis2 + 2.0-SNAPSHOT + runtime + + + + junit + junit + 4.5 + test + + + + + + ${artifactId} + + + diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldImpl.java b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldImpl.java new file mode 100644 index 0000000000..2186c00e57 --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldImpl.java @@ -0,0 +1,33 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package helloworld; + +import org.oasisopen.sca.annotation.Service; + +/** + * This class implements the HelloWorld service. + */ +@Service(HelloWorldService.class) +public class HelloWorldImpl implements HelloWorldService { + + public String getGreetings(String name) { + return "Hello " + name; + } + +} diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldServer.java b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldServer.java new file mode 100644 index 0000000000..5454487ff6 --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldServer.java @@ -0,0 +1,60 @@ +/* + * 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 helloworld; + +import java.io.IOException; + +import org.apache.activemq.broker.BrokerService; +import org.apache.tuscany.sca.host.embedded.SCADomain; + +/** + * This server program shows how to create an SCA runtime, and start it which + * activates the helloworld Web service endpoint. + */ +public class HelloWorldServer { + + protected static BrokerService startBroker() throws Exception { + BrokerService jmsBroker = new BrokerService(); + jmsBroker.setPersistent(false); + jmsBroker.setUseJmx(false); + jmsBroker.addConnector("tcp://localhost:61619"); + jmsBroker.start(); + return jmsBroker; + } + + public static void main(String[] args) throws Exception { + + BrokerService broker = startBroker(); + SCADomain scaDomain = SCADomain.newInstance("helloworldwsjms.composite"); + + try { + System.out.println("HelloWorld server started (press enter to shutdown)"); + System.in.read(); + } catch (IOException e) { + e.printStackTrace(); + } + + scaDomain.close(); + broker.stop(); + System.out.println("HelloWorld server stopped"); + // FIXME: Workaround for http://issues.apache.org/jira/browse/AXIS2-3685 + System.exit(0); + } + +} diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldService.java b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldService.java new file mode 100644 index 0000000000..a0081be22d --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/java/helloworld/HelloWorldService.java @@ -0,0 +1,31 @@ +/* + * 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 helloworld; + +import org.oasisopen.sca.annotation.Remotable; + +/** + * This is the business interface of the HelloWorld greetings service. + */ +@Remotable +public interface HelloWorldService { + + public String getGreetings(String name); +} + diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/definitions.xml b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/definitions.xml new file mode 100644 index 0000000000..8c881ab0bb --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/definitions.xml @@ -0,0 +1,66 @@ + + + + + + + The general intent that a transport is available over which SOAP messages flow + + + + + + A JMS transport is required + + + + + + An HTTP transport is required + + + + + + + An HTTPS transport is required + + + + + + + org.apache.activemq.jndi.ActiveMQInitialContextFactory + tcp://localhost:61619 + QueueConnectionFactory + + + + + \ No newline at end of file diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/helloworldwsjms.composite b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/helloworldwsjms.composite new file mode 100644 index 0000000000..67079f738e --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/helloworldwsjms.composite @@ -0,0 +1,35 @@ + + + + + + + + + + + + + diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/helloworldwsjmspolicy.composite b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/helloworldwsjmspolicy.composite new file mode 100644 index 0000000000..10faf374f3 --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/helloworldwsjmspolicy.composite @@ -0,0 +1,34 @@ + + + + + + + + + + + + + diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/wsdl/helloworld.wsdl b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/wsdl/helloworld.wsdl new file mode 100644 index 0000000000..3f9e00689e --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/main/resources/wsdl/helloworld.wsdl @@ -0,0 +1,92 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java new file mode 100644 index 0000000000..34f8605d5d --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/test/java/helloworld/HelloWorldJmsPolicyServerTestCase.java @@ -0,0 +1,68 @@ +/* + * 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 helloworld; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +import java.io.IOException; + +import org.apache.activemq.broker.BrokerService; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests that the helloworld server is available + */ +public class HelloWorldJmsPolicyServerTestCase{ + + private SCADomain scaDomain; + private BrokerService jmsBroker; + + @Before + public void startServer() throws Exception { + startBroker(); + scaDomain = SCADomain.newInstance("helloworldwsjmspolicy.composite"); + } + + protected void startBroker() throws Exception { + jmsBroker = new BrokerService(); + jmsBroker.setPersistent(false); + jmsBroker.setUseJmx(false); + jmsBroker.addConnector("tcp://localhost:61619"); + jmsBroker.start(); + } + + @Test + public void testServiceCall() throws IOException { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldServiceComponent/HelloWorldService"); + assertNotNull(helloWorldService); + assertEquals("Hello Smith", helloWorldService.getGreetings("Smith")); + } + + @After + public void stopServer() throws Exception { + scaDomain.close(); + if (jmsBroker != null) { + jmsBroker.stop(); + } + } +} diff --git a/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCase.java b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCase.java new file mode 100644 index 0000000000..03d566cc17 --- /dev/null +++ b/sca-java-2.x/contrib/samples/helloworld-ws-service-jms/src/test/java/helloworld/HelloWorldJmsServerTestCase.java @@ -0,0 +1,72 @@ +/* + * 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 helloworld; + +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertNotNull; + +import java.io.IOException; + +import org.apache.activemq.broker.BrokerService; +import org.apache.tuscany.sca.host.embedded.SCADomain; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +/** + * Tests that the helloworld server is available + */ +public class HelloWorldJmsServerTestCase{ + + private SCADomain scaDomain; + private BrokerService jmsBroker; + + @Before + public void startServer() throws Exception { + startBroker(); + scaDomain = SCADomain.newInstance("helloworldwsjms.composite"); + } + + protected void startBroker() throws Exception { + jmsBroker = new BrokerService(); + jmsBroker.setPersistent(false); + jmsBroker.setUseJmx(false); + jmsBroker.addConnector("tcp://localhost:61619"); + jmsBroker.start(); + } + + @Test + public void testServiceCall() throws IOException { + HelloWorldService helloWorldService = scaDomain.getService(HelloWorldService.class, "HelloWorldServiceComponent/HelloWorldService"); + assertNotNull(helloWorldService); + + assertEquals("Hello Smith", helloWorldService.getGreetings("Smith")); + } + + @After + public void stopServer() throws Exception { + if (scaDomain != null) { + scaDomain.close(); + } + if (jmsBroker != null) { + jmsBroker.stop(); + } + } + +} -- cgit v1.2.3