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
dd2c9c75
authored
2014-04-08 15:49:50 -0500
by
Jerry Pommer
Browse Files
Options
Browse Files
Tag
Download
Plain Diff
Merge branch 'BF-2598' of /home/git/repositories/brainfood/ofbiz-directcontrolservlet
2 parents
7eca963e
78d782c7
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
27 additions
and
14 deletions
src/com/brainfood/ofbiz/DirectControlServlet.java
src/com/brainfood/ofbiz/DirectControlServlet.java
View file @
dd2c9c7
...
...
@@ -66,14 +66,14 @@ public class DirectControlServlet extends HttpServlet {
// get the mapping file for this webapp
ServletContext
context
=
config
.
getServletContext
();
String
mappingFile
=
context
.
getInitParameter
(
"serviceURLMappings"
);
Debug
.
log
Error
(
"Mapping file: "
+
mappingFile
,
module
);
Debug
.
log
Info
(
"Mapping file: "
+
mappingFile
,
module
);
if
(
context
.
getInitParameter
(
"sessionTokenName"
)
!=
null
)
{
sessionTokenName
=
context
.
getInitParameter
(
"sessionTokenName"
);
}
if
(
mappingFile
==
null
)
{
Debug
.
log
Error
(
"No mapping file configured"
,
module
);
Debug
.
log
Info
(
"No mapping file configured"
,
module
);
}
else
{
try
{
BufferedReader
in
=
new
BufferedReader
(
new
InputStreamReader
(
context
.
getResourceAsStream
(
mappingFile
)));
...
...
@@ -83,7 +83,7 @@ public class DirectControlServlet extends HttpServlet {
serviceURLMappings
.
put
(
confItem
[
0
],
confItem
[
1
]);
}
}
catch
(
IOException
ex
)
{
Debug
.
log
Error
(
"Could not read mapping file "
+
mappingFile
,
module
);
Debug
.
log
Info
(
"Could not read mapping file "
+
mappingFile
,
module
);
throw
new
ServletException
(
"Could not read mapping file "
+
mappingFile
);
}
}
...
...
@@ -95,8 +95,8 @@ public class DirectControlServlet extends HttpServlet {
public
void
doPost
(
HttpServletRequest
request
,
HttpServletResponse
response
)
throws
ServletException
,
IOException
{
String
method
=
""
;
Debug
.
logInfo
(
"
request.getPathInfo: "
+
request
.
getPathInfo
(),
module
);
Debug
.
logInfo
(
"
request.getContentType: "
+
request
.
getContentType
(),
module
);
Debug
.
logInfo
(
"
getPathInfo: "
+
request
.
getPathInfo
()
+
"
request.getContentType: "
+
request
.
getContentType
(),
module
);
String
pathInfo
=
request
.
getPathInfo
();
if
(
pathInfo
==
null
||
pathInfo
.
length
()
==
0
)
{
...
...
@@ -116,15 +116,16 @@ public class DirectControlServlet extends HttpServlet {
String
contentType
=
request
.
getContentType
();
if
(
contentType
!=
null
&&
contentType
.
indexOf
(
"application/x-www-form-urlencoded"
)
!=
-
1
)
{
method
=
request
.
getParameter
(
"_method"
);
if
(
method
==
null
)
method
=
"POST"
;
// If this is a backbone PUT/DELETE emulated call then handle it
Debug
.
logInfo
(
"Method: "
+
method
,
module
);
if
(
"PUT"
.
equals
(
method
)
||
"DELETE"
.
equals
(
method
)
||
"CALL"
.
equals
(
method
))
{
if
(!
"CALL"
.
equals
(
method
))
context
.
put
(
"_method"
,
method
);
if
(
"PUT"
.
equals
(
method
)
||
"DELETE"
.
equals
(
method
)
||
"CALL"
.
equals
(
method
)
||
"POST"
.
equals
(
method
)
)
{
//
if (!"CALL".equals(method)) context.put("_method", method);
JSON
json
=
new
JSON
(
new
StringReader
(
request
.
getParameter
(
"model"
)));
Map
<
String
,
Object
>
items
=
json
.
JSONObject
();
authToken
=
(
String
)
items
.
get
(
"sessionId"
);
for
(
String
key
:
items
.
keySet
())
{
if
(!
"sessionId"
.
equals
(
key
))
{
if
(!
"sessionId"
.
equals
(
key
)
&&
!
"_method"
.
equals
(
key
)
)
{
context
.
put
(
key
,
items
.
get
(
key
));
Debug
.
logInfo
(
"parameter '"
+
key
+
"'="
+
items
.
get
(
key
),
module
);
}
...
...
@@ -134,24 +135,27 @@ public class DirectControlServlet extends HttpServlet {
for
(
Enumeration
<
String
>
params
=
request
.
getParameterNames
();
params
.
hasMoreElements
();)
{
String
param
=
params
.
nextElement
();
Object
[]
values
=
request
.
getParameterValues
(
param
);
if
(!
"sessionId"
.
equals
(
param
))
{
if
(!
"sessionId"
.
equals
(
param
)
&&
!
"_method"
.
equals
(
param
)
)
{
context
.
put
(
param
,
values
.
length
==
1
?
values
[
0
]
:
values
);
Debug
.
logInfo
(
"parameter '"
+
param
+
"'="
+
context
.
get
(
param
),
module
);
}
}
}
}
else
{
Debug
.
log
Error
(
"Unsupported form encoding"
,
module
);
Debug
.
log
Info
(
"Unsupported form encoding"
,
module
);
}
// If there is a mapping for this pathInfo, run the corresponding service
// otherwise, return an error
String
serviceName
=
serviceURLMappings
.
get
(
pathInfo
+
"#"
+
method
);
Debug
.
logInfo
(
"Service name "
+
serviceName
,
module
);
if
(
serviceName
==
null
)
{
serviceName
=
serviceURLMappings
.
get
(
pathInfo
);
if
(
serviceName
==
null
)
{
response
.
setStatus
(
400
);
Debug
.
logInfo
(
"No mapping found for "
+
pathInfo
+
"#"
+
method
,
module
);
PrintWriter
writer
=
response
.
getWriter
();
writer
.
println
(
"No mapping found for URL \""
+
pathInfo
+
"\""
);
writer
.
flush
();
...
...
@@ -160,6 +164,8 @@ public class DirectControlServlet extends HttpServlet {
}
}
Debug
.
logInfo
(
"Service name"
+
serviceName
+
" mapped for "
+
pathInfo
+
"#"
+
method
,
module
);
// If the sessionId parameter is set, attempt to look up the corresponding
// UserLogin and apply it to the service context
if
(
authToken
!=
null
)
{
...
...
@@ -187,6 +193,13 @@ public class DirectControlServlet extends HttpServlet {
Locale
locale
=
UtilHttp
.
getLocale
(
request
);
TimeZone
timeZone
=
UtilHttp
.
getTimeZone
(
request
);
/*
DispatchContext dctx = dispatcher.getDispatchContext();
ModelService model = dctx.getModelService(serviceName);
for (ModelParam modelParam: model.getInModelParamList()) {
}
*/
Map
<
String
,
Object
>
result
=
dispatcher
.
runSync
(
serviceName
,
context
);
System
.
err
.
println
(
"RESULT:"
+
result
);
...
...
@@ -234,20 +247,20 @@ public class DirectControlServlet extends HttpServlet {
/** This method only sets up a dispatcher for the current webapp and passed in delegator, it does not save it to the ServletContext or anywhere else, just returns it */
public
static
LocalDispatcher
makeWebappDispatcher
(
ServletContext
servletContext
,
Delegator
delegator
)
{
if
(
delegator
==
null
)
{
Debug
.
log
Error
(
"[ContextFilter.init] ERROR: delegator not defined."
,
module
);
Debug
.
log
Info
(
"[ContextFilter.init] ERROR: delegator not defined."
,
module
);
return
null
;
}
// get the unique name of this dispatcher
String
dispatcherName
=
servletContext
.
getInitParameter
(
"localDispatcherName"
);
if
(
dispatcherName
==
null
)
{
Debug
.
log
Error
(
"No localDispatcherName specified in the web.xml file"
,
module
);
Debug
.
log
Info
(
"No localDispatcherName specified in the web.xml file"
,
module
);
dispatcherName
=
delegator
.
getDelegatorName
();
}
LocalDispatcher
dispatcher
=
ServiceContainer
.
getLocalDispatcher
(
dispatcherName
,
delegator
);
if
(
dispatcher
==
null
)
{
Debug
.
log
Error
(
"[ContextFilter.init] ERROR: dispatcher could not be initialized."
,
module
);
Debug
.
log
Info
(
"[ContextFilter.init] ERROR: dispatcher could not be initialized."
,
module
);
}
return
dispatcher
;
...
...
@@ -265,7 +278,7 @@ public class DirectControlServlet extends HttpServlet {
delegator
=
DelegatorFactory
.
getDelegator
(
delegatorName
);
servletContext
.
setAttribute
(
"delegator"
,
delegator
);
if
(
delegator
==
null
)
{
Debug
.
log
Error
(
"[ContextFilter.init] ERROR: delegator factory returned null for delegatorName \""
+
delegatorName
+
"\""
,
module
);
Debug
.
log
Info
(
"[ContextFilter.init] ERROR: delegator factory returned null for delegatorName \""
+
delegatorName
+
"\""
,
module
);
}
}
return
delegator
;
...
...
Please
register
or
sign in
to post a comment