Commit 75663c5b authored by Derek DeMoro's avatar Derek DeMoro Committed by derek

Adding general servlet mappings.


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1383 b35dd754-fafc-0310-a699-88a17e54d16e
parent 04991804
...@@ -23,7 +23,12 @@ import javax.servlet.ServletOutputStream; ...@@ -23,7 +23,12 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpServletResponse;
import java.io.*;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
...@@ -63,8 +68,7 @@ public class PluginServlet extends HttpServlet { ...@@ -63,8 +68,7 @@ public class PluginServlet extends HttpServlet {
} }
public void service(HttpServletRequest request, HttpServletResponse response) public void service(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException throws ServletException, IOException {
{
String pathInfo = request.getPathInfo(); String pathInfo = request.getPathInfo();
if (pathInfo == null) { if (pathInfo == null) {
response.setStatus(HttpServletResponse.SC_NOT_FOUND); response.setStatus(HttpServletResponse.SC_NOT_FOUND);
...@@ -83,7 +87,7 @@ public class PluginServlet extends HttpServlet { ...@@ -83,7 +87,7 @@ public class PluginServlet extends HttpServlet {
return; return;
} }
// Handle servlet requests. // Handle servlet requests.
else if (servlets.containsKey(pathInfo.substring(1).toLowerCase())) { else if (getServlet(pathInfo) != null) {
handleServlet(pathInfo, request, response); handleServlet(pathInfo, request, response);
} }
// Anything else results in a 404. // Anything else results in a 404.
...@@ -226,17 +230,15 @@ public class PluginServlet extends HttpServlet { ...@@ -226,17 +230,15 @@ public class PluginServlet extends HttpServlet {
* If no servlet is found, a 404 error is returned. * If no servlet is found, a 404 error is returned.
* *
* @param pathInfo the extra path info. * @param pathInfo the extra path info.
* @param request the request object. * @param request the request object.
* @param response the response object. * @param response the response object.
* @throws ServletException if a servlet exception occurs while handling the request. * @throws ServletException if a servlet exception occurs while handling the request.
* @throws IOException if an IOException occurs while handling the request. * @throws IOException if an IOException occurs while handling the request.
*/ */
private void handleServlet(String pathInfo, HttpServletRequest request, private void handleServlet(String pathInfo, HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException HttpServletResponse response) throws ServletException, IOException {
{
// Strip the starting "/" from the path to find the JSP URL. // Strip the starting "/" from the path to find the JSP URL.
String jspURL = pathInfo.substring(1); HttpServlet servlet = getServlet(pathInfo);
HttpServlet servlet = servlets.get(jspURL);
if (servlet != null) { if (servlet != null) {
servlet.service(request, response); servlet.service(request, response);
return; return;
...@@ -247,6 +249,32 @@ public class PluginServlet extends HttpServlet { ...@@ -247,6 +249,32 @@ public class PluginServlet extends HttpServlet {
} }
} }
/**
* Returns the correct servlet with mapping checks.
*
* @param pathInfo the pathinfo to map to the servlet.
* @return the mapped servlet, or null if no servlet was found.
*/
private HttpServlet getServlet(String pathInfo) {
pathInfo = pathInfo.substring(1).toLowerCase();
HttpServlet servlet = servlets.get(pathInfo);
if (servlet == null) {
for (String key : servlets.keySet()) {
int index = key.indexOf("/*");
String searchkey = key;
if (index != -1) {
searchkey = key.substring(0, index);
}
if (searchkey.startsWith(pathInfo) || pathInfo.startsWith(searchkey)) {
servlet = servlets.get(key);
break;
}
}
}
return servlet;
}
/** /**
* Handles a request for an image. * Handles a request for an image.
* *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment