You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by an...@apache.org on 2011/07/23 21:35:43 UTC
svn commit: r1150200 - in
/tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp: ./
pom.xml src/main/resources/helloworld.composite
src/test/java/sample/HelloworldTestCase.java
Author: antelder
Date: Sat Jul 23 19:35:42 2011
New Revision: 1150200
URL: http://svn.apache.org/viewvc?rev=1150200&view=rev
Log:
Add a helloworld sample for the JSONP binding
Added:
tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/
- copied from r1147543, tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/
Modified:
tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/pom.xml
tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/main/resources/helloworld.composite
tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/test/java/sample/HelloworldTestCase.java
Modified: tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/pom.xml?rev=1150200&r1=1147543&r2=1150200&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/pom.xml Sat Jul 23 19:35:42 2011
@@ -28,16 +28,30 @@
<relativePath/>
</parent>
- <artifactId>helloworld-jsonrpc</artifactId>
+ <artifactId>helloworld-jsonp</artifactId>
<version>2.0-SNAPSHOT</version>
- <name>Apache Tuscany SCA Samples Helloworld JSON-RPC</name>
+ <name>Apache Tuscany SCA Samples Helloworld JSONP</name>
<properties>
<tuscany.version>${project.version}</tuscany.version>
</properties>
- <dependencies>
+ <!-- ASF repositories so sample can be built from SVN without building trunk-->
+ <repositories><repository>
+ <id>apache.snapshots</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://repository.apache.org/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </repository></repositories>
+ <pluginRepositories><pluginRepository>
+ <id>apache.snapshots</id>
+ <name>Apache Snapshot Repository</name>
+ <url>http://repository.apache.org/snapshots</url>
+ <releases><enabled>false</enabled></releases>
+ </pluginRepository></pluginRepositories>
+
+ <dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
@@ -62,7 +76,7 @@
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-binding-jsonrpc-runtime</artifactId>
+ <artifactId>tuscany-binding-jsonp-runtime</artifactId>
<version>${tuscany.version}</version>
<scope>test</scope>
</dependency>
@@ -87,7 +101,7 @@
<dependencies>
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
- <artifactId>tuscany-binding-jsonrpc-runtime</artifactId>
+ <artifactId>tuscany-binding-jsonp-runtime</artifactId>
<version>${tuscany.version}</version>
</dependency>
</dependencies>
Modified: tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/main/resources/helloworld.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/main/resources/helloworld.composite?rev=1150200&r1=1147543&r2=1150200&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/main/resources/helloworld.composite (original)
+++ tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/main/resources/helloworld.composite Sat Jul 23 19:35:42 2011
@@ -25,7 +25,7 @@
<component name="HelloworldComponent">
<implementation.java class="sample.HelloworldImpl"/>
<service name="Helloworld">
- <tuscany:binding.jsonrpc/>
+ <tuscany:binding.jsonp/>
</service>
</component>
Modified: tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/test/java/sample/HelloworldTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/test/java/sample/HelloworldTestCase.java?rev=1150200&r1=1147543&r2=1150200&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/test/java/sample/HelloworldTestCase.java (original)
+++ tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonp/src/test/java/sample/HelloworldTestCase.java Sat Jul 23 19:35:42 2011
@@ -18,31 +18,57 @@
*/
package sample;
-import org.junit.Assert;
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
import org.apache.tuscany.sca.Node;
import org.apache.tuscany.sca.TuscanyRuntime;
+import org.junit.Assert;
import org.junit.Test;
import org.oasisopen.sca.NoSuchServiceException;
public class HelloworldTestCase {
@Test
- public void testSayHello() throws NoSuchServiceException {
+ public void testSayHello() throws NoSuchServiceException, IOException {
// Run the SCA composite in a Tuscany runtime
Node node = TuscanyRuntime.runComposite("helloworld.composite", "target/classes");
try {
-
+
// Get the Helloworld service proxy
Helloworld helloworld = node.getService(Helloworld.class, "HelloworldComponent");
-
+
// test that it works as expected
Assert.assertEquals("Hello Amelia", helloworld.sayHello("Amelia"));
-
+
+ // test that has exposed an HTTP endpoint that works as expected
+ URL url = new URL("http://localhost:8080/HelloworldComponent/Helloworld/sayHello?name=Amelia&callback=someFunc");
+ Assert.assertEquals("someFunc(\"Hello Amelia\");", read(url.openStream()));
+
} finally {
// Stop the Tuscany runtime Node
- node.stop();
+ node.stop();
+ }
+ }
+
+ private static String read(InputStream is) throws IOException {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ StringBuffer sb = new StringBuffer();
+ String str;
+ while ((str = reader.readLine()) != null) {
+ sb.append(str);
+ }
+ return sb.toString();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
}
}
}