class TomcatFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
        HttpServletRequest req = (HttpServletRequest) request;
        HttpServletResponse res = (HttpServletResponse) response;

        String uri = req.getRequestURI();
        String decodedUri = URLDecoder.decode(uri, "UTF-8");
        final boolean isRequestEncoded = !uri.equals(decodedUri);

        Message message = messageService.createMessage("org.zowe.apiml.gateway.requestContainEncodedSlash", uri);
        if (!allowEncodedSlashes && isRequestEncoded) {
            res.setStatus(HttpStatus.BAD_REQUEST.value());
            res.setContentType(MediaType.APPLICATION_JSON_UTF8_VALUE);
            try {
                mapper.writeValue(res.getWriter(), message.mapToView());
            } catch (IOException e) {
                apimlLog.log("org.zowe.apiml.security.errorWrittingResponse", e.getMessage());
                throw new ServletException("Error writing response", e);
            }
        } else {
            chain.doFilter(request, response);
        }
    }

}