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
ef4b37ae
authored
2014-10-09 19:24:11 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'BF-4298' of /home/git/repositories/brainfood/ofbiz-directcontrolservlet
2 parents
27a74df2
2ec575a2
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
37 additions
and
3 deletions
src/com/brainfood/ofbiz/DirectControlServlet.java
src/com/brainfood/ofbiz/DirectControlServlet.java
View file @
ef4b37a
...
...
@@ -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
;
}
}
}
...
...
Please
register
or
sign in
to post a comment