Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -231,4 +233,5 @@ private void doPostInternal(final HttpServletRequest req, final HttpServletRespo
ServletUtils.sendJsonError(req, resp, 400, "bad_request");
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -16,7 +18,7 @@ public class PathParts {
private Matcher matcher;

public PathParts(final HttpServletRequest req) {
this(req.getRequestURI());
this(getUri(req));
}

public PathParts(final String path) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}

}