Process _method correctly
Method was not being set on a POST and was being populated as a parameter into the context. Now that there is mapping for the method type there is no reason to put it into the context.
Showing
1 changed file
with
28 additions
and
15 deletions
... | @@ -66,14 +66,14 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -66,14 +66,14 @@ public class DirectControlServlet extends HttpServlet { |
66 | // get the mapping file for this webapp | 66 | // get the mapping file for this webapp |
67 | ServletContext context = config.getServletContext(); | 67 | ServletContext context = config.getServletContext(); |
68 | String mappingFile = context.getInitParameter("serviceURLMappings"); | 68 | String mappingFile = context.getInitParameter("serviceURLMappings"); |
69 | Debug.logError("Mapping file: " + mappingFile, module); | 69 | Debug.logInfo("Mapping file: " + mappingFile, module); |
70 | 70 | ||
71 | if (context.getInitParameter("sessionTokenName") != null) { | 71 | if (context.getInitParameter("sessionTokenName") != null) { |
72 | sessionTokenName = context.getInitParameter("sessionTokenName"); | 72 | sessionTokenName = context.getInitParameter("sessionTokenName"); |
73 | } | 73 | } |
74 | 74 | ||
75 | if (mappingFile == null) { | 75 | if (mappingFile == null) { |
76 | Debug.logError("No mapping file configured", module); | 76 | Debug.logInfo("No mapping file configured", module); |
77 | } else { | 77 | } else { |
78 | try { | 78 | try { |
79 | BufferedReader in = new BufferedReader(new InputStreamReader(context.getResourceAsStream(mappingFile))); | 79 | BufferedReader in = new BufferedReader(new InputStreamReader(context.getResourceAsStream(mappingFile))); |
... | @@ -83,7 +83,7 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -83,7 +83,7 @@ public class DirectControlServlet extends HttpServlet { |
83 | serviceURLMappings.put(confItem[0], confItem[1]); | 83 | serviceURLMappings.put(confItem[0], confItem[1]); |
84 | } | 84 | } |
85 | } catch (IOException ex) { | 85 | } catch (IOException ex) { |
86 | Debug.logError("Could not read mapping file " + mappingFile, module); | 86 | Debug.logInfo("Could not read mapping file " + mappingFile, module); |
87 | throw new ServletException("Could not read mapping file " + mappingFile); | 87 | throw new ServletException("Could not read mapping file " + mappingFile); |
88 | } | 88 | } |
89 | } | 89 | } |
... | @@ -95,8 +95,8 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -95,8 +95,8 @@ public class DirectControlServlet extends HttpServlet { |
95 | 95 | ||
96 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { | 96 | public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { |
97 | String method = ""; | 97 | String method = ""; |
98 | Debug.logInfo("request.getPathInfo: " + request.getPathInfo(), module); | 98 | Debug.logInfo("getPathInfo: " + request.getPathInfo() + |
99 | Debug.logInfo("request.getContentType: " + request.getContentType(), module); | 99 | " request.getContentType: " + request.getContentType(), module); |
100 | 100 | ||
101 | String pathInfo = request.getPathInfo(); | 101 | String pathInfo = request.getPathInfo(); |
102 | if (pathInfo == null || pathInfo.length() == 0) { | 102 | if (pathInfo == null || pathInfo.length() == 0) { |
... | @@ -116,42 +116,46 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -116,42 +116,46 @@ public class DirectControlServlet extends HttpServlet { |
116 | String contentType = request.getContentType(); | 116 | String contentType = request.getContentType(); |
117 | if (contentType != null && contentType.indexOf("application/x-www-form-urlencoded") != -1) { | 117 | if (contentType != null && contentType.indexOf("application/x-www-form-urlencoded") != -1) { |
118 | method = request.getParameter("_method"); | 118 | method = request.getParameter("_method"); |
119 | if (method == null) method = "POST"; | ||
119 | // If this is a backbone PUT/DELETE emulated call then handle it | 120 | // If this is a backbone PUT/DELETE emulated call then handle it |
120 | Debug.logInfo("Method: " + method, module); | 121 | Debug.logInfo("Method: " + method, module); |
121 | if ("PUT".equals(method) || "DELETE".equals(method) || "CALL".equals(method)) { | 122 | if ("PUT".equals(method) || "DELETE".equals(method) || "CALL".equals(method) || "POST".equals(method)) { |
122 | if (!"CALL".equals(method)) context.put("_method", method); | 123 | // if (!"CALL".equals(method)) context.put("_method", method); |
123 | JSON json = new JSON(new StringReader(request.getParameter("model"))); | 124 | JSON json = new JSON(new StringReader(request.getParameter("model"))); |
124 | Map<String,Object> items = json.JSONObject(); | 125 | Map<String,Object> items = json.JSONObject(); |
125 | authToken = (String) items.get("sessionId"); | 126 | authToken = (String) items.get("sessionId"); |
126 | for (String key : items.keySet()) { | 127 | for (String key : items.keySet()) { |
127 | if (!"sessionId".equals(key)) { | 128 | if (!"sessionId".equals(key) && !"_method".equals(key)) { |
128 | context.put(key, items.get(key)); | 129 | context.put(key, items.get(key)); |
129 | Debug.logInfo("parameter '" + key + "'=" + items.get(key), module); | 130 | Debug.logInfo("parameter '" + key + "'=" + items.get(key), module); |
130 | } | 131 | } |
131 | } | 132 | } |
132 | } else { | 133 | } else { |
133 | authToken = request.getParameter("sessionId"); | 134 | authToken = request.getParameter("sessionId"); |
134 | for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) { | 135 | for (Enumeration<String> params = request.getParameterNames(); params.hasMoreElements();) { |
135 | String param = params.nextElement(); | 136 | String param = params.nextElement(); |
136 | Object[] values = request.getParameterValues(param); | 137 | Object[] values = request.getParameterValues(param); |
137 | if (!"sessionId".equals(param)) { | 138 | if (!"sessionId".equals(param) && !"_method".equals(param)) { |
138 | context.put(param, values.length == 1 ? values[0] : values); | 139 | context.put(param, values.length == 1 ? values[0] : values); |
139 | Debug.logInfo("parameter '" + param + "'=" + context.get(param), module); | 140 | Debug.logInfo("parameter '" + param + "'=" + context.get(param), module); |
140 | } | 141 | } |
141 | } | 142 | } |
142 | } | 143 | } |
143 | } else { | 144 | } else { |
144 | Debug.logError("Unsupported form encoding", module); | 145 | Debug.logInfo("Unsupported form encoding", module); |
145 | } | 146 | } |
146 | 147 | ||
147 | // If there is a mapping for this pathInfo, run the corresponding service | 148 | // If there is a mapping for this pathInfo, run the corresponding service |
148 | // otherwise, return an error | 149 | // otherwise, return an error |
149 | String serviceName = serviceURLMappings.get(pathInfo + "#" + method); | 150 | String serviceName = serviceURLMappings.get(pathInfo + "#" + method); |
151 | Debug.logInfo("Service name " + serviceName, module); | ||
150 | if (serviceName == null) { | 152 | if (serviceName == null) { |
151 | serviceName = serviceURLMappings.get(pathInfo); | 153 | serviceName = serviceURLMappings.get(pathInfo); |
152 | if (serviceName == null) { | 154 | if (serviceName == null) { |
153 | response.setStatus(400); | 155 | response.setStatus(400); |
154 | 156 | ||
157 | Debug.logInfo("No mapping found for " + pathInfo + "#" + method, module); | ||
158 | |||
155 | PrintWriter writer = response.getWriter(); | 159 | PrintWriter writer = response.getWriter(); |
156 | writer.println("No mapping found for URL \"" + pathInfo + "\""); | 160 | writer.println("No mapping found for URL \"" + pathInfo + "\""); |
157 | writer.flush(); | 161 | writer.flush(); |
... | @@ -160,6 +164,8 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -160,6 +164,8 @@ public class DirectControlServlet extends HttpServlet { |
160 | } | 164 | } |
161 | } | 165 | } |
162 | 166 | ||
167 | Debug.logInfo("Service name" +serviceName + " mapped for " + pathInfo + "#" + method, module); | ||
168 | |||
163 | // If the sessionId parameter is set, attempt to look up the corresponding | 169 | // If the sessionId parameter is set, attempt to look up the corresponding |
164 | // UserLogin and apply it to the service context | 170 | // UserLogin and apply it to the service context |
165 | if (authToken != null) { | 171 | if (authToken != null) { |
... | @@ -187,6 +193,13 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -187,6 +193,13 @@ public class DirectControlServlet extends HttpServlet { |
187 | Locale locale = UtilHttp.getLocale(request); | 193 | Locale locale = UtilHttp.getLocale(request); |
188 | TimeZone timeZone = UtilHttp.getTimeZone(request); | 194 | TimeZone timeZone = UtilHttp.getTimeZone(request); |
189 | 195 | ||
196 | /* | ||
197 | DispatchContext dctx = dispatcher.getDispatchContext(); | ||
198 | ModelService model = dctx.getModelService(serviceName); | ||
199 | for (ModelParam modelParam: model.getInModelParamList()) { | ||
200 | } | ||
201 | */ | ||
202 | |||
190 | Map<String, Object> result = dispatcher.runSync(serviceName, context); | 203 | Map<String, Object> result = dispatcher.runSync(serviceName, context); |
191 | 204 | ||
192 | System.err.println("RESULT:" + result); | 205 | System.err.println("RESULT:" + result); |
... | @@ -234,20 +247,20 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -234,20 +247,20 @@ public class DirectControlServlet extends HttpServlet { |
234 | /** 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 */ | 247 | /** 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 */ |
235 | public static LocalDispatcher makeWebappDispatcher(ServletContext servletContext, Delegator delegator) { | 248 | public static LocalDispatcher makeWebappDispatcher(ServletContext servletContext, Delegator delegator) { |
236 | if (delegator == null) { | 249 | if (delegator == null) { |
237 | Debug.logError("[ContextFilter.init] ERROR: delegator not defined.", module); | 250 | Debug.logInfo("[ContextFilter.init] ERROR: delegator not defined.", module); |
238 | return null; | 251 | return null; |
239 | } | 252 | } |
240 | // get the unique name of this dispatcher | 253 | // get the unique name of this dispatcher |
241 | String dispatcherName = servletContext.getInitParameter("localDispatcherName"); | 254 | String dispatcherName = servletContext.getInitParameter("localDispatcherName"); |
242 | 255 | ||
243 | if (dispatcherName == null) { | 256 | if (dispatcherName == null) { |
244 | Debug.logError("No localDispatcherName specified in the web.xml file", module); | 257 | Debug.logInfo("No localDispatcherName specified in the web.xml file", module); |
245 | dispatcherName = delegator.getDelegatorName(); | 258 | dispatcherName = delegator.getDelegatorName(); |
246 | } | 259 | } |
247 | 260 | ||
248 | LocalDispatcher dispatcher = ServiceContainer.getLocalDispatcher(dispatcherName, delegator); | 261 | LocalDispatcher dispatcher = ServiceContainer.getLocalDispatcher(dispatcherName, delegator); |
249 | if (dispatcher == null) { | 262 | if (dispatcher == null) { |
250 | Debug.logError("[ContextFilter.init] ERROR: dispatcher could not be initialized.", module); | 263 | Debug.logInfo("[ContextFilter.init] ERROR: dispatcher could not be initialized.", module); |
251 | } | 264 | } |
252 | 265 | ||
253 | return dispatcher; | 266 | return dispatcher; |
... | @@ -265,7 +278,7 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -265,7 +278,7 @@ public class DirectControlServlet extends HttpServlet { |
265 | delegator = DelegatorFactory.getDelegator(delegatorName); | 278 | delegator = DelegatorFactory.getDelegator(delegatorName); |
266 | servletContext.setAttribute("delegator", delegator); | 279 | servletContext.setAttribute("delegator", delegator); |
267 | if (delegator == null) { | 280 | if (delegator == null) { |
268 | Debug.logError("[ContextFilter.init] ERROR: delegator factory returned null for delegatorName \"" + delegatorName + "\"", module); | 281 | Debug.logInfo("[ContextFilter.init] ERROR: delegator factory returned null for delegatorName \"" + delegatorName + "\"", module); |
269 | } | 282 | } |
270 | } | 283 | } |
271 | return delegator; | 284 | return delegator; | ... | ... |
-
Please register or sign in to post a comment