diff options
author | Abyss777 <abyss@fox5.ru> | 2018-02-02 11:53:02 +0500 |
---|---|---|
committer | Abyss777 <abyss@fox5.ru> | 2018-02-02 11:53:02 +0500 |
commit | 1d56c58847d811086d65115d7dca7a705bfda92a (patch) | |
tree | 9edd5d2230d2fdad6a7d70ba255328dc0b5a2f17 | |
parent | 16f912fa4ebfbb89a5d99116c12740229fa09b67 (diff) | |
download | trackermap-server-1d56c58847d811086d65115d7dca7a705bfda92a.tar.gz trackermap-server-1d56c58847d811086d65115d7dca7a705bfda92a.tar.bz2 trackermap-server-1d56c58847d811086d65115d7dca7a705bfda92a.zip |
Remove custom text and repeated casting
-rw-r--r-- | src/org/traccar/api/MediaFilter.java | 15 |
1 files changed, 7 insertions, 8 deletions
diff --git a/src/org/traccar/api/MediaFilter.java b/src/org/traccar/api/MediaFilter.java index de15209e7..4685ce05b 100644 --- a/src/org/traccar/api/MediaFilter.java +++ b/src/org/traccar/api/MediaFilter.java @@ -43,6 +43,7 @@ public class MediaFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { + HttpServletResponse httpResponse = ((HttpServletResponse) response); try { HttpSession session = ((HttpServletRequest) request).getSession(false); Long userId = null; @@ -54,8 +55,7 @@ public class MediaFilter implements Filter { } } if (userId == null) { - ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_UNAUTHORIZED); - response.getWriter().println("Not authorized"); + httpResponse.sendError(HttpServletResponse.SC_UNAUTHORIZED); return; } @@ -68,19 +68,18 @@ public class MediaFilter implements Filter { if (device != null) { Context.getPermissionsManager().checkDevice(userId, device.getId()); } else { - ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_NOT_FOUND); - response.getWriter().println("Device not found"); + httpResponse.sendError(HttpServletResponse.SC_NOT_FOUND); return; } } chain.doFilter(request, response); } catch (SecurityException e) { - ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_FORBIDDEN); - response.getWriter().println(Log.exceptionStack(e)); + httpResponse.setStatus(HttpServletResponse.SC_FORBIDDEN); + httpResponse.getWriter().println(Log.exceptionStack(e)); } catch (SQLException e) { - ((HttpServletResponse) response).setStatus(HttpServletResponse.SC_BAD_REQUEST); - response.getWriter().println(Log.exceptionStack(e)); + httpResponse.setStatus(HttpServletResponse.SC_BAD_REQUEST); + httpResponse.getWriter().println(Log.exceptionStack(e)); } } |