Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

allow c-l to run in custom servlet context path #162

Open
wants to merge 1 commit into from

1 participant

kr428
kr428

The change is pretty much similar to the one suggested by jalpedersen, differs just in details. Having the context replacement done in the static method on PathParts seems not the nicest way of doing this, though; I'd prefer refactoring all the javax.servlet dependencies out of PathParts...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Jun 13, 2012
  1. making LuceneServlet contextpath-aware

    kr authored
This page is out of date. Refresh to see the latest.
16 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
View
@@ -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);
14 src/main/java/com/github/rnewson/couchdb/lucene/PathParts.java
View
@@ -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(), ""));
+ }
+
+ }
}
2  src/main/resources/log4j.xml
View
@@ -21,7 +21,7 @@
</appender>
<logger name="com.github">
- <level value="INFO"/>
+ <level value="DEBUG"/>
</logger>
<root>
Something went wrong with that request. Please try again.