Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

making LuceneServlet contextpath-aware

  • Loading branch information...
commit c55dad0c680cb404a0d3c7e0b8b9b8aa9c1859d8 1 parent b98f4b7
kr authored
View
16 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
@@ -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.");
@@ -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);
}
@@ -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;
@@ -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);
View
14 src/main/java/com/github/rnewson/couchdb/lucene/PathParts.java
@@ -15,11 +15,11 @@
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);
@@ -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(), ""));
+ }
+
+ }
}
View
2  src/main/resources/log4j.xml
@@ -21,7 +21,7 @@
</appender>
<logger name="com.github">
- <level value="INFO"/>
+ <level value="DEBUG"/>
</logger>
<root>
Please sign in to comment.
Something went wrong with that request. Please try again.