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;
public class DirectControlServlet extends HttpServlet {
public static final String module = DirectControlServlet.class.getName();
public static final Map<String, String> serviceURLMappings = new HashMap<String, String>();
public static final Map<String, Map<String, String>> serviceURLMappings = new HashMap<String, Map<String, String>>();
private String sessionTokenName = "_AUTHTOKEN";
private String checkSessionService;
......@@ -96,7 +96,19 @@ public class DirectControlServlet extends HttpServlet {
continue;
}
String[] confItem = line.split("=");
serviceURLMappings.put(confItem[0], confItem[1]);
String[] pathMethodParts = confItem[0].split("#");
String path = pathMethodParts[0], method;
if (pathMethodParts.length == 1) {
method = "GET";
} else {
method = pathMethodParts[1];
}
Map<String, String> methodServiceMap = serviceURLMappings.get(path);
if (methodServiceMap == null) {
methodServiceMap = new HashMap<String, String>();
serviceURLMappings.put(path, methodServiceMap);
}
methodServiceMap.put(method, confItem[1]);
}
} catch (IOException ex) {
Debug.logInfo("Could not read mapping file " + mappingFile, module);
......@@ -187,22 +199,31 @@ public class DirectControlServlet extends HttpServlet {
// 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);
Map<String, String> methodServiceMapping = serviceURLMappings.get(pathInfo);
if (methodServiceMapping == null) {
response.setStatus(404);
Debug.logInfo("No mapping found for " + pathInfo, module);
PrintWriter writer = response.getWriter();
writer.println("No mapping found for URL \"" + pathInfo + "\"");
writer.flush();
writer.close();
return;
}
String serviceName = methodServiceMapping.get(method);
if (serviceName == null) {
serviceName = serviceURLMappings.get(pathInfo);
if (serviceName == null) {
response.setStatus(404);
response.setStatus(404);
Debug.logInfo("No mapping found for " + pathInfo + "#" + method, module);
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;
}
PrintWriter writer = response.getWriter();
writer.println("No mapping found for URL \"" + pathInfo + "\"");
writer.flush();
writer.close();
return;
}
Debug.logInfo("Service name " + serviceName, module);
// Check if there is an output handler
String outputHandler = "JSON";
......