@Test public void testTenantFilterOK() throws Exception { when(httpServletRequest.getHeaderNames()).thenReturn(httpServletRequestHeaders); when(httpServletRequest.getHeader(GlobalDataRest.X_TENANT_ID)) .thenReturn(headersMap.get(GlobalDataRest.X_TENANT_ID)); when(httpServletRequest.getRequestURI()).thenReturn(NOT_STATUS_ADMIN_URI); filter.doFilter(httpServletRequest, httpServletResponse, filterChain); verify(filterChain).doFilter(httpServletRequest, httpServletResponse); }
@Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Status status = checkTenantHeaders((HttpServletRequest) request); if (Status.PRECONDITION_FAILED.getStatusCode() == status.getStatusCode() || Status.UNAUTHORIZED.getStatusCode() == status.getStatusCode()) { LOGGER.error(GlobalDataRest.X_TENANT_ID + " check failed!"); final HttpServletResponse newResponse = (HttpServletResponse) response; newResponse.setStatus(status.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, newResponse, JsonHandler.createObjectNode().put("Error", GlobalDataRest.X_TENANT_ID + " check failed!")); } else { chain.doFilter(request, response); } }
TenantFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Status status = checkTenantHeaders((HttpServletRequest) request); if (Status.PRECONDITION_FAILED.getStatusCode() == status.getStatusCode() || Status.UNAUTHORIZED.getStatusCode() == status.getStatusCode()) { LOGGER.error(GlobalDataRest.X_TENANT_ID + " check failed!"); final HttpServletResponse newResponse = (HttpServletResponse) response; newResponse.setStatus(status.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, newResponse, JsonHandler.createObjectNode().put("Error", GlobalDataRest.X_TENANT_ID + " check failed!")); } else { chain.doFilter(request, response); } } }
TenantFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Status status = checkTenantHeaders((HttpServletRequest) request); if (Status.PRECONDITION_FAILED.getStatusCode() == status.getStatusCode() || Status.UNAUTHORIZED.getStatusCode() == status.getStatusCode()) { LOGGER.error(GlobalDataRest.X_TENANT_ID + " check failed!"); final HttpServletResponse newResponse = (HttpServletResponse) response; newResponse.setStatus(status.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, newResponse, JsonHandler.createObjectNode().put("Error", GlobalDataRest.X_TENANT_ID + " check failed!")); } else { chain.doFilter(request, response); } }  }
TenantFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Status status = checkTenantHeaders((HttpServletRequest) request); if (Status.PRECONDITION_FAILED.getStatusCode() == status.getStatusCode() || Status.UNAUTHORIZED.getStatusCode() == status.getStatusCode()) { LOGGER.error(GlobalDataRest.X_TENANT_ID + " check failed!"); final HttpServletResponse newResponse = (HttpServletResponse) response; newResponse.setStatus(status.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, newResponse, JsonHandler.createObjectNode().put("Error", GlobalDataRest.X_TENANT_ID + " check failed!")); } else { chain.doFilter(request, response); } }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy(); }
TenantFilter implements Filter { @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { Status status = checkTenantHeaders((HttpServletRequest) request); if (Status.PRECONDITION_FAILED.getStatusCode() == status.getStatusCode() || Status.UNAUTHORIZED.getStatusCode() == status.getStatusCode()) { LOGGER.error(GlobalDataRest.X_TENANT_ID + " check failed!"); final HttpServletResponse newResponse = (HttpServletResponse) response; newResponse.setStatus(status.getStatusCode()); HeaderIdHelper.writeMessageToResponse(request, newResponse, JsonHandler.createObjectNode().put("Error", GlobalDataRest.X_TENANT_ID + " check failed!")); } else { chain.doFilter(request, response); } }  @Override void init(FilterConfig filterConfig); @Override void doFilter(ServletRequest request, ServletResponse response, FilterChain chain); @Override void destroy();  }