Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Strip of context path, so C-L can be deployed under different contexts #152

Open
wants to merge 1 commit into from

1 participant

@jalpedersen

This patch strips of the contextPath when examining URIs, so LuceneServlet can be deployed under any context, and not just "/".

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Feb 25, 2012
  1. @jalpedersen
This page is out of date. Refresh to see the latest.
View
9 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
@@ -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");
}
+
}
View
4 src/main/java/com/github/rnewson/couchdb/lucene/PathParts.java
@@ -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) {
View
6 src/main/java/com/github/rnewson/couchdb/lucene/util/ServletUtils.java
@@ -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());
+ }
+
}
Something went wrong with that request. Please try again.