From 8bcbd044540bda6d1d31e8d8d6c4f3759d69294a Mon Sep 17 00:00:00 2001 From: Uwe Schindler Date: Wed, 14 Mar 2012 20:29:42 +0000 Subject: [PATCH] SOLR-3244: Fix new admin UI for Tomcat git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@1300710 13f79535-47bb-0310-9956-ffa450edef68 --- solr/CHANGES.txt | 3 +- .../solr/servlet/LoadAdminUiServlet.java | 43 ++++++++++--------- 2 files changed, 25 insertions(+), 21 deletions(-) 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"); } }