add custom Jetty errorhandler

to provide custom error page footer line
- remove redundant mime check in UrlProxyServlet
pull/1/head
reger 11 years ago
parent c193a02023
commit d51f9cc863

@ -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 page
try {
htrootContext.setBaseResource(Resource.newResource(htrootpath));

@ -0,0 +1,53 @@
//
// YaCyErrorHandler
// ----------------
// Copyright 2014 by Michael Peter Christen; mc@yacy.net, 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");
}
}
}

@ -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);
}

Loading…
Cancel
Save