diff options
author | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-09-29 09:23:57 +0000 |
---|---|---|
committer | slaws <slaws@13f79535-47bb-0310-9956-ffa450edef68> | 2010-09-29 09:23:57 +0000 |
commit | 5055f20ec42ce04534f6eb1d151a92a8f757e8ef (patch) | |
tree | 94e015eabc4f0aeaf095ed26659d281bcb496bc0 /sca-java-1.x/trunk/modules | |
parent | 76598f25fab0e1f07759dd484ebf043a331b3856 (diff) |
TUSCANY-3696 - Support parameter of type array in the JSONP binding.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1002534 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
6 files changed, 142 insertions, 6 deletions
diff --git a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java index d68a353896..3fe293cb8d 100644 --- a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java +++ b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java @@ -19,7 +19,10 @@ package org.apache.tuscany.sca.binding.jsonp.runtime;
+import java.util.List;
+
import org.apache.tuscany.sca.binding.jsonp.JSONPBinding;
+import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.invocation.Invoker;
@@ -44,7 +47,22 @@ public class JSONPReferenceBindingProvider implements ReferenceBindingProvider { } catch (Exception ex){
// we know this supports clone
}
+
contract.getInterface().resetDataBinding("JSON2x");
+
+ // force array types to map to JSON also
+ for (Operation operation : contract.getInterface().getOperations()){
+ DataType<List<DataType>> inputTypes = operation.getInputType();
+ for (DataType inputType : inputTypes.getLogical()){
+ if ("java:array".equals(inputType.getDataBinding())){
+ inputType.setDataBinding("JSON2x");
+ }
+ }
+ DataType outputType = operation.getOutputType();
+ if ("java:array".equals(outputType.getDataBinding())){
+ outputType.setDataBinding("JSON2x");
+ }
+ }
}
public Invoker createInvoker(Operation operation) {
return new JSONPInvoker(operation, binding);
diff --git a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java index 28a809f989..a76df37522 100644 --- a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java +++ b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java @@ -19,9 +19,12 @@ package org.apache.tuscany.sca.binding.jsonp.runtime;
+import java.util.List;
+
import org.apache.tuscany.sca.assembly.ComponentService;
import org.apache.tuscany.sca.binding.jsonp.JSONPBinding;
import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Interface;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.interfacedef.Operation;
@@ -53,6 +56,20 @@ public class JSONPServiceBindingProvider implements ServiceBindingProvider { // we know this supports clone
}
contract.getInterface().resetDataBinding("JSON2x");
+
+ // force array types to map to JSON also
+ for (Operation operation : contract.getInterface().getOperations()){
+ DataType<List<DataType>> inputTypes = operation.getInputType();
+ for (DataType inputType : inputTypes.getLogical()){
+ if ("java:array".equals(inputType.getDataBinding())){
+ inputType.setDataBinding("JSON2x");
+ }
+ }
+ DataType outputType = operation.getOutputType();
+ if ("java:array".equals(outputType.getDataBinding())){
+ outputType.setDataBinding("JSON2x");
+ }
+ }
}
public void start() {
diff --git a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java index 8d731e9198..a08dba6708 100644 --- a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java +++ b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java @@ -38,4 +38,16 @@ public class HelloWorldClient implements HelloWorldService { public BeanA sayHello3(BeanA bean) {
return ref.sayHello3(bean);
}
+
+ public String[] sayHello4(String[] name) {
+ return ref.sayHello4(name);
+ }
+
+ public BeanA[] sayHello5(BeanA[] beans){
+ return ref.sayHello5(beans);
+ }
+
+ public String[] sayHello6(BeanA[] beans, String[] names, String anotherName){
+ return ref.sayHello6(beans, names, anotherName);
+ }
}
diff --git a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java index 7efddd7643..2334c48cac 100644 --- a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java +++ b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java @@ -34,4 +34,34 @@ public class HelloWorldImpl implements HelloWorldService { return bean;
}
+ public String[] sayHello4(String[] name) {
+ String returnString = "Hello";
+
+ for (int i=0 ; i < name.length; i++){
+ returnString += " " + name[i];
+ }
+
+ String [] response = {returnString};
+ return response;
+ }
+
+ public BeanA[] sayHello5(BeanA[] beans){
+ beans[0].setS("Hello " + beans[0].getS());
+ return beans;
+ }
+
+ public String[] sayHello6(BeanA[] beans, String[] names, String anotherName){
+ String returnString = "Hello";
+
+ returnString += " " + beans[0].getS();
+
+ for (int i=0 ; i < names.length; i++){
+ returnString += " " + names[i];
+ }
+
+ returnString += " " + anotherName;
+
+ String [] response = {returnString};
+ return response;
+ }
}
diff --git a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java index 184dac6810..1eda6de915 100644 --- a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java +++ b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java @@ -29,5 +29,10 @@ public interface HelloWorldService { String sayHello2(String firstName, String lastName);
BeanA sayHello3(BeanA bean);
-
+
+ String[] sayHello4(String[] name);
+
+ BeanA[] sayHello5(BeanA[] beans);
+
+ String[] sayHello6(BeanA[] beans, String[] names, String anotherName);
}
diff --git a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java index 29d4f311cc..16d962911c 100644 --- a/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java +++ b/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java @@ -30,7 +30,6 @@ import java.net.URL; import junit.framework.Assert;
import org.apache.tuscany.sca.node.SCAClient;
-import org.apache.tuscany.sca.node.SCAContribution;
import org.apache.tuscany.sca.node.SCANodeFactory;
import org.apache.tuscany.sca.node.SCANode;
import org.junit.AfterClass;
@@ -38,8 +37,6 @@ import org.junit.BeforeClass; import org.junit.Ignore;
import org.junit.Test;
-import sun.tools.tree.ThisExpression;
-
public class BindingTestCase {
private static SCANode node;
@@ -73,8 +70,7 @@ public class BindingTestCase { @Test
//@Ignore("TUSCANY-3635")
- public void testComplexParams() throws MalformedURLException, IOException {
-
+ public void testComplexParams() throws MalformedURLException, IOException {
HelloWorldService client = ((SCAClient)node).getService(HelloWorldService.class, "HelloWorldClient");
BeanA bean = new BeanA();
@@ -87,6 +83,64 @@ public class BindingTestCase { }
@Test
+ public void testStringArray() throws MalformedURLException, IOException {
+ HelloWorldService client = ((SCAClient)node).getService(HelloWorldService.class, "HelloWorldClient");
+
+ String[] names = {"Fred", "Bloggs"};
+ String[] response = client.sayHello4(names);
+
+ Assert.assertEquals("Hello Fred Bloggs", response[0]);
+ }
+
+ @Test
+ public void testBeanArray() throws MalformedURLException, IOException {
+ HelloWorldService client = ((SCAClient)node).getService(HelloWorldService.class, "HelloWorldClient");
+
+ BeanA bean = new BeanA();
+ bean.setB(true);
+ bean.setS("Fred");
+ bean.setX(2);
+ bean.setX(5);
+
+ BeanA[] beans = {bean};
+ BeanA[] response = client.sayHello5(beans);
+
+ Assert.assertEquals("Hello Fred", response[0].getS());
+ }
+
+ /* HTTP Request for testMixedArray
+ GET /HelloWorldComponent/HelloWorldService/sayHello6?arg0=%5B%7B%22b%22%3Atrue%2C%22s%22%3A%22Fred%22%2C%22y%22%3Anull%2C%22x%22%3A5%7D%5D&arg1=%5B%22Fred%22%2C%22Bloggs%22%5D&arg2=%22Bloggs%22 HTTP/1.1
+ Host: localhost:8085
+ Connection: Keep-Alive
+ User-Agent: Apache-HttpClient/4.0 (java 1.5)
+ */
+ /* FYI Converted URL =
+ /HelloWorldComponent/HelloWorldService/sayHello6?arg0=[{"b":true,"s":"Fred","y":null,"x":5}]&arg1=["Fred":"Bloggs"]&arg2="Bloggs" HTTP/1.1
+ */
+ /* HTTP Response for testMixedArray
+ HTTP/1.1 200 OK
+ Content-Length: 35
+ ["Hello Fred Fred Bloggs Bloggs"]
+ */
+ @Test
+ public void testMixedArray() throws MalformedURLException, IOException {
+ HelloWorldService client = ((SCAClient)node).getService(HelloWorldService.class, "HelloWorldClient");
+
+ BeanA bean = new BeanA();
+ bean.setB(true);
+ bean.setS("Fred");
+ bean.setX(2);
+ bean.setX(5);
+
+ BeanA[] beans = {bean};
+ String[] names = {"Fred", "Bloggs"};
+
+ String[] response = client.sayHello6(beans, names, "Bloggs");
+
+ Assert.assertEquals("Hello Fred Fred Bloggs Bloggs", response[0]);
+ }
+
+ @Test
@Ignore
public void waitForInput(){
System.out.println("Press a key");
|