Permalink
Browse files

Strip of context path, so C-L can be deployed under different context…

…s, and not just /
  • Loading branch information...
1 parent daf007b commit 13a389c6e4b0a7dd92a56bda63d17abe56488caf @jalpedersen committed Feb 25, 2012
@@ -47,6 +47,8 @@
import com.github.rnewson.couchdb.lucene.couchdb.View;
import com.github.rnewson.couchdb.lucene.util.ServletUtils;
+import static com.github.rnewson.couchdb.lucene.util.ServletUtils.getUri;
+
public final class LuceneServlet extends HttpServlet {
private static final Logger LOG = Logger.getLogger(LuceneServlet.class);
@@ -181,7 +183,7 @@ protected void doGet(final HttpServletRequest req,
private void doGetInternal(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException, JSONException {
- switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
+ switch (StringUtils.countMatches(getUri(req), "/")) {
case 1:
handleWelcomeReq(req, resp);
return;
@@ -216,9 +218,9 @@ protected void doPost(final HttpServletRequest req,
private void doPostInternal(final HttpServletRequest req, final HttpServletResponse resp)
throws IOException, JSONException {
- switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
+ switch (StringUtils.countMatches(getUri(req), "/")) {
case 3:
- if (req.getPathInfo().endsWith("/_cleanup")) {
+ if (req.getRequestURI().endsWith("/_cleanup")) {
cleanup(req, resp);
return;
}
@@ -231,4 +233,5 @@ private void doPostInternal(final HttpServletRequest req, final HttpServletRespo
ServletUtils.sendJsonError(req, resp, 400, "bad_request");
}
+
}
@@ -5,6 +5,8 @@
import javax.servlet.http.HttpServletRequest;
+import static com.github.rnewson.couchdb.lucene.util.ServletUtils.getUri;
+
public class PathParts {
private static final Pattern QUERY_REGEX = Pattern
@@ -16,7 +18,7 @@
private Matcher matcher;
public PathParts(final HttpServletRequest req) {
- this(req.getRequestURI());
+ this(getUri(req));
}
public PathParts(final String path) {
@@ -103,4 +103,10 @@ public static void sendJsonSuccess(final HttpServletRequest req, final HttpServl
}
}
+ //Strip of context part of URI
+ public static String getUri(HttpServletRequest request) {
+ //Strip of context path if present
+ return request.getRequestURI().substring(request.getContextPath().length());
+ }
+
}

0 comments on commit 13a389c

Please sign in to comment.