You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by rf...@apache.org on 2009/04/07 23:08:53 UTC
svn commit: r762966 - in /tuscany/java/sca/samples:
dosgi-calculator-operations/
dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/
dosgi-calculator/ dosgi-calculator/src/main/java/calculator/rmi/
dosgi-calculator/src/main/reso...
Author: rfeng
Date: Tue Apr 7 21:08:52 2009
New Revision: 762966
URL: http://svn.apache.org/viewvc?rev=762966&view=rev
Log:
Expose the CalculatorService as a web service
Modified:
tuscany/java/sca/samples/dosgi-calculator-operations/pom.xml
tuscany/java/sca/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/CalculatorOSGiNodeTestCase.java
tuscany/java/sca/samples/dosgi-calculator/pom.xml
tuscany/java/sca/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java
tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType
tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite
tuscany/java/sca/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java
Modified: tuscany/java/sca/samples/dosgi-calculator-operations/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/dosgi-calculator-operations/pom.xml?rev=762966&r1=762965&r2=762966&view=diff
==============================================================================
--- tuscany/java/sca/samples/dosgi-calculator-operations/pom.xml (original)
+++ tuscany/java/sca/samples/dosgi-calculator-operations/pom.xml Tue Apr 7 21:08:52 2009
@@ -48,7 +48,7 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-impl-osgi</artifactId>
<version>2.0-SNAPSHOT</version>
- <scope>test</scope>
+ <scope>runtime</scope>
</dependency>
<dependency>
Modified: tuscany/java/sca/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/CalculatorOSGiNodeTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/CalculatorOSGiNodeTestCase.java?rev=762966&r1=762965&r2=762966&view=diff
==============================================================================
--- tuscany/java/sca/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/CalculatorOSGiNodeTestCase.java (original)
+++ tuscany/java/sca/samples/dosgi-calculator-operations/src/test/java/calculator/dosgi/operations/test/CalculatorOSGiNodeTestCase.java Tue Apr 7 21:08:52 2009
@@ -34,6 +34,7 @@
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
import calculator.dosgi.operations.AddService;
@@ -66,9 +67,11 @@
if (b.getSymbolicName().equals("org.eclipse.equinox.ds") || b.getSymbolicName()
.startsWith("org.apache.tuscany.sca.")) {
try {
- b.start();
+ if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
+ // Start the non-fragment bundle
+ b.start();
+ }
} catch (Exception e) {
- System.out.println(bundleStatus(b, false));
e.printStackTrace();
}
System.out.println(bundleStatus(b, false));
Modified: tuscany/java/sca/samples/dosgi-calculator/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/dosgi-calculator/pom.xml?rev=762966&r1=762965&r2=762966&view=diff
==============================================================================
--- tuscany/java/sca/samples/dosgi-calculator/pom.xml (original)
+++ tuscany/java/sca/samples/dosgi-calculator/pom.xml Tue Apr 7 21:08:52 2009
@@ -36,7 +36,13 @@
<version>2.0-SNAPSHOT</version>
<type>pom</type>
</dependency>
-
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-feature-webservice</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <type>pom</type>
+ <scope>runtime</scope>
+ </dependency>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-launcher-equinox</artifactId>
@@ -48,7 +54,7 @@
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-node-impl-osgi</artifactId>
<version>2.0-SNAPSHOT</version>
- <scope>test</scope>
+ <scope>runtime</scope>
</dependency>
<dependency>
Modified: tuscany/java/sca/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java?rev=762966&r1=762965&r2=762966&view=diff
==============================================================================
--- tuscany/java/sca/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java (original)
+++ tuscany/java/sca/samples/dosgi-calculator/src/main/java/calculator/rmi/OperationsRMIServer.java Tue Apr 7 21:08:52 2009
@@ -58,12 +58,14 @@
Thread thread = new Thread() {
public void run() {
try {
+ System.out.println("Starting the RMI server for calculator operations...");
Remote stub = UnicastRemoteObject.exportObject(OperationsRMIServer.this);
registry = LocateRegistry.createRegistry(8085);
registry.bind("AddService", stub);
registry.bind("SubtractService", stub);
registry.bind("MultiplyService", stub);
registry.bind("DivideService", stub);
+ System.out.println("RMI server for calculator operations is now started.");
} catch (Exception e) {
e.printStackTrace();
}
Modified: tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType?rev=762966&r1=762965&r2=762966&view=diff
==============================================================================
--- tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType (original)
+++ tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.componentType Tue Apr 7 21:08:52 2009
@@ -7,28 +7,28 @@
* 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.
+ * under the License.
-->
-<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+<componentType xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:t="http://tuscany.apache.org/xmlns/sca/1.1">
<!-- The service elment defines an SCA view of the OSGi service -->
- <service name="Calculator">
+ <service name="CalculatorService">
<!-- The interface will be mapped into the OSGi service class -->
<interface.java interface="calculator.dosgi.CalculatorService"/>
<!-- The list of OSGi properties -->
<t:osgi.property name="prop1">1</t:osgi.property>
<t:osgi.property name="prop2">ABC</t:osgi.property>
</service>
-
+
<!-- The reference elment defines an SCA proxy to a remote OSGi service -->
<reference name="addService">
<interface.java interface="calculator.dosgi.operations.AddService"/>
@@ -50,5 +50,5 @@
<t:osgi.property name="prop1">1</t:osgi.property>
<t:osgi.property name="prop2">ABC</t:osgi.property>
</reference>
-
+
</componentType>
Modified: tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite?rev=762966&r1=762965&r2=762966&view=diff
==============================================================================
--- tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite (original)
+++ tuscany/java/sca/samples/dosgi-calculator/src/main/resources/OSGI-INF/sca/bundle.composite Tue Apr 7 21:08:52 2009
@@ -7,24 +7,27 @@
* 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.
+ * under the License.
-->
-<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200903"
xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
- xmlns:xsd="http://www.w3.org/2001/XMLSchema"
- targetNamespace="http://calculator.dosgi"
+ xmlns:xsd="http://www.w3.org/2001/XMLSchema"
+ targetNamespace="http://calculator.dosgi"
name="CalculatorComposite">
<component name="CalculatorComponent">
<tuscany:implementation.osgi bundleSymbolicName="calculator.dosgi" bundleVersion="1.0.0" />
+ <service name="CalculatorService">
+ <binding.ws uri="http://localhost:8086/CalculatorService"/>
+ </service>
<reference name="addService">
<tuscany:binding.rmi uri="rmi://localhost:8085/AddService"/>
</reference>
@@ -37,8 +40,8 @@
<reference name="divideService">
<tuscany:binding.rmi uri="rmi://localhost:8085/DivideService"/>
</reference>
-
- <!--
+
+ <!--
<reference name="addService" target="OperationsComponent/AddService">
</reference>
<reference name="subtractService" target="OperationsComponent/SubtractService">
Modified: tuscany/java/sca/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/java/sca/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java?rev=762966&r1=762965&r2=762966&view=diff
==============================================================================
--- tuscany/java/sca/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java (original)
+++ tuscany/java/sca/samples/dosgi-calculator/src/test/java/calculator/dosgi/test/CalculatorOSGiNodeTestCase.java Tue Apr 7 21:08:52 2009
@@ -21,6 +21,11 @@
import static calculator.dosgi.test.OSGiTestUtils.bundleStatus;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.io.Reader;
+import java.net.URL;
+
import org.apache.tuscany.sca.node.equinox.launcher.EquinoxHost;
import org.junit.AfterClass;
import org.junit.Assert;
@@ -28,6 +33,7 @@
import org.junit.Test;
import org.osgi.framework.Bundle;
import org.osgi.framework.BundleContext;
+import org.osgi.framework.Constants;
import org.osgi.framework.ServiceReference;
import calculator.dosgi.CalculatorService;
@@ -59,9 +65,11 @@
if (b.getSymbolicName().equals("org.eclipse.equinox.ds") || b.getSymbolicName()
.startsWith("org.apache.tuscany.sca.")) {
try {
- b.start();
+ if (b.getHeaders().get(Constants.FRAGMENT_HOST) == null) {
+ // Start the non-fragment bundle
+ b.start();
+ }
} catch (Exception e) {
- System.out.println(bundleStatus(b, false));
e.printStackTrace();
}
System.out.println(bundleStatus(b, false));
@@ -96,6 +104,29 @@
System.out.println("2.0 / 1.0 = " + calculator.divide(2.0, 1.0));
}
+ @Test
+ /**
+ * Test the Web service exposed by the Calculator
+ */
+ public void testWS() throws Exception {
+ URL url = new URL("http://localhost:8086/CalculatorService?wsdl");
+ InputStream is = url.openStream();
+ Reader reader = new InputStreamReader(is);
+ char[] content = new char[10240]; // 10k
+ int len = 0;
+ while (true) {
+ int size = reader.read(content, len, content.length - len);
+ if (size < 0) {
+ break;
+ }
+ len += size;
+ }
+ Assert.assertTrue(len > 0);
+ String str = new String(content, 0, len);
+ System.out.println(str);
+ Assert.assertTrue(str.indexOf("<wsdl:definitions") != -1);
+ }
+
/**
* @throws java.lang.Exception
*/