diff options
author | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-31 06:18:58 +0000 |
---|---|---|
committer | antelder <antelder@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-31 06:18:58 +0000 |
commit | f67386be77288ab36155456f9d60692fda75d065 (patch) | |
tree | a21373f8f5dafbf3a37319a365cde100fbca1ae1 /sca-java-2.x/trunk | |
parent | bc5a744c6e2c15300e6c2ed1ccf32bfa49eee7e5 (diff) |
Update to work with POSTing JSON
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@991087 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
-rw-r--r-- | sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java | 27 |
1 files changed, 25 insertions, 2 deletions
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<Object> os = new ArrayList<Object>();
+ 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();
|