mirror of
https://github.com/zxing/zxing.git
synced 2025-01-12 03:37:34 -08:00
Consolidate redirection, remove fairly redundant custom error page
This commit is contained in:
parent
ce31611d34
commit
e75788e3e0
|
@ -1,44 +0,0 @@
|
|||
/*
|
||||
* Copyright 2014 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.web;
|
||||
|
||||
import com.google.common.base.Preconditions;
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
import javax.servlet.annotation.WebServlet;
|
||||
import javax.servlet.http.HttpServlet;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
|
||||
@WebServlet("/w/docs/javadoc/*")
|
||||
public final class LegacyJavadocRedirectServlet extends HttpServlet {
|
||||
|
||||
private static final String PREFIX = "/w/docs/javadoc";
|
||||
|
||||
@Override
|
||||
protected void doGet(HttpServletRequest request, HttpServletResponse response) {
|
||||
String requestURI = request.getRequestURI();
|
||||
Preconditions.checkArgument(requestURI.startsWith(PREFIX));
|
||||
String requestWithoutPrefix = requestURI.substring(PREFIX.length());
|
||||
if (requestWithoutPrefix.isEmpty()) {
|
||||
requestWithoutPrefix = "/";
|
||||
}
|
||||
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
|
||||
response.setHeader(HttpHeaders.LOCATION, "http://zxing.github.io/zxing/apidocs" + requestWithoutPrefix);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,71 @@
|
|||
/*
|
||||
* Copyright 2014 ZXing authors
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.google.zxing.web;
|
||||
|
||||
import com.google.common.net.HttpHeaders;
|
||||
|
||||
import javax.servlet.Filter;
|
||||
import javax.servlet.FilterChain;
|
||||
import javax.servlet.FilterConfig;
|
||||
import javax.servlet.ServletException;
|
||||
import javax.servlet.ServletRequest;
|
||||
import javax.servlet.ServletResponse;
|
||||
import javax.servlet.annotation.WebFilter;
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.io.IOException;
|
||||
|
||||
@WebFilter("/*")
|
||||
public final class RedirectFilter implements Filter {
|
||||
|
||||
private static final String OLD_JAVADOC_PREFIX = "/w/docs/javadoc";
|
||||
|
||||
@Override
|
||||
public void init(FilterConfig filterConfig) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void doFilter(ServletRequest servletRequest,
|
||||
ServletResponse servletResponse,
|
||||
FilterChain filterChain) throws IOException, ServletException {
|
||||
HttpServletRequest request = (HttpServletRequest) servletRequest;
|
||||
String requestURI = request.getRequestURI();
|
||||
if ("/index.jspx".equals(requestURI) ||
|
||||
"/w/".equals(requestURI) ||
|
||||
"/w/index.jspx".equals(requestURI)) {
|
||||
redirect(servletResponse, "/w/decode.jspx");
|
||||
} else if (requestURI.startsWith(OLD_JAVADOC_PREFIX)) {
|
||||
String withoutPrefix = requestURI.substring(OLD_JAVADOC_PREFIX.length());
|
||||
redirect(servletResponse, "http://zxing.github.io/zxing/apidocs" + withoutPrefix);
|
||||
} else {
|
||||
filterChain.doFilter(servletRequest, servletResponse);
|
||||
}
|
||||
}
|
||||
|
||||
private static void redirect(ServletResponse servletResponse, String location) {
|
||||
HttpServletResponse response = (HttpServletResponse) servletResponse;
|
||||
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
|
||||
response.setHeader(HttpHeaders.LOCATION, location);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void destroy() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1">
|
||||
<!--
|
||||
Copyright 2008 ZXing authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<jsp:directive.page contentType="text/html" isErrorPage="true" session="false"/>
|
||||
<jsp:directive.page import="
|
||||
java.io.PrintWriter,
|
||||
java.io.StringWriter,
|
||||
com.google.common.xml.XmlEscapers"/>
|
||||
<jsp:text><![CDATA[<!DOCTYPE html>]]></jsp:text>
|
||||
<html>
|
||||
<head>
|
||||
<title>Error</title>
|
||||
<style type="text/css">body{background-color:#e9eef3}</style>
|
||||
</head>
|
||||
<body>
|
||||
<p><strong>Error ${pageContext.errorData.statusCode}</strong> : ${pageContext.errorData.requestURI}</p>
|
||||
<jsp:scriptlet>
|
||||
if (request.getAttribute("javax.servlet.error.message") != null) {
|
||||
String responseMessage = request.getAttribute("javax.servlet.error.message").toString();
|
||||
pageContext.setAttribute("responseMessage", XmlEscapers.xmlContentEscaper().escape(responseMessage));
|
||||
</jsp:scriptlet>
|
||||
<p><strong>${responseMessage}</strong></p>
|
||||
<jsp:scriptlet>
|
||||
}
|
||||
</jsp:scriptlet>
|
||||
<jsp:scriptlet>
|
||||
Throwable t = pageContext.getErrorData().getThrowable();
|
||||
if (t != null) {
|
||||
StringWriter sw = new StringWriter();
|
||||
t.printStackTrace(new PrintWriter(sw));
|
||||
pageContext.setAttribute("stackTrace", XmlEscapers.xmlContentEscaper().escape(sw.toString()));
|
||||
</jsp:scriptlet>
|
||||
<p><pre>${stackTrace}</pre></p>
|
||||
<jsp:scriptlet>
|
||||
}
|
||||
</jsp:scriptlet>
|
||||
</body>
|
||||
</html>
|
||||
</jsp:root>
|
|
@ -1,24 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2008 ZXing authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!-- Author: Sean Owen -->
|
||||
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1">
|
||||
<jsp:directive.page session="false"/>
|
||||
<jsp:scriptlet>
|
||||
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
|
||||
response.setHeader("Location", "w/decode.jspx");
|
||||
</jsp:scriptlet>
|
||||
</jsp:root>
|
|
@ -41,7 +41,9 @@
|
|||
<div id="main">
|
||||
<div id="header"><h1><img src="zxing-icon.png" height="32" width="32" alt=""/> Decode Succeeded</h1></div>
|
||||
<jsp:scriptlet>
|
||||
for (Result result : (Iterable<Result>) request.getAttribute("results")) {
|
||||
@SuppressWarnings("unchecked")
|
||||
Iterable<Result> results = (Iterable<Result>) request.getAttribute("results");
|
||||
for (Result result : results) {
|
||||
ParsedResult parsedResult = ResultParser.parseResult(result);
|
||||
|
||||
String text = result.getText();
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
Copyright 2008 ZXing authors
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
-->
|
||||
<!-- Author: Sean Owen -->
|
||||
<jsp:root xmlns:jsp="http://java.sun.com/JSP/Page" version="2.1">
|
||||
<jsp:directive.page session="false"/>
|
||||
<jsp:scriptlet>
|
||||
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
|
||||
response.setHeader("Location", "decode.jspx");
|
||||
</jsp:scriptlet>
|
||||
</jsp:root>
|
Loading…
Reference in a new issue