Skip to content
This repository was archived by the owner on May 4, 2023. It is now read-only.
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 @@ -122,7 +122,7 @@ private void cleanup(final HttpServletRequest req,
}

private Couch getCouch(final HttpServletRequest req) throws IOException {
final String sectionName = new PathParts(req).getKey();
final String sectionName = new PathParts(PathParts.getPathWithoutContext(req)).getKey();
final Configuration section = ini.getSection(sectionName);
if (!section.containsKey("url")) {
throw new FileNotFoundException(sectionName + " is missing or has no url parameter.");
Expand Down Expand Up @@ -153,8 +153,7 @@ private synchronized DatabaseIndexer getIndexer(final Database database)
private DatabaseIndexer getIndexer(final HttpServletRequest req)
throws IOException, JSONException {
final Couch couch = getCouch(req);
final Database database = couch.getDatabase(new PathParts(req)
.getDatabaseName());
final Database database = couch.getDatabase(new PathParts(PathParts.getPathWithoutContext(req)).getDatabaseName());
return getIndexer(database);
}

Expand All @@ -179,9 +178,9 @@ protected void doGet(final HttpServletRequest req,
}
}

private void doGetInternal(final HttpServletRequest req, final HttpServletResponse resp)
throws ServletException, IOException, JSONException {
switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
private void doGetInternal(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException, JSONException {
LOG.debug("processing path "+req.getRequestURI()+" -- effective: "+PathParts.getPathWithoutContext(req));
switch (StringUtils.countMatches(PathParts.getPathWithoutContext(req), "/")) {
case 1:
handleWelcomeReq(req, resp);
return;
Expand Down Expand Up @@ -214,9 +213,8 @@ protected void doPost(final HttpServletRequest req,
}
}

private void doPostInternal(final HttpServletRequest req, final HttpServletResponse resp)
throws IOException, JSONException {
switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
private void doPostInternal(final HttpServletRequest req, final HttpServletResponse resp) throws IOException, JSONException {
switch (StringUtils.countMatches(PathParts.getPathWithoutContext(req), "/")) {
case 3:
if (req.getPathInfo().endsWith("/_cleanup")) {
cleanup(req, resp);
Expand Down
14 changes: 11 additions & 3 deletions src/main/java/com/github/rnewson/couchdb/lucene/PathParts.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ public class PathParts {

private Matcher matcher;

public PathParts(final HttpServletRequest req) {
this(req.getRequestURI());
public PathParts(final String path) {
this.setPath(path);
}

public PathParts(final String path) {
public void setPath(String path) {
matcher = QUERY_REGEX.matcher(path);
if (!matcher.matches()) {
matcher = GLOBAL_REGEX.matcher(path);
Expand Down Expand Up @@ -61,4 +61,12 @@ public String toString() {
+ "]";
}

public static String getPathWithoutContext(HttpServletRequest request) {
if (request.getContextPath().isEmpty() && (!("/".equals(request.getContextPath())))) {
return request.getRequestURI();
} else {
return (request.getRequestURI().replace(request.getContextPath(), ""));
}

}
}
2 changes: 1 addition & 1 deletion src/main/resources/log4j.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
</appender>

<logger name="com.github">
<level value="INFO"/>
<level value="DEBUG"/>
</logger>

<root>
Expand Down