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
75a3aa43
authored
2016-07-04 18:14:03 -0500
by
Adam Heath
Browse Files
Options
Browse Files
Tag
Download
Email Patches
Plain Diff
Detect invalidly mapped service names earlier, before the request body
is parsed.
1 parent
498612c9
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
35 additions
and
32 deletions
src/com/brainfood/ofbiz/DirectControlServlet.java
src/com/brainfood/ofbiz/DirectControlServlet.java
View file @
75a3aa4
...
...
@@ -130,21 +130,34 @@ public class DirectControlServlet extends HttpServlet {
}
pathInfo
=
pathInfo
.
substring
(
1
).
replaceAll
(
":"
,
"."
);
// Determine type of request and load the context from JSON content or
// parameter values accordingly
if
(
contentType
!=
null
)
{
int
semi
=
contentType
.
indexOf
(
";"
);
if
(
semi
!=
-
1
)
{
contentType
=
contentType
.
substring
(
0
,
semi
);
}
}
// Determine the request method for service lookup and parameter filters
String
method
=
""
;
method
=
request
.
getParameter
(
"_method"
);
String
method
=
request
.
getParameter
(
"_method"
);
String
httpMethod
=
request
.
getMethod
();
if
(
method
==
null
&&
httpMethod
!=
null
)
method
=
httpMethod
;
if
(
method
==
null
)
method
=
"GET"
;
if
(
method
==
null
)
{
method
=
request
.
getMethod
();
}
if
(
method
==
null
)
{
method
=
"GET"
;
}
// If there is a mapping for this pathInfo, run the corresponding service
// otherwise, return an error
String
serviceName
=
serviceURLMappings
.
get
(
pathInfo
+
"#"
+
method
);
if
(
serviceName
==
null
)
{
serviceName
=
serviceURLMappings
.
get
(
pathInfo
);
if
(
serviceName
==
null
)
{
response
.
setStatus
(
404
);
Debug
.
logInfo
(
"No mapping found for "
+
pathInfo
+
"#"
+
method
,
module
);
PrintWriter
writer
=
response
.
getWriter
();
writer
.
println
(
"No mapping found for URL \""
+
pathInfo
+
"\""
);
writer
.
flush
();
writer
.
close
();
return
;
}
}
Debug
.
logInfo
(
"Service name "
+
serviceName
,
module
);
// Load context
Map
<
String
,
Object
>
context
=
new
HashMap
<
String
,
Object
>();
...
...
@@ -157,6 +170,15 @@ public class DirectControlServlet extends HttpServlet {
}
context
.
remove
(
"_method"
);
// Determine type of request and load the context from JSON content or
// parameter values accordingly
if
(
contentType
!=
null
)
{
int
semi
=
contentType
.
indexOf
(
";"
);
if
(
semi
!=
-
1
)
{
contentType
=
contentType
.
substring
(
0
,
semi
);
}
}
if
(
"application/json"
.
equals
(
contentType
))
{
// Read request body as JSON and insert into the context
Map
<
String
,
Object
>
items
=
UtilGenerics
.
cast
(
JSON
.
from
(
UtilIO
.
readString
(
request
.
getReader
())).
toObject
(
Map
.
class
));
...
...
@@ -211,25 +233,6 @@ public class DirectControlServlet extends HttpServlet {
Delegator
delegator
=
getDelegator
(
request
.
getServletContext
());
LocalDispatcher
dispatcher
=
getDispatcher
(
request
.
getServletContext
());
// 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
(
404
);
Debug
.
logInfo
(
"No mapping found for "
+
pathInfo
+
"#"
+
method
,
module
);
PrintWriter
writer
=
response
.
getWriter
();
writer
.
println
(
"No mapping found for URL \""
+
pathInfo
+
"\""
);
writer
.
flush
();
writer
.
close
();
return
;
}
}
// Check if there is an output handler
String
outputHandler
=
"JSON"
;
if
(
serviceName
.
indexOf
(
"|"
)
!=
-
1
)
{
...
...
Please
register
or
sign in
to post a comment