Skip to content
Snippets Groups Projects
Commit d84228ba authored by Tim Levett's avatar Tim Levett
Browse files

Merge branch 'no_redirects' into 'master'

MUMMNG-2046 : no more redirects

+ Added `*.html` to the jar
+ Removed webapps dir from the jar module, that's just weird
+ changed Valve class to just read the file from the classpath and write it to the response

Resolved #1 

See merge request !3
parents b3dfe31b 603f4bc3
No related branches found
No related tags found
No related merge requests found
......@@ -29,5 +29,14 @@
<build>
<finalName>myuw-error-valve</finalName>
<resources>
<resource>
<directory>../ROOT/src/main/webapp</directory>
<includes>
<include>*.html</include>
</includes>
<filtering>false</filtering>
</resource>
</resources>
</build>
</project>
......@@ -2,16 +2,11 @@ package edu.wisc.my.root;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.util.Scanner;
import org.apache.catalina.Valve;
import org.apache.catalina.connector.Request;
import org.apache.catalina.connector.Response;
import org.apache.catalina.util.RequestUtil;
import org.apache.catalina.valves.Constants;
import org.apache.catalina.valves.ErrorReportValve;
import org.apache.tomcat.util.res.StringManager;
public class MyUWErrorValve extends ErrorReportValve implements Valve {
......@@ -30,12 +25,28 @@ public class MyUWErrorValve extends ErrorReportValve implements Valve {
if (statusCode < 400 || response.getContentWritten() > 0 || !response.setErrorReported()) {
return;
}
final String page;
InputStream in = null;
try {
if(statusCode > 400 && statusCode < 500)
response.sendRedirect(MISSING_PAGE_LOCATION);
else
response.sendRedirect(ERROR_PAGE_LOCATION);
if(statusCode > 400 && statusCode < 500) {
page = MISSING_PAGE_LOCATION;
} else {
page = ERROR_PAGE_LOCATION;
}
try {
in = MyUWErrorValve.class.getResourceAsStream(page);
int c;
while ((c = in.read()) != -1) {
response.getWriter().write(c);
}
response.flushBuffer();
} finally {
if(in != null) {
in.close();
}
response.finishResponse();
}
} catch (IOException e) {
super.report(request, response, throwable);
}
......
<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" >
<web-app>
<display-name>MyUW Root</display-name>
<error-page>
<error-code>500</error-code>
<location>/500.html</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/404.html</location>
</error-page>
</web-app>
myuw-error-valve/src/main/webapp/favicon.ico

1.37 KiB

myuw-error-valve/src/main/webapp/main_logo_w_all.png

8.38 KiB

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