class TenantFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
        // check if the tenant is not existing or is not an integer
        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);
        }
    }

}