Skip to content

armgit / solr

Public Imported from GitHub
0

Apache Solr open-source search software

SOLR-3244: Fix new admin UI for Tomcat

Uwe Schindler8bcbd044540b
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 942b669963c..12ea0eec849 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -439,7 +439,8 @@ Other Changes
* SOLR-2607: Removed obsolete client/ folder (ehatcher, Eric Pugh, janhoy)
-* SOLR-3202: Dropping Support for JSP. New Admin UI is all client side (ryan)
+* SOLR-3202, SOLR-3244: Dropping Support for JSP. New Admin UI is all client side
+ (ryan, Aliaksandr Zhuhrou, Uwe Schindler)
* SOLR-3159: Upgrade example and tests to run with Jetty 8 (ryan)
diff --git a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java
index 8aecca07298..3783d724e41 100644
--- a/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java
+++ b/solr/core/src/java/org/apache/solr/servlet/LoadAdminUiServlet.java
@@ -17,8 +17,7 @@
package org.apache.solr.servlet;
-import java.io.File;
-import java.io.FileInputStream;
+import java.io.InputStream;
import java.io.IOException;
import java.io.PrintWriter;
@@ -29,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.commons.lang.StringEscapeUtils;
import org.apache.solr.core.CoreContainer;
@@ -47,25 +47,28 @@ public final class LoadAdminUiServlet extends HttpServlet {
response.setContentType("text/html");
PrintWriter out = response.getWriter();
- File f = new File(getServletContext().getRealPath("admin.html"));
- if(f.exists()) {
- // This attribute is set by the SolrDispatchFilter
- CoreContainer cores = (CoreContainer) request.getAttribute("org.apache.solr.CoreContainer");
+ InputStream in = getServletContext().getResourceAsStream("/admin.html");
+ if(in != null) {
+ try {
+ // This attribute is set by the SolrDispatchFilter
+ CoreContainer cores = (CoreContainer) request.getAttribute("org.apache.solr.CoreContainer");
- String html = IOUtils.toString(new FileInputStream(f), "UTF-8");
-
- String[] search = new String[] {
- "${contextPath}",
- "${adminPath}"
- };
- String[] replace = new String[] {
- request.getContextPath(),
- cores.getAdminPath()
- };
-
- out.println( StringUtils.replaceEach(html, search, replace) );
- }
- else {
+ String html = IOUtils.toString(in, "UTF-8");
+
+ String[] search = new String[] {
+ "${contextPath}",
+ "${adminPath}"
+ };
+ String[] replace = new String[] {
+ StringEscapeUtils.escapeJavaScript(request.getContextPath()),
+ StringEscapeUtils.escapeJavaScript(cores.getAdminPath())
+ };
+
+ out.println( StringUtils.replaceEach(html, search, replace) );
+ } finally {
+ IOUtils.closeQuietly(in);
+ }
+ } else {
out.println("solr");
}
}