Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

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

Open
wants to merge 1 commit into
from
Jump to file or symbol
Failed to load files and symbols.
+15 −4
Split
@@ -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());
+ }
+
}