Skip to content
Toggle navigation
Toggle navigation
This project
Loading...
Sign in
brainfood
/
ofbiz-directcontrolservlet
Go to a project
Toggle navigation
Toggle navigation pinning
Projects
Groups
Snippets
Help
Project
Activity
Repository
Graphs
Network
Create a new issue
Commits
Issue Boards
Files
Commits
Network
Compare
Branches
Tags
d8530866
authored
2014-10-09 18:34:59 -0500
by
Ean Schuessler
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Return dates as standard strings. #4298
1 parent
27a74df2
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
38 additions
and
1 deletions
src/com/brainfood/ofbiz/DirectControlServlet.java
src/com/brainfood/ofbiz/DirectControlServlet.java
View file @
d853086
...
...
@@ -12,6 +12,8 @@ import java.util.Map;
import
java.net.URL
;
import
java.net.MalformedURLException
;
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,6 +21,7 @@ import java.util.Enumeration;
import
java.util.Locale
;
import
java.util.TimeZone
;
import
java.util.Iterator
;
import
java.sql.Timestamp
;
import
javolution.util.FastList
;
...
...
@@ -48,7 +51,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 +64,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 +225,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
=
FastList
.
newInstance
();
context
=
model
.
makeValid
(
context
,
ModelService
.
IN_PARAM
,
true
,
errorMessages
,
timeZone
,
locale
);
Map
<
String
,
Object
>
result
=
dispatcher
.
runSync
(
serviceName
,
context
);
result
.
remove
(
"responseMessage"
);
...
...
@@ -234,7 +248,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
);
...
...
@@ -305,3 +322,23 @@ public class DirectControlServlet extends HttpServlet {
return
delegator
;
}
}
class
ISODateValueProcessor
implements
JsonValueProcessor
{
public
static
final
String
module
=
ISODateValueProcessor
.
class
.
getName
();
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
;
}
}
...
...
Please
register
or
sign in
to post a comment