tuscany-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rf...@apache.org
Subject svn commit: r1180782 - in /tuscany/sca-java-2.x/trunk: distribution/all/src/main/release/bin/ modules/assembly-xsd/src/main/resources/ modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/ modules/binding-jsonrp...
Date Mon, 10 Oct 2011 05:01:23 GMT
Author: rfeng
Date: Mon Oct 10 05:01:22 2011
New Revision: 1180782

URL: http://svn.apache.org/viewvc?rev=1180782&view=rev
Log:
Fix test case and update license

Modified:
    tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE
    tuscany/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite
    tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite
    tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml
    tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java

Modified: tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE (original)
+++ tuscany/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE Mon Oct 10 05:01:22
2011
@@ -271,6 +271,7 @@ The following components come under Apac
  jackson-core-asl-1.8.5.jar
  jackson-mapper-asl-1.8.5.jar
  jackson-xc-1.8.5.jar
+ jackson-module-json-org-0.9.1.jar
  jettison-1.2.jar
  jetty-6.1.26.jar
  jetty-util-6.1.26.jar

Modified: tuscany/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd
(original)
+++ tuscany/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd
Mon Oct 10 05:01:22 2011
@@ -34,6 +34,7 @@
                     <!-- any namespace="##targetNamespace" processContents="lax" minOccurs="0"
                          maxOccurs="unbounded"/ -->
                 </sequence>
+                <attribute name="version" use="optional" type="string"></attribute>
                 <!-- anyAttribute namespace="##any" processContents="lax"/ -->
             </extension>
         </complexContent>

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java
Mon Oct 10 05:01:22 2011
@@ -80,7 +80,7 @@ public class JsonRpc10Request {
     }
 
     public boolean isNotification() {
-        return id == null;
+        return id == null || id == JSONObject.NULL;
     }
 
     public String getMethod() {

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java
Mon Oct 10 05:01:22 2011
@@ -101,7 +101,7 @@ public class JsonRpc20Request {
     }
 
     public boolean isNotification() {
-        return id == null;
+        return id == null || id == JSONObject.NULL;
     }
 
     public String getMethod() {

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java
Mon Oct 10 05:01:22 2011
@@ -165,11 +165,15 @@ public class JsonRpcServlet extends Http
                 if (input.has("jsonrpc")) {
                     JsonRpc20Request jsonReq = new JsonRpc20Request(input);
                     JsonRpc20Result jsonResult = invoke(jsonReq);
-                    jsonResult.write(response.getWriter());
+                    if (jsonResult != null) {
+                        jsonResult.write(response.getWriter());
+                    }
                 } else {
                     JsonRpc10Request jsonReq = new JsonRpc10Request(input);
                     JsonRpc10Response jsonResult = invoke(jsonReq);
-                    jsonResult.write(response.getWriter());
+                    if (jsonResult != null) {
+                        jsonResult.write(response.getWriter());
+                    }
                 }
             }
         } catch (Throwable e) {
@@ -178,7 +182,9 @@ public class JsonRpcServlet extends Http
     }
 
     private JsonRpc20Result invoke(JsonRpc20Request request) throws Exception {
-
+        if (request.isNotification()) {
+            return null;
+        }
         // invoke the request
         String method = request.getMethod();
         Object[] params = request.getParams();
@@ -251,7 +257,9 @@ public class JsonRpcServlet extends Http
     }
 
     private JsonRpc10Response invoke(JsonRpc10Request request) throws Exception {
-
+        if (request.isNotification()) {
+            return null;
+        }
         // invoke the request
         String method = request.getMethod();
         Object[] params = request.getParams();

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java
Mon Oct 10 05:01:22 2011
@@ -31,9 +31,6 @@ import org.junit.Test;
 import echo.Echo;
 
 public class JSONRPCReferenceTestCase {
-    private static final String SERVICE_PATH = "/EchoService";
-    private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
-
     private static Node nodeServer;
     private static Node node;
 
@@ -82,5 +79,29 @@ public class JSONRPCReferenceTestCase {
             throw e;
         }
     }
+    
+    @Test
+    public void testInvokeReference20() throws Exception {
+        Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference20");
+        String result = echoComponent.echo("ABC");
+        Assert.assertEquals("echo: ABC", result);
+    }
+
+    @Test
+    public void testInvokeReferenceVoidOperation20() throws Exception {
+        Echo echoComponent = node.getService(Echo.class,"EchoComponentWithReference20");
+        echoComponent.echoVoid();
+    }
+    
+    @Test(expected = Exception.class)
+    public void testInvokeReferenceException20() throws Exception {
+        Echo echoComponent = node.getService(Echo.class, "EchoComponentWithReference20");
+        try {
+            echoComponent.echoBusinessException();
+        } catch (Exception e) {
+            System.err.println(e);
+            throw e;
+        }
+    }
 
 }

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java
Mon Oct 10 05:01:22 2011
@@ -28,6 +28,7 @@ import org.apache.tuscany.sca.node.Contr
 import org.apache.tuscany.sca.node.ContributionLocationHelper;
 import org.apache.tuscany.sca.node.Node;
 import org.apache.tuscany.sca.node.NodeFactory;
+import org.json.JSONArray;
 import org.json.JSONObject;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
@@ -44,9 +45,8 @@ import com.meterware.httpunit.WebRespons
  */
 public class JSONRPCServiceTestCase {
 
-    private static final String SERVICE_PATH = "/EchoService";
-
-    private static final String SERVICE_URL = "http://localhost:8085/SCADomain" + SERVICE_PATH;
+    private static String SERVICE_URL;
+    private static String SERVICE20_URL;
 
     private static Node node;
 
@@ -56,6 +56,8 @@ public class JSONRPCServiceTestCase {
             String contribution = ContributionLocationHelper.getContributionLocation(JSONRPCServiceTestCase.class);
             node = NodeFactory.newInstance().createNode("JSONRPCBinding.composite", new Contribution("test",
contribution));
             node.start();
+            SERVICE_URL = node.getEndpointAddress("EchoComponent/Echo/Echo");
+            SERVICE20_URL = node.getEndpointAddress("EchoComponent/Echo/jsonrpc20");
         } catch (Exception e) {
             e.printStackTrace();
         }
@@ -79,6 +81,40 @@ public class JSONRPCServiceTestCase {
         JSONObject jsonResp = new JSONObject(response.getText());
         Assert.assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result"));
     }
+    
+    @Test
+    public void testEchoWithJSONRPC20Binding() throws Exception {
+        JSONObject jsonRequest = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\",
\"params\": [\"Hello JSON-RPC\"], \"id\": 1}");
+
+        WebConversation wc = new WebConversation();
+        WebRequest request   = new PostMethodWebRequest( SERVICE20_URL, new ByteArrayInputStream(jsonRequest.toString().getBytes("UTF-8")),"application/json");
+        WebResponse response = wc.getResource(request);
+
+        Assert.assertEquals(200, response.getResponseCode());
+
+        JSONObject jsonResp = new JSONObject(response.getText());
+        Assert.assertEquals("echo: Hello JSON-RPC", jsonResp.getString("result"));
+    }
+    
+    
+    @Test
+    public void testEchoWithJSONRPC20BindingBatch() throws Exception {
+        JSONObject jsonRequest1 = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\",
\"params\": [\"Hello JSON-RPC\"], \"id\": 1}");
+        JSONObject jsonRequest2 = new JSONObject("{ \"jsonrpc\": \"2.0\", \"method\": \"echo\",
\"params\": [\"Hello JSON-RPC 2.0\"], \"id\": 2}");
+        JSONArray batchReq = new JSONArray();
+        batchReq.put(jsonRequest1);
+        batchReq.put(jsonRequest2);
+        
+        WebConversation wc = new WebConversation();
+        WebRequest request   = new PostMethodWebRequest( SERVICE20_URL, new ByteArrayInputStream(batchReq.toString().getBytes("UTF-8")),"application/json");
+        WebResponse response = wc.getResource(request);
+
+        Assert.assertEquals(200, response.getResponseCode());
+
+        JSONArray jsonResp = new JSONArray(response.getText());
+        Assert.assertEquals("echo: Hello JSON-RPC", ((JSONObject) jsonResp.get(0)).getString("result"));
+        Assert.assertEquals("echo: Hello JSON-RPC 2.0", ((JSONObject) jsonResp.get(1)).getString("result"));
+    }
 
     @Test
     public void testJSONRPCBindingGET() throws Exception {

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite
Mon Oct 10 05:01:22 2011
@@ -32,6 +32,7 @@
         <implementation.java class="echo.EchoComponentImpl"/>
         <service name="Echo">
             <tuscany:binding.jsonrpc uri="http://localhost:8085/SCADomain/EchoService"/>
+            <tuscany:binding.jsonrpc version="2.0" name="jsonrpc20" uri="http://localhost:8085/SCADomain/EchoService20"/>
         </service>
     </component>
     

Modified: tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite
(original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite
Mon Oct 10 05:01:22 2011
@@ -24,9 +24,17 @@
 	name="JSONRPCReference">
 
     <component name="EchoComponentWithReference">
-        <implementation.java class="echo.EchoClientImpl"/>
+        <implementation.java class="echo.EchoClientImpl" />
         <reference name="echoReference">
-            <tuscany:binding.jsonrpc uri="http://localhost:8085/SCADomain/EchoService"/>
+            <tuscany:binding.jsonrpc uri="http://localhost:8085/SCADomain/EchoService"
/>
+        </reference>
+    </component>
+
+    <component name="EchoComponentWithReference20">
+        <implementation.java class="echo.EchoClientImpl" />
+
+        <reference name="echoReference">
+            <tuscany:binding.jsonrpc version="2.0" uri="http://localhost:8085/SCADomain/EchoService20"
/>
         </reference>
     </component>
     

Modified: tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/databinding-json/pom.xml Mon Oct 10 05:01:22 2011
@@ -57,6 +57,12 @@
             <groupId>com.fasterxml</groupId>
             <artifactId>jackson-module-json-org</artifactId>
             <version>0.9.1</version>
+            <exclusions>
+                <exclusion>
+                    <groupId>junit</groupId>
+                    <artifactId>junit</artifactId>
+                </exclusion>
+            </exclusions>
         </dependency>
         
         <dependency>

Modified: tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java?rev=1180782&r1=1180781&r2=1180782&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java
(original)
+++ tuscany/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java
Mon Oct 10 05:01:22 2011
@@ -48,7 +48,9 @@ public class HelloworldTestCase {
             // test that has exposed an HTTP endpoint that works as expected
             // JSONRPC args are base64 encoded, ["World"] = WyJXb3JsZCJd  
             URL url = new URL("http://localhost:8080/HelloworldComponent/Helloworld?method=sayHello&params=WyJXb3JsZCJd&id=1");
-            Assert.assertEquals("{\"id\":1,\"result\":\"Hello World\"}", read(url.openStream()));
+            String response = read(url.openStream());
+            System.out.println(response);
+            Assert.assertTrue(response.contains("\"id\":1,\"result\":\"Hello World\""));
 
         } finally {
             // Stop the Tuscany runtime Node



Mime
View raw message