From f67386be77288ab36155456f9d60692fda75d065 Mon Sep 17 00:00:00 2001 From: antelder Date: Tue, 31 Aug 2010 06:18:58 +0000 Subject: Update to work with POSTing JSON git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@991087 13f79535-47bb-0310-9956-ffa450edef68 --- .../HTTPDefaultWireFormatServiceInterceptor.java | 27 ++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) (limited to 'sca-java-2.x/trunk/modules') diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java index 9a0c73e9b0..ccd4e03ca6 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java @@ -28,6 +28,7 @@ import java.util.Comparator; import java.util.List; import java.util.Set; import java.util.SortedSet; +import java.util.StringTokenizer; import java.util.TreeSet; import javax.servlet.ServletRequest; @@ -90,10 +91,32 @@ public class HTTPDefaultWireFormatServiceInterceptor implements Interceptor { if ("GET".equals(servletRequest.getMethod())) { msg.setBody(getRequestFromQueryString(msg.getOperation(), servletRequest)); } else { - msg.setBody(read(servletRequest)); + msg.setBody(getRequestFromPost(msg.getOperation(), servletRequest)); } return msg; } + + /** + * The data binding seems to be expecting an Object array of json strings so if the + * post data is a json array convert that to an array of strings + * TODO: should this be being done by the data binding framework? + */ + private Object[] getRequestFromPost(Operation operation, HttpServletRequest servletRequest) throws IOException { + List os = new ArrayList(); + String data = read(servletRequest); + if (data.length() > 0) { + if (data.startsWith("[") && data.endsWith("]")) { + data = data.substring(1, data.length()-1); + StringTokenizer st = new StringTokenizer(data, ","); + while (st.hasMoreElements()) { + os.add(st.nextElement()); + } + } else { + os.add(data); + } + } + return os.toArray(); + } private Message invokeResponse(Message msg) throws IOException { HTTPContext context = msg.getBindingContext(); @@ -219,7 +242,7 @@ public class HTTPDefaultWireFormatServiceInterceptor implements Interceptor { while ((str = reader.readLine()) != null) { sb.append(str); } - return sb.toString(); + return sb.toString().trim(); } finally { if (reader != null) { reader.close(); -- cgit v1.2.3