You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
yacy_search_server/source/net/yacy/http/CrashProtectionHandler.java

49 lines
1.3 KiB

package net.yacy.http;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.server.Handler;
import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.handler.HandlerWrapper;
public class CrashProtectionHandler extends HandlerWrapper implements Handler, HandlerContainer {
public CrashProtectionHandler() {
super();
}
public CrashProtectionHandler(Handler h) {
super();
this.setHandler(h);
}
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
try {
super.handle(target, baseRequest, request, response);
} catch (Exception e) {
// handle all we can
writeResponse(request, response, e);
baseRequest.setHandled(true);
}
}
private void writeResponse(HttpServletRequest request, HttpServletResponse response, Exception exc) throws IOException {
PrintWriter out = response.getWriter();
out.println("Ops!");
out.println();
out.println("Message: " + exc.getMessage());
exc.printStackTrace(out);
response.setContentType("text/plain");
response.setStatus(500);
}
}