ef4b37ae by Adam Heath

Merge branch 'BF-4298' of /home/git/repositories/brainfood/ofbiz-directcontrolservlet

2 parents 27a74df2 2ec575a2
...@@ -11,7 +11,10 @@ import java.util.Collection; ...@@ -11,7 +11,10 @@ import java.util.Collection;
11 import java.util.Map; 11 import java.util.Map;
12 import java.net.URL; 12 import java.net.URL;
13 import java.net.MalformedURLException; 13 import java.net.MalformedURLException;
14 import java.util.ArrayList;
14 import java.util.Set; 15 import java.util.Set;
16 import java.util.Date;
17 import java.util.List;
15 import java.util.concurrent.CopyOnWriteArraySet; 18 import java.util.concurrent.CopyOnWriteArraySet;
16 import java.util.HashMap; 19 import java.util.HashMap;
17 import java.util.HashSet; 20 import java.util.HashSet;
...@@ -19,8 +22,7 @@ import java.util.Enumeration; ...@@ -19,8 +22,7 @@ import java.util.Enumeration;
19 import java.util.Locale; 22 import java.util.Locale;
20 import java.util.TimeZone; 23 import java.util.TimeZone;
21 import java.util.Iterator; 24 import java.util.Iterator;
22 25 import java.sql.Timestamp;
23 import javolution.util.FastList;
24 26
25 import javax.script.ScriptContext; 27 import javax.script.ScriptContext;
26 import javax.servlet.RequestDispatcher; 28 import javax.servlet.RequestDispatcher;
...@@ -48,7 +50,9 @@ import org.ofbiz.entity.GenericValue; ...@@ -48,7 +50,9 @@ import org.ofbiz.entity.GenericValue;
48 import org.ofbiz.entity.util.EntityUtil; 50 import org.ofbiz.entity.util.EntityUtil;
49 import org.ofbiz.entity.condition.EntityOperator; 51 import org.ofbiz.entity.condition.EntityOperator;
50 import org.ofbiz.entity.condition.EntityCondition; 52 import org.ofbiz.entity.condition.EntityCondition;
53 import org.ofbiz.service.DispatchContext;
51 import org.ofbiz.service.LocalDispatcher; 54 import org.ofbiz.service.LocalDispatcher;
55 import org.ofbiz.service.ModelService;
52 import org.ofbiz.service.ServiceContainer; 56 import org.ofbiz.service.ServiceContainer;
53 57
54 import groovy.lang.GroovyClassLoader; 58 import groovy.lang.GroovyClassLoader;
...@@ -59,6 +63,8 @@ import org.ofbiz.base.json.JSON; ...@@ -59,6 +63,8 @@ import org.ofbiz.base.json.JSON;
59 import org.ofbiz.base.json.ParseException; 63 import org.ofbiz.base.json.ParseException;
60 64
61 import net.sf.json.JSONObject; 65 import net.sf.json.JSONObject;
66 import net.sf.json.JsonConfig;
67 import net.sf.json.processors.JsonValueProcessor;
62 68
63 public class DirectControlServlet extends HttpServlet { 69 public class DirectControlServlet extends HttpServlet {
64 public static final String module = DirectControlServlet.class.getName(); 70 public static final String module = DirectControlServlet.class.getName();
...@@ -218,10 +224,17 @@ public class DirectControlServlet extends HttpServlet { ...@@ -218,10 +224,17 @@ public class DirectControlServlet extends HttpServlet {
218 224
219 Debug.logInfo("USERLOGIN " + context.get("userLogin") + " AUTHTOKEN " + authToken, module); 225 Debug.logInfo("USERLOGIN " + context.get("userLogin") + " AUTHTOKEN " + authToken, module);
220 226
227 DispatchContext dctx = dispatcher.getDispatchContext();
228 ModelService model = dctx.getModelService(serviceName);
229
221 // some needed info for when running the service 230 // some needed info for when running the service
222 Locale locale = UtilHttp.getLocale(request); 231 Locale locale = UtilHttp.getLocale(request);
223 TimeZone timeZone = UtilHttp.getTimeZone(request); 232 TimeZone timeZone = UtilHttp.getTimeZone(request);
224 233
234 List<Object> errorMessages = new ArrayList<Object>();
235
236 context = model.makeValid(context, ModelService.IN_PARAM, true, errorMessages, timeZone, locale);
237
225 Map<String, Object> result = dispatcher.runSync(serviceName, context); 238 Map<String, Object> result = dispatcher.runSync(serviceName, context);
226 239
227 result.remove("responseMessage"); 240 result.remove("responseMessage");
...@@ -234,7 +247,10 @@ public class DirectControlServlet extends HttpServlet { ...@@ -234,7 +247,10 @@ public class DirectControlServlet extends HttpServlet {
234 247
235 PrintWriter writer = response.getWriter(); 248 PrintWriter writer = response.getWriter();
236 249
237 JSONObject json = JSONObject.fromObject(result); 250 JsonConfig jsonConfig = new JsonConfig();
251 jsonConfig.registerJsonValueProcessor(Date.class, new ISODateValueProcessor());
252 jsonConfig.registerJsonValueProcessor(Timestamp.class, new ISODateValueProcessor());
253 JSONObject json = JSONObject.fromObject(result, jsonConfig);
238 String jsonStr = json.toString(); 254 String jsonStr = json.toString();
239 response.setContentLength(jsonStr.getBytes("UTF8").length); 255 response.setContentLength(jsonStr.getBytes("UTF8").length);
240 writer.write(jsonStr); 256 writer.write(jsonStr);
...@@ -304,4 +320,22 @@ public class DirectControlServlet extends HttpServlet { ...@@ -304,4 +320,22 @@ public class DirectControlServlet extends HttpServlet {
304 } 320 }
305 return delegator; 321 return delegator;
306 } 322 }
323
324 protected static class ISODateValueProcessor implements JsonValueProcessor {
325 public ISODateValueProcessor() {
326 }
327
328 public Object processArrayValue( Object value, JsonConfig jsonConfig ) {
329 return value;
330 }
331
332 public Object processObjectValue( String key, Object value, JsonConfig jsonConfig ) {
333 return process(value, jsonConfig);
334 }
335
336 private Object process( Object value, JsonConfig jsonConfig ) {
337 String newValue = value.toString();
338 return newValue;
339 }
340 }
307 } 341 }
......