Issue #BF-5730: Pre-parse the METHOD match into a sub-map, so that the
runtime does not need to do string concatenation in the hot-path.
Showing
1 changed file
with
35 additions
and
14 deletions
... | @@ -71,7 +71,7 @@ import net.sf.json.processors.JsonValueProcessor; | ... | @@ -71,7 +71,7 @@ import net.sf.json.processors.JsonValueProcessor; |
71 | 71 | ||
72 | public class DirectControlServlet extends HttpServlet { | 72 | public class DirectControlServlet extends HttpServlet { |
73 | public static final String module = DirectControlServlet.class.getName(); | 73 | public static final String module = DirectControlServlet.class.getName(); |
74 | public static final Map<String, String> serviceURLMappings = new HashMap<String, String>(); | 74 | public static final Map<String, Map<String, String>> serviceURLMappings = new HashMap<String, Map<String, String>>(); |
75 | private String sessionTokenName = "_AUTHTOKEN"; | 75 | private String sessionTokenName = "_AUTHTOKEN"; |
76 | private String checkSessionService; | 76 | private String checkSessionService; |
77 | 77 | ||
... | @@ -96,7 +96,19 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -96,7 +96,19 @@ public class DirectControlServlet extends HttpServlet { |
96 | continue; | 96 | continue; |
97 | } | 97 | } |
98 | String[] confItem = line.split("="); | 98 | String[] confItem = line.split("="); |
99 | serviceURLMappings.put(confItem[0], confItem[1]); | 99 | String[] pathMethodParts = confItem[0].split("#"); |
100 | String path = pathMethodParts[0], method; | ||
101 | if (pathMethodParts.length == 1) { | ||
102 | method = "GET"; | ||
103 | } else { | ||
104 | method = pathMethodParts[1]; | ||
105 | } | ||
106 | Map<String, String> methodServiceMap = serviceURLMappings.get(path); | ||
107 | if (methodServiceMap == null) { | ||
108 | methodServiceMap = new HashMap<String, String>(); | ||
109 | serviceURLMappings.put(path, methodServiceMap); | ||
110 | } | ||
111 | methodServiceMap.put(method, confItem[1]); | ||
100 | } | 112 | } |
101 | } catch (IOException ex) { | 113 | } catch (IOException ex) { |
102 | Debug.logInfo("Could not read mapping file " + mappingFile, module); | 114 | Debug.logInfo("Could not read mapping file " + mappingFile, module); |
... | @@ -187,22 +199,31 @@ public class DirectControlServlet extends HttpServlet { | ... | @@ -187,22 +199,31 @@ public class DirectControlServlet extends HttpServlet { |
187 | 199 | ||
188 | // If there is a mapping for this pathInfo, run the corresponding service | 200 | // If there is a mapping for this pathInfo, run the corresponding service |
189 | // otherwise, return an error | 201 | // otherwise, return an error |
190 | String serviceName = serviceURLMappings.get(pathInfo + "#" + method); | 202 | Map<String, String> methodServiceMapping = serviceURLMappings.get(pathInfo); |
191 | Debug.logInfo("Service name " + serviceName, module); | 203 | if (methodServiceMapping == null) { |
204 | response.setStatus(404); | ||
205 | |||
206 | Debug.logInfo("No mapping found for " + pathInfo, module); | ||
207 | |||
208 | PrintWriter writer = response.getWriter(); | ||
209 | writer.println("No mapping found for URL \"" + pathInfo + "\""); | ||
210 | writer.flush(); | ||
211 | writer.close(); | ||
212 | return; | ||
213 | } | ||
214 | String serviceName = methodServiceMapping.get(method); | ||
192 | if (serviceName == null) { | 215 | if (serviceName == null) { |
193 | serviceName = serviceURLMappings.get(pathInfo); | 216 | response.setStatus(404); |
194 | if (serviceName == null) { | ||
195 | response.setStatus(404); | ||
196 | 217 | ||
197 | Debug.logInfo("No mapping found for " + pathInfo + "#" + method, module); | 218 | Debug.logInfo("No mapping found for " + pathInfo + "#" + method, module); |
198 | 219 | ||
199 | PrintWriter writer = response.getWriter(); | 220 | PrintWriter writer = response.getWriter(); |
200 | writer.println("No mapping found for URL \"" + pathInfo + "\""); | 221 | writer.println("No mapping found for URL \"" + pathInfo + "\""); |
201 | writer.flush(); | 222 | writer.flush(); |
202 | writer.close(); | 223 | writer.close(); |
203 | return; | 224 | return; |
204 | } | ||
205 | } | 225 | } |
226 | Debug.logInfo("Service name " + serviceName, module); | ||
206 | 227 | ||
207 | // Check if there is an output handler | 228 | // Check if there is an output handler |
208 | String outputHandler = "JSON"; | 229 | String outputHandler = "JSON"; | ... | ... |
-
Please register or sign in to post a comment