Skip to content

Commit 5df41b9

Browse files
author
Vladimir Kotal
authored
Merge pull request #1347 from vladak/http_error_codes
set HTTP error codes for error conditions
2 parents 58fe41a + d1d38e3 commit 5df41b9

File tree

4 files changed

+29
-8
lines changed

4 files changed

+29
-8
lines changed

src/org/opensolaris/opengrok/configuration/RuntimeEnvironment.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2006, 2016, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2006, 2017, Oracle and/or its affiliates. All rights reserved.
2222
*/
2323
package org.opensolaris.opengrok.configuration;
2424

@@ -1877,6 +1877,11 @@ public MultiReader getMultiReader(SortedSet<String> projects,
18771877
} catch (IOException ex) {
18781878
LOGGER.log(Level.SEVERE,
18791879
"cannot get IndexReader for project" + proj, ex);
1880+
return null;
1881+
} catch (NullPointerException ex) {
1882+
LOGGER.log(Level.SEVERE,
1883+
"cannot get IndexReader for project" + proj, ex);
1884+
return null;
18801885
}
18811886
}
18821887
MultiReader multiReader = null;

src/org/opensolaris/opengrok/web/SearchHelper.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
*/
1919

2020
/*
21-
* Copyright (c) 2011, 2016, Oracle and/or its affiliates. All rights reserved.
21+
* Copyright (c) 2011, 2017, Oracle and/or its affiliates. All rights reserved.
2222
* Portions copyright (c) 2011 Jens Elkner.
2323
*/
2424
package org.opensolaris.opengrok.web;
@@ -37,6 +37,7 @@
3737
import org.apache.lucene.document.Document;
3838
import org.apache.lucene.index.DirectoryReader;
3939
import org.apache.lucene.index.IndexReader;
40+
import org.apache.lucene.index.MultiReader;
4041
import org.apache.lucene.index.Term;
4142
import org.apache.lucene.queryparser.classic.ParseException;
4243
import org.apache.lucene.search.BooleanQuery;
@@ -260,8 +261,13 @@ public SearchHelper prepareExec(SortedSet<String> projects) {
260261
// not matter given that MultiReader is just a cheap wrapper
261262
// around set of IndexReader objects.
262263
closeOnDestroy = false;
263-
searcher = new IndexSearcher(RuntimeEnvironment.getInstance().
264-
getMultiReader(projects, searcherList));
264+
MultiReader multireader = RuntimeEnvironment.getInstance().
265+
getMultiReader(projects, searcherList);
266+
if (multireader != null) {
267+
searcher = new IndexSearcher(multireader);
268+
} else {
269+
errorMsg = "Failed to initialize search. Check the index.";
270+
}
265271
}
266272

267273
// TODO check if below is somehow reusing sessions so we don't

web/error.jsp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,12 @@ information: Portions Copyright [yyyy] [name of copyright owner]
1616
1717
CDDL HEADER END
1818
19-
Copyright (c) 2005, 2012, Oracle and/or its affiliates. All rights reserved.
19+
Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2020
Portions Copyright 2011 Jens Elkner.
2121
22-
--%><%@ page session="false" isErrorPage="true" import="
22+
--%>
23+
<%@page import="javax.servlet.http.HttpServletResponse"%>
24+
<%@ page session="false" isErrorPage="true" import="
2325
java.io.PrintWriter,
2426
java.io.StringWriter,
2527

@@ -30,9 +32,13 @@ org.opensolaris.opengrok.web.Util"
3032
cfg = PageConfig.get(request);
3133
cfg.setTitle("Error!");
3234
35+
// Set status to Internal error. This should help to avoid caching
36+
// the page by some proxies.
37+
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
38+
3339
String context = request.getContextPath();
3440
String configError = "";
35-
if (cfg.getSourceRootPath()==null || cfg.getSourceRootPath().isEmpty()) {
41+
if (cfg.getSourceRootPath() == null || cfg.getSourceRootPath().isEmpty()) {
3642
configError = "CONFIGURATION parameter has not been configured in "
3743
+ "web.xml! Please configure your webapp.";
3844
} else if (!cfg.getEnv().getSourceRootFile().isDirectory()) {

web/search.jsp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,11 @@ information: Portions Copyright [yyyy] [name of copyright owner]
1818
1919
CDDL HEADER END
2020
21-
Copyright (c) 2005, 2016, Oracle and/or its affiliates. All rights reserved.
21+
Copyright (c) 2005, 2017, Oracle and/or its affiliates. All rights reserved.
2222
Portions Copyright 2011 Jens Elkner.
2323
2424
--%>
25+
<%@page import="javax.servlet.http.HttpServletResponse"%>
2526
<%@page session="false" errorPage="error.jsp" import="
2627
org.opensolaris.opengrok.search.Results,
2728
org.opensolaris.opengrok.web.SearchHelper,
@@ -77,6 +78,9 @@ include file="projects.jspf"
7778
}
7879
if (searchHelper.errorMsg != null) {
7980
cfg.setTitle("Search Error");
81+
// Set status to Internal error. This should help to avoid caching
82+
// the page by some proxies.
83+
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
8084
} else {
8185
cfg.setTitle(cfg.getSearchTitle());
8286
}

0 commit comments

Comments
 (0)