Distributed Peer-to-Peer Web Search Engine and Intranet Search Appliance
Java decentralizedintranet-searchintranet-search-enginep2pp2p-networkprivacyprivacy-protectionsearch-enginesearchenginewebweb-search-enginewebsearchwebseearch-engine
add custom Jetty errorhandler to provide custom error page footer line - remove redundant mime check in UrlProxyServlet
regerd51f9cc8637b
diff --git a/source/net/yacy/http/Jetty8HttpServerImpl.java b/source/net/yacy/http/Jetty8HttpServerImpl.javaindex 8e9b3c00e..41ce610c2 100644--- a/source/net/yacy/http/Jetty8HttpServerImpl.java+++ b/source/net/yacy/http/Jetty8HttpServerImpl.java@@ -108,6 +108,7 @@ public class Jetty8HttpServerImpl implements YaCyHttpServer {WebAppContext htrootContext = new WebAppContext();htrootContext.setContextPath("/");String htrootpath = sb.getConfig(SwitchboardConstants.HTROOT_PATH, SwitchboardConstants.HTROOT_PATH_DEFAULT);+ htrootContext.setErrorHandler(new YaCyErrorHandler()); // handler for custom error pagetry {htrootContext.setBaseResource(Resource.newResource(htrootpath));diff --git a/source/net/yacy/http/YaCyErrorHandler.java b/source/net/yacy/http/YaCyErrorHandler.javanew file mode 100644index 000000000..109600241--- /dev/null+++ b/source/net/yacy/http/YaCyErrorHandler.java@@ -0,0 +1,53 @@+//+// YaCyErrorHandler+// ----------------+// Copyright 2014 by Michael Peter Christen; [email protected], Frankfurt a. M., Germany+// First released 2014 at http://yacy.net+//+// $LastChangedDate$+// $LastChangedRevision$+// $LastChangedBy$+//+// This library is free software; you can redistribute it and/or+// modify it under the terms of the GNU Lesser General Public+// License as published by the Free Software Foundation; either+// version 2.1 of the License, or (at your option) any later version.+//+// This library is distributed in the hope that it will be useful,+// but WITHOUT ANY WARRANTY; without even the implied warranty of+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU+// Lesser General Public License for more details.+//+// You should have received a copy of the GNU Lesser General Public License+// along with this program in the file lgpl21.txt+// If not, see <http://www.gnu.org/licenses/>.+//++package net.yacy.http;++import java.io.IOException;+import java.io.Writer;+import javax.servlet.http.HttpServletRequest;+import net.yacy.peers.operation.yacyBuildProperties;+import org.eclipse.jetty.server.handler.ErrorHandler;++/**+ * Custom Handler to serve error pages called by the HttpResponse.sendError method+ */+public class YaCyErrorHandler extends ErrorHandler {++ @Override+ protected void writeErrorPageBody(HttpServletRequest request, Writer writer, int code, String message, boolean showStacks)+ throws IOException {+ String uri = request.getRequestURI();++ writeErrorPageMessage(request, writer, code, message, uri);+ if (showStacks) {+ writeErrorPageStacks(request, writer);+ }+ writer.write("<br/><hr /><small>YaCy " + yacyBuildProperties.getVersion() + " - <i> powered by Jetty </i> - </small>");+ for (int i = 0; i < 20; i++) {+ writer.write("<br/> \n");+ }+ }+}diff --git a/source/net/yacy/http/servlets/UrlProxyServlet.java b/source/net/yacy/http/servlets/UrlProxyServlet.javaindex 4870ec6c8..626f1c2b7 100644--- a/source/net/yacy/http/servlets/UrlProxyServlet.java+++ b/source/net/yacy/http/servlets/UrlProxyServlet.java@@ -195,7 +195,7 @@ public class UrlProxyServlet extends ProxyServlet implements Servlet {response.setStatus(httpStatus);response.setContentType(mimeType);- if ((httpStatus == HttpServletResponse.SC_OK) &&(mimeType != null) && (mimeType.startsWith("text/html") || mimeType.startsWith("text"))) {+ if ((httpStatus == HttpServletResponse.SC_OK) && (mimeType != null) && mimeType.startsWith("text")) {if (proxyResponseHeader.containsKey(HeaderFramework.TRANSFER_ENCODING) && proxyResponseHeader.get(HeaderFramework.TRANSFER_ENCODING).contains("chunked")) {proxyout = new ChunkedInputStream(proxyout);}