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;
import java.util.Map;
import java.net.URL;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.Set;
import java.util.Date;
import java.util.List;
import java.util.concurrent.CopyOnWriteArraySet;
import java.util.HashMap;
import java.util.HashSet;
......@@ -19,8 +22,7 @@ import java.util.Enumeration;
import java.util.Locale;
import java.util.TimeZone;
import java.util.Iterator;
import javolution.util.FastList;
import java.sql.Timestamp;
import javax.script.ScriptContext;
import javax.servlet.RequestDispatcher;
......@@ -48,7 +50,9 @@ import org.ofbiz.entity.GenericValue;
import org.ofbiz.entity.util.EntityUtil;
import org.ofbiz.entity.condition.EntityOperator;
import org.ofbiz.entity.condition.EntityCondition;
import org.ofbiz.service.DispatchContext;
import org.ofbiz.service.LocalDispatcher;
import org.ofbiz.service.ModelService;
import org.ofbiz.service.ServiceContainer;
import groovy.lang.GroovyClassLoader;
......@@ -59,6 +63,8 @@ import org.ofbiz.base.json.JSON;
import org.ofbiz.base.json.ParseException;
import net.sf.json.JSONObject;
import net.sf.json.JsonConfig;
import net.sf.json.processors.JsonValueProcessor;
public class DirectControlServlet extends HttpServlet {
public static final String module = DirectControlServlet.class.getName();
......@@ -218,10 +224,17 @@ public class DirectControlServlet extends HttpServlet {
Debug.logInfo("USERLOGIN " + context.get("userLogin") + " AUTHTOKEN " + authToken, module);
DispatchContext dctx = dispatcher.getDispatchContext();
ModelService model = dctx.getModelService(serviceName);
// some needed info for when running the service
Locale locale = UtilHttp.getLocale(request);
TimeZone timeZone = UtilHttp.getTimeZone(request);
List<Object> errorMessages = new ArrayList<Object>();
context = model.makeValid(context, ModelService.IN_PARAM, true, errorMessages, timeZone, locale);
Map<String, Object> result = dispatcher.runSync(serviceName, context);
result.remove("responseMessage");
......@@ -234,7 +247,10 @@ public class DirectControlServlet extends HttpServlet {
PrintWriter writer = response.getWriter();
JSONObject json = JSONObject.fromObject(result);
JsonConfig jsonConfig = new JsonConfig();
jsonConfig.registerJsonValueProcessor(Date.class, new ISODateValueProcessor());
jsonConfig.registerJsonValueProcessor(Timestamp.class, new ISODateValueProcessor());
JSONObject json = JSONObject.fromObject(result, jsonConfig);
String jsonStr = json.toString();
response.setContentLength(jsonStr.getBytes("UTF8").length);
writer.write(jsonStr);
......@@ -304,4 +320,22 @@ public class DirectControlServlet extends HttpServlet {
}
return delegator;
}
protected static class ISODateValueProcessor implements JsonValueProcessor {
public ISODateValueProcessor() {
}
public Object processArrayValue( Object value, JsonConfig jsonConfig ) {
return value;
}
public Object processObjectValue( String key, Object value, JsonConfig jsonConfig ) {
return process(value, jsonConfig);
}
private Object process( Object value, JsonConfig jsonConfig ) {
String newValue = value.toString();
return newValue;
}
}
}
......