summaryrefslogtreecommitdiffstats
path: root/java/sca/modules/binding-jsonp-runtime
diff options
context:
space:
mode:
authorantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-07-28 05:05:45 +0000
committerantelder <antelder@13f79535-47bb-0310-9956-ffa450edef68>2009-07-28 05:05:45 +0000
commitb285236148619a04052dcf7c3750f90739a4228d (patch)
tree8cc1c879f40c1cbbbf88e39425e4e898f1ad0603 /java/sca/modules/binding-jsonp-runtime
parentd7fc6366e08dad6e6bc7004cdd08052b50f10040 (diff)
Update to not require the client to quote strings (turns out the binding can work out itself that the arg is a String so requires quotes)
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@798404 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'java/sca/modules/binding-jsonp-runtime')
-rw-r--r--java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java15
-rw-r--r--java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java2
2 files changed, 14 insertions, 3 deletions
diff --git a/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java b/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java
index c308dd870d..f61b6c493e 100644
--- a/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java
+++ b/java/sca/modules/binding-jsonp-runtime/src/main/java/org/apache/tuscany/sca/binding/jsonp/runtime/JSONPServlet.java
@@ -23,12 +23,14 @@ import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.Enumeration;
+import java.util.List;
import javax.servlet.GenericServlet;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
+import org.apache.tuscany.sca.interfacedef.DataType;
import org.apache.tuscany.sca.interfacedef.Operation;
import org.apache.tuscany.sca.runtime.RuntimeWire;
import org.codehaus.jackson.JsonParseException;
@@ -62,14 +64,23 @@ public class JSONPServlet extends GenericServlet {
*/
protected String getJSONRequest(ServletRequest servletRequest) throws IOException, JsonParseException, JsonMappingException {
String jsonRequest = "[";
+
+ List<DataType> types = operation.getInputType().getLogical();
+ int typesIndex = 0;
+
for (Enumeration<?> ns = servletRequest.getParameterNames(); ns.hasMoreElements(); ) {
String name = (String) ns.nextElement();
if (!name.startsWith("_") && !"callback".equals(name)) {
if (jsonRequest.length() > 1) {
jsonRequest += ", ";
}
- //jsonRequest += name + ":" + servletRequest.getParameter(name);
- jsonRequest += servletRequest.getParameter(name);
+
+ if (typesIndex < types.size() && String.class.equals(types.get(typesIndex).getGenericType())) {
+ jsonRequest += "\"" + servletRequest.getParameter(name) + "\"";
+ } else {
+ jsonRequest += servletRequest.getParameter(name);
+ }
+
}
}
jsonRequest += "]";
diff --git a/java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java b/java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java
index ee5187f288..d817aff0ff 100644
--- a/java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java
+++ b/java/sca/modules/binding-jsonp-runtime/src/test/java/test/BindingTestCase.java
@@ -39,7 +39,7 @@ public class BindingTestCase {
@Test
public void testService() throws MalformedURLException, IOException {
- URL url = new URL("http://localhost:8085/HelloWorldService/sayHello?name=\"petra\"&callback=foo");
+ URL url = new URL("http://localhost:8085/HelloWorldService/sayHello?name=petra&callback=foo");
BufferedReader br = new BufferedReader(new InputStreamReader(url.openStream()));
String response = br.readLine();
Assert.assertEquals("foo(\"Hello petra\");", response);