You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by sl...@apache.org on 2010/09/29 11:23:58 UTC

svn commit: r1002534 - in /tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src: main/java/org/apache/tuscany/sca/binding/jsonp/runtime/ test/java/helloworld/ test/java/test/

Author: slaws
Date: Wed Sep 29 09:23:57 2010
New Revision: 1002534

URL: http://svn.apache.org/viewvc?rev=1002534&view=rev
Log:
TUSCANY-3696 - Support parameter of type array in the JSONP binding. 

Modified:
    tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java
    tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java
    tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java
    tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java
    tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java
    tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java

Modified: tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java?rev=1002534&r1=1002533&r2=1002534&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java (original)
+++ tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPReferenceBindingProvider.java Wed Sep 29 09:23:57 2010
@@ -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 JSONPReferenceBindingProvid
         } 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);

Modified: tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java?rev=1002534&r1=1002533&r2=1002534&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java (original)
+++ tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServiceBindingProvider.java Wed Sep 29 09:23:57 2010
@@ -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
             // 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() {

Modified: tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java?rev=1002534&r1=1002533&r2=1002534&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java (original)
+++ tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldClient.java Wed Sep 29 09:23:57 2010
@@ -38,4 +38,16 @@ public class HelloWorldClient implements
     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);
+    }     
 }

Modified: tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java?rev=1002534&r1=1002533&r2=1002534&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java (original)
+++ tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldImpl.java Wed Sep 29 09:23:57 2010
@@ -34,4 +34,34 @@ public class HelloWorldImpl implements H
         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;
+    }  
 }

Modified: tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java?rev=1002534&r1=1002533&r2=1002534&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java (original)
+++ tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/helloworld/HelloWorldService.java Wed Sep 29 09:23:57 2010
@@ -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);
 }

Modified: tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java?rev=1002534&r1=1002533&r2=1002534&view=diff
==============================================================================
--- tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java (original)
+++ tuscany/sca-java-1.x/trunk/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java Wed Sep 29 09:23:57 2010
@@ -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");