aboutsummaryrefslogtreecommitdiff
path: root/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web
diff options
context:
space:
mode:
authorAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2016-03-30 11:57:24 +0200
committerAndreas Fitzek <andreas.fitzek@iaik.tugraz.at>2016-03-30 11:57:24 +0200
commit98076fc60c31be00584c81d4ce7c2ef29d2c7eb2 (patch)
tree4e9e3d7b1396d06acaba91f3158de068e8d713e5 /pdf-as-web/src/main/java/at/gv/egiz/pdfas/web
parent16a8c6fb04043162a981f6c1ea593de86e2f43cb (diff)
downloadpdf-as-4-98076fc60c31be00584c81d4ce7c2ef29d2c7eb2.tar.gz
pdf-as-4-98076fc60c31be00584c81d4ce7c2ef29d2c7eb2.tar.bz2
pdf-as-4-98076fc60c31be00584c81d4ce7c2ef29d2c7eb2.zip
Catch and Log all exceptions into pdf-as log
Diffstat (limited to 'pdf-as-web/src/main/java/at/gv/egiz/pdfas/web')
-rw-r--r--pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/filter/ExceptionCatchFilter.java126
1 files changed, 67 insertions, 59 deletions
diff --git a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/filter/ExceptionCatchFilter.java b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/filter/ExceptionCatchFilter.java
index 7b126a40..675b1d6b 100644
--- a/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/filter/ExceptionCatchFilter.java
+++ b/pdf-as-web/src/main/java/at/gv/egiz/pdfas/web/filter/ExceptionCatchFilter.java
@@ -46,14 +46,13 @@ import at.gv.egiz.pdfas.web.helper.PdfAsHelper;
*/
public class ExceptionCatchFilter implements Filter {
- private static final Logger logger = LoggerFactory
- .getLogger(ExceptionCatchFilter.class);
-
- /**
- * Default constructor.
- */
- public ExceptionCatchFilter() {
- }
+ private static final Logger logger = LoggerFactory.getLogger(ExceptionCatchFilter.class);
+
+ /**
+ * Default constructor.
+ */
+ public ExceptionCatchFilter() {
+ }
/**
* @see Filter#destroy()
@@ -64,65 +63,74 @@ public class ExceptionCatchFilter implements Filter {
/**
* @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
*/
- public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
+ public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
+ throws IOException, ServletException {
try {
-
- if(request instanceof HttpServletRequest) {
-
- logger.debug("Processing Parameters into Attributes");
- HttpServletRequest httpRequest = (HttpServletRequest)request;
- MDC.put("SESSION_ID", httpRequest.getSession().getId());
-
- logger.warn("Access from IP {}", getClientIpAddr(httpRequest));
-
- PdfAsHelper.logAccess(httpRequest);
- @SuppressWarnings("unchecked")
- Enumeration<String> parameterNames = httpRequest.getParameterNames();
- while(parameterNames.hasMoreElements()) {
- String name = parameterNames.nextElement();
- String value = httpRequest.getParameter(name);
- request.setAttribute(name, value);
+
+ if (request instanceof HttpServletRequest) {
+ HttpServletRequest httpRequest = (HttpServletRequest) request;
+ MDC.put("SESSION_ID", httpRequest.getSession().getId());
+ logger.debug("Processing Parameters into Attributes");
+ logger.warn("Access from IP {}", getClientIpAddr(httpRequest));
+
+ PdfAsHelper.logAccess(httpRequest);
+ @SuppressWarnings("unchecked")
+ Enumeration<String> parameterNames = httpRequest.getParameterNames();
+ while (parameterNames.hasMoreElements()) {
+ String name = parameterNames.nextElement();
+ String value = httpRequest.getParameter(name);
+ request.setAttribute(name, value);
+ }
}
- }
-
- try {
- chain.doFilter(request, response);
- } finally {
- if(request instanceof HttpServletResponse) {
- HttpServletResponse resp = (HttpServletResponse)response;
- logger.debug("Got response status: {}", resp.getStatus());
+
+ try {
+ chain.doFilter(request, response);
+ } finally {
+ if (response != null) {
+ if (response instanceof HttpServletResponse) {
+ HttpServletResponse resp = (HttpServletResponse) response;
+ logger.debug("Got response status: {}", resp.getStatus());
+ } else {
+ logger.warn("Response is not a HttpServletResponse!");
+ }
+ } else {
+ logger.warn("Response is not a HttpServletResponse!");
+ }
}
- }
+ } catch (Throwable e) {
+ logger.error("Unhandled exception found", e);
+ throw new ServletException(e.getMessage());
} finally {
MDC.remove("SESSION_ID");
}
- /*} catch(Throwable e) {
- System.err.println("Unhandled Exception found!");
- e.printStackTrace(System.err);
- logger.error("Unhandled Exception found!", e);
- }*/
+ /*
+ * } catch(Throwable e) {
+ * System.err.println("Unhandled Exception found!");
+ * e.printStackTrace(System.err);
+ * logger.error("Unhandled Exception found!", e); }
+ */
+ }
+
+ public static String getClientIpAddr(HttpServletRequest request) {
+ String ip = request.getHeader("X-Forwarded-For");
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("Proxy-Client-IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("WL-Proxy-Client-IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_CLIENT_IP");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getHeader("HTTP_X_FORWARDED_FOR");
+ }
+ if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
+ ip = request.getRemoteAddr();
+ }
+ return ip;
}
- public static String getClientIpAddr(HttpServletRequest request) {
- String ip = request.getHeader("X-Forwarded-For");
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("Proxy-Client-IP");
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("WL-Proxy-Client-IP");
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("HTTP_CLIENT_IP");
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getHeader("HTTP_X_FORWARDED_FOR");
- }
- if (ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {
- ip = request.getRemoteAddr();
- }
- return ip;
- }
-
/**
* @see Filter#init(FilterConfig)
*/