Example usage for org.apache.solr.common.params CommonParams CORES_HANDLER_PATH

List of usage examples for org.apache.solr.common.params CommonParams CORES_HANDLER_PATH

Introduction

In this page you can find the example usage for org.apache.solr.common.params CommonParams CORES_HANDLER_PATH.

Prototype

String CORES_HANDLER_PATH

To view the source code for org.apache.solr.common.params CommonParams CORES_HANDLER_PATH.

Click Source Link

Usage

From source file:org.apache.ofbiz.solr.webapp.OFBizSolrLoadAdminUiServlet.java

License:Apache License

@Override
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    boolean isForwarded = forwardUrl(request, response);
    if (isForwarded) {
        return;/* www .  jav a 2  s  .  c  o m*/
    }

    // 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 && cores != null) {
        try {
            response.setCharacterEncoding("UTF-8");
            response.setContentType("text/html");
            Writer out = new OutputStreamWriter(response.getOutputStream(), StandardCharsets.UTF_8);

            String html = IOUtils.toString(in, "UTF-8");
            Package pack = SolrCore.class.getPackage();

            String[] search = new String[] { "${contextPath}", "${adminPath}", "${version}" };
            String[] replace = new String[] { StringEscapeUtils.escapeJavaScript(request.getContextPath()),
                    StringEscapeUtils.escapeJavaScript(CommonParams.CORES_HANDLER_PATH),
                    StringEscapeUtils.escapeJavaScript(pack.getSpecificationVersion()) };

            out.write(StringUtils.replaceEach(html, search, replace));
            out.flush();
        } finally {
            IOUtils.closeQuietly(in);
        }
    } else {
        response.sendError(404);
    }
}