f55c2104 by Adam Heath

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.
1 parent 0eec71bc
...@@ -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,10 +199,19 @@ public class DirectControlServlet extends HttpServlet { ...@@ -187,10 +199,19 @@ 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) {
192 if (serviceName == null) { 204 response.setStatus(404);
193 serviceName = serviceURLMappings.get(pathInfo); 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);
194 if (serviceName == null) { 215 if (serviceName == null) {
195 response.setStatus(404); 216 response.setStatus(404);
196 217
...@@ -202,7 +223,7 @@ public class DirectControlServlet extends HttpServlet { ...@@ -202,7 +223,7 @@ public class DirectControlServlet extends HttpServlet {
202 writer.close(); 223 writer.close();
203 return; 224 return;
204 } 225 }
205 } 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";
......