Skip to content
Snippets Groups Projects
Commit 19568a41 authored by srosse's avatar srosse
Browse files

OO-3586: add custom error dispatcher to replace the Apache Tomcat one

parent 171b5d6d
No related branches found
No related tags found
No related merge requests found
/**
* <a href="http://www.openolat.org">
* OpenOLAT - Online Learning and Training</a><br>
* <p>
* Licensed under the Apache License, Version 2.0 (the "License"); <br>
* you may not use this file except in compliance with the License.<br>
* You may obtain a copy of the License at the
* <a href="http://www.apache.org/licenses/LICENSE-2.0">Apache homepage</a>
* <p>
* Unless required by applicable law or agreed to in writing,<br>
* software distributed under the License is distributed on an "AS IS" BASIS, <br>
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. <br>
* See the License for the specific language governing permissions and <br>
* limitations under the License.
* <p>
* Initial code contributed and copyrighted by<br>
* frentix GmbH, http://www.frentix.com
* <p>
*/
package org.olat.core.dispatcher;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.olat.core.logging.OLog;
import org.olat.core.logging.Tracing;
/**
* Used to override the standard error page of Tomcat. The goal is to
* suppress the stack trace at any cost.
*
* Initial date: 25 juil. 2018<br>
* @author srosse, stephane.rosse@frentix.com, http://www.frentix.com
*
*/
public class ErrorsDispatcher implements Dispatcher {
private static final OLog log = Tracing.createLoggerFor(ErrorsDispatcher.class);
@Override
public void execute(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
try(PrintWriter writer = response.getWriter()) {
writer.append("<!DOCTYPE html><html>")
.append("<head><title>Unexpected error</title></head>")
.append("<body><h3>An unexpected error occured... Sorry!</h3><p>Error code: ")
.append(Integer.toString(response.getStatus()))
.append("</p></body></html>");
} catch(Exception e) {
log.error("", e);
}
}
}
......@@ -46,6 +46,9 @@
<entry key="/error/">
<ref bean="errorMailBean" />
</entry>
<entry key="/errors/">
<ref bean="errorsBean" />
</entry>
<entry key="/math/">
<ref bean="mathwebbean" />
</entry>
......@@ -80,6 +83,8 @@
<property name="mailManager" ref="mailManager"/>
<property name="securityManager" ref="baseSecurityManager"/>
</bean>
<bean id="errorsBean" class="org.olat.core.dispatcher.ErrorsDispatcher" />
<!-- all olat dispatchers -->
<bean id="dmzbean" class="org.olat.dispatcher.DMZDispatcher">
......
......@@ -199,4 +199,12 @@
<session-config>
<session-timeout>60</session-timeout>
</session-config>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/errors/error.html</location>
</error-page>
<error-page>
<location>/errors/error.html</location>
</error-page>
</web-app>
......@@ -165,4 +165,11 @@
<session-timeout>60</session-timeout>
</session-config>
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/errors/error.html</location>
</error-page>
<error-page>
<location>/errors/error.html</location>
</error-page>
</web-app>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment