diff options
Diffstat (limited to 'sca-java-2.x/trunk')
11 files changed, 99 insertions, 15 deletions
diff --git a/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE b/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE index 48eb152fd4..b118fb6068 100644 --- a/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE +++ b/sca-java-2.x/trunk/distribution/all/src/main/release/bin/LICENSE @@ -271,6 +271,7 @@ The following components come under Apache Software License 2.0 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
diff --git a/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd b/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd index d1bdcbdfae..cad5addc2d 100644 --- a/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd +++ b/sca-java-2.x/trunk/modules/assembly-xsd/src/main/resources/tuscany-sca-1.1-binding-jsonrpc.xsd @@ -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> diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java index e4ae943685..82eb6ea2f4 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc10Request.java @@ -80,7 +80,7 @@ public class JsonRpc10Request { } public boolean isNotification() { - return id == null; + return id == null || id == JSONObject.NULL; } public String getMethod() { diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java index 2ee18bcf5a..e73f049545 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/protocol/JsonRpc20Request.java @@ -101,7 +101,7 @@ public class JsonRpc20Request { } public boolean isNotification() { - return id == null; + return id == null || id == JSONObject.NULL; } public String getMethod() { diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java index 9e4ef8168b..a183d2211c 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonrpc/provider/JsonRpcServlet.java @@ -165,11 +165,15 @@ public class JsonRpcServlet extends HttpServlet { 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 HttpServlet { } 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 HttpServlet { } private JsonRpc10Response invoke(JsonRpc10Request request) throws Exception { - + if (request.isNotification()) { + return null; + } // invoke the request String method = request.getMethod(); Object[] params = request.getParams(); diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java index 3d817354bc..a83adb4a1b 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCReferenceTestCase.java @@ -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; + } + } } diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java index a0e7af8172..bbf8d4cee7 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/java/org/apache/tuscany/sca/binding/jsonrpc/JSONRPCServiceTestCase.java @@ -28,6 +28,7 @@ import org.apache.tuscany.sca.node.Contribution; 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.WebResponse; */ 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 { diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite index 9c97574db7..0c588cf137 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCBinding.composite @@ -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>
diff --git a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite index 16dcbce45f..5391416510 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite +++ b/sca-java-2.x/trunk/modules/binding-jsonrpc-runtime/src/test/resources/JSONRPCReference.composite @@ -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> diff --git a/sca-java-2.x/trunk/modules/databinding-json/pom.xml b/sca-java-2.x/trunk/modules/databinding-json/pom.xml index 06580aac3d..b81bedacd2 100644 --- a/sca-java-2.x/trunk/modules/databinding-json/pom.xml +++ b/sca-java-2.x/trunk/modules/databinding-json/pom.xml @@ -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> diff --git a/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java b/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java index 61e53a6939..f4f382a590 100644 --- a/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java +++ b/sca-java-2.x/trunk/samples/getting-started/helloworld-jsonrpc/src/test/java/sample/HelloworldTestCase.java @@ -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¶ms=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
|