Skip to content
This repository

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

Open
wants to merge 1 commit into from

1 participant

kr428
kr428
kr428 commented

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

Showing 1 unique commit by 1 author.

Jun 13, 2012
kr making LuceneServlet contextpath-aware c55dad0
This page is out of date. Refresh to see the latest.
16 src/main/java/com/github/rnewson/couchdb/lucene/LuceneServlet.java
@@ -122,7 +122,7 @@ private void cleanup(final HttpServletRequest req,
122 122 }
123 123
124 124 private Couch getCouch(final HttpServletRequest req) throws IOException {
125   - final String sectionName = new PathParts(req).getKey();
  125 + final String sectionName = new PathParts(PathParts.getPathWithoutContext(req)).getKey();
126 126 final Configuration section = ini.getSection(sectionName);
127 127 if (!section.containsKey("url")) {
128 128 throw new FileNotFoundException(sectionName + " is missing or has no url parameter.");
@@ -153,8 +153,7 @@ private synchronized DatabaseIndexer getIndexer(final Database database)
153 153 private DatabaseIndexer getIndexer(final HttpServletRequest req)
154 154 throws IOException, JSONException {
155 155 final Couch couch = getCouch(req);
156   - final Database database = couch.getDatabase(new PathParts(req)
157   - .getDatabaseName());
  156 + final Database database = couch.getDatabase(new PathParts(PathParts.getPathWithoutContext(req)).getDatabaseName());
158 157 return getIndexer(database);
159 158 }
160 159
@@ -179,9 +178,9 @@ protected void doGet(final HttpServletRequest req,
179 178 }
180 179 }
181 180
182   - private void doGetInternal(final HttpServletRequest req, final HttpServletResponse resp)
183   - throws ServletException, IOException, JSONException {
184   - switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
  181 + private void doGetInternal(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException, JSONException {
  182 + LOG.debug("processing path "+req.getRequestURI()+" -- effective: "+PathParts.getPathWithoutContext(req));
  183 + switch (StringUtils.countMatches(PathParts.getPathWithoutContext(req), "/")) {
185 184 case 1:
186 185 handleWelcomeReq(req, resp);
187 186 return;
@@ -214,9 +213,8 @@ protected void doPost(final HttpServletRequest req,
214 213 }
215 214 }
216 215
217   - private void doPostInternal(final HttpServletRequest req, final HttpServletResponse resp)
218   - throws IOException, JSONException {
219   - switch (StringUtils.countMatches(req.getRequestURI(), "/")) {
  216 + private void doPostInternal(final HttpServletRequest req, final HttpServletResponse resp) throws IOException, JSONException {
  217 + switch (StringUtils.countMatches(PathParts.getPathWithoutContext(req), "/")) {
220 218 case 3:
221 219 if (req.getPathInfo().endsWith("/_cleanup")) {
222 220 cleanup(req, resp);
14 src/main/java/com/github/rnewson/couchdb/lucene/PathParts.java
@@ -15,11 +15,11 @@
15 15
16 16 private Matcher matcher;
17 17
18   - public PathParts(final HttpServletRequest req) {
19   - this(req.getRequestURI());
  18 + public PathParts(final String path) {
  19 + this.setPath(path);
20 20 }
21 21
22   - public PathParts(final String path) {
  22 + public void setPath(String path) {
23 23 matcher = QUERY_REGEX.matcher(path);
24 24 if (!matcher.matches()) {
25 25 matcher = GLOBAL_REGEX.matcher(path);
@@ -61,4 +61,12 @@ public String toString() {
61 61 + "]";
62 62 }
63 63
  64 + public static String getPathWithoutContext(HttpServletRequest request) {
  65 + if (request.getContextPath().isEmpty() && (!("/".equals(request.getContextPath())))) {
  66 + return request.getRequestURI();
  67 + } else {
  68 + return (request.getRequestURI().replace(request.getContextPath(), ""));
  69 + }
  70 +
  71 + }
64 72 }
2  src/main/resources/log4j.xml
@@ -21,7 +21,7 @@
21 21 </appender>
22 22
23 23 <logger name="com.github">
24   - <level value="INFO"/>
  24 + <level value="DEBUG"/>
25 25 </logger>
26 26
27 27 <root>

Tip: You can add notes to lines in a file. Hover to the left of a line to make a note

Something went wrong with that request. Please try again.