498612c9 by Adam Heath

Changes to support latest ofbiz upstream.

1 parent 2d2edf98
...@@ -37,11 +37,13 @@ import javax.servlet.http.HttpSession; ...@@ -37,11 +37,13 @@ import javax.servlet.http.HttpSession;
37 import javax.servlet.http.Cookie; 37 import javax.servlet.http.Cookie;
38 import javax.servlet.http.Part; 38 import javax.servlet.http.Part;
39 39
40 import org.ofbiz.base.lang.JSON;
40 import org.ofbiz.base.util.Debug; 41 import org.ofbiz.base.util.Debug;
41 import org.ofbiz.base.util.GroovyUtil; 42 import org.ofbiz.base.util.GroovyUtil;
42 import org.ofbiz.base.util.ScriptHelper; 43 import org.ofbiz.base.util.ScriptHelper;
43 import org.ofbiz.base.util.ScriptUtil; 44 import org.ofbiz.base.util.ScriptUtil;
44 import org.ofbiz.base.util.StringUtil; 45 import org.ofbiz.base.util.StringUtil;
46 import org.ofbiz.base.util.UtilGenerics;
45 import org.ofbiz.base.util.UtilHttp; 47 import org.ofbiz.base.util.UtilHttp;
46 import org.ofbiz.base.util.UtilMisc; 48 import org.ofbiz.base.util.UtilMisc;
47 import org.ofbiz.base.util.UtilProperties; 49 import org.ofbiz.base.util.UtilProperties;
...@@ -70,7 +72,6 @@ import groovy.lang.GroovyClassLoader; ...@@ -70,7 +72,6 @@ import groovy.lang.GroovyClassLoader;
70 import groovy.lang.Script; 72 import groovy.lang.Script;
71 73
72 import org.codehaus.groovy.runtime.InvokerHelper; 74 import org.codehaus.groovy.runtime.InvokerHelper;
73 import org.ofbiz.base.json.JSON;
74 75
75 import net.sf.json.JSONObject; 76 import net.sf.json.JSONObject;
76 import net.sf.json.JsonConfig; 77 import net.sf.json.JsonConfig;
...@@ -158,10 +159,9 @@ public class DirectControlServlet extends HttpServlet { ...@@ -158,10 +159,9 @@ public class DirectControlServlet extends HttpServlet {
158 159
159 if ("application/json".equals(contentType)) { 160 if ("application/json".equals(contentType)) {
160 // Read request body as JSON and insert into the context 161 // Read request body as JSON and insert into the context
161 JSON json = new JSON(request.getReader()); 162 Map<String, Object> items = UtilGenerics.cast(JSON.from(UtilIO.readString(request.getReader())).toObject(Map.class));
162 Map<String,Object> items = json.JSONObject(); 163 for (Object key : items.keySet()) {
163 for (String key : items.keySet()) { 164 context.put((String) key, items.get(key));
164 context.put(key, items.get(key));
165 } 165 }
166 } else if ("text/csv".equals(contentType)) { 166 } else if ("text/csv".equals(contentType)) {
167 Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(request.getReader()); 167 Iterable<CSVRecord> records = CSVFormat.EXCEL.parse(request.getReader());
...@@ -199,11 +199,10 @@ public class DirectControlServlet extends HttpServlet { ...@@ -199,11 +199,10 @@ public class DirectControlServlet extends HttpServlet {
199 // Check if the request is a backbone style "emulateJSON" request 199 // Check if the request is a backbone style "emulateJSON" request
200 if (contentType != null && contentType.indexOf("x-www-form-urlencoded") != -1 && request.getParameter("model") != null) { 200 if (contentType != null && contentType.indexOf("x-www-form-urlencoded") != -1 && request.getParameter("model") != null) {
201 Debug.logInfo("MODEL: " + request.getParameter("model"), module); 201 Debug.logInfo("MODEL: " + request.getParameter("model"), module);
202 JSON json = new JSON(new StringReader(request.getParameter("model"))); 202 Map<String, Object> items = UtilGenerics.cast(JSON.from(UtilIO.readString(request.getReader())).toObject(Map.class));
203 Map<String,Object> items = json.JSONObject(); 203 for (Object key : items.keySet()) {
204 for (String key : items.keySet()) {
205 if (!"sessionId".equals(key)) { 204 if (!"sessionId".equals(key)) {
206 context.put(key, items.get(key)); 205 context.put((String) key, items.get(key));
207 } 206 }
208 } 207 }
209 } 208 }
...@@ -313,11 +312,7 @@ public class DirectControlServlet extends HttpServlet { ...@@ -313,11 +312,7 @@ public class DirectControlServlet extends HttpServlet {
313 312
314 PrintWriter writer = response.getWriter(); 313 PrintWriter writer = response.getWriter();
315 314
316 JsonConfig jsonConfig = new JsonConfig(); 315 String jsonStr = JSON.from(result).toString();
317 jsonConfig.registerJsonValueProcessor(Date.class, new ISODateValueProcessor());
318 jsonConfig.registerJsonValueProcessor(Timestamp.class, new ISODateValueProcessor());
319 JSONObject json = JSONObject.fromObject(result, jsonConfig);
320 String jsonStr = json.toString();
321 response.setContentLength(jsonStr.getBytes("UTF8").length); 316 response.setContentLength(jsonStr.getBytes("UTF8").length);
322 writer.write(jsonStr); 317 writer.write(jsonStr);
323 writer.flush(); 318 writer.flush();
......