parent
13724ddd43
commit
965aac5ebb
@ -0,0 +1,52 @@
|
|||||||
|
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.HttpConnection;
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
|
||||||
|
// we handled this request, break out of handler chain
|
||||||
|
Request base_request = (request instanceof Request) ? (Request)request:HttpConnection.getCurrentConnection().getRequest();
|
||||||
|
base_request.setHandled(true);
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,8 @@
|
|||||||
|
package net.yacy.http;
|
||||||
|
|
||||||
|
import org.eclipse.jetty.server.handler.ErrorHandler;
|
||||||
|
|
||||||
|
public class YaCyErrorHandler extends ErrorHandler {
|
||||||
|
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in new issue