From 1d56c58847d811086d65115d7dca7a705bfda92a Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 2 Feb 2018 11:53:02 +0500 Subject: Remove custom text and repeated casting --- src/org/traccar/api/MediaFilter.java | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) (limited to 'src') 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)); } } -- cgit v1.2.3