class EncodedCharactersFilter extends ZuulFilter {

    @Override
    public boolean shouldFilter() {
        boolean shouldFilter = true;

        RequestContext context = RequestContext.getCurrentContext();
        final String serviceId = (String) context.get(SERVICE_ID_KEY);

        List<ServiceInstance> instanceList = discoveryClient.getInstances(serviceId);

        List<Map<String, String>> enabledList = instanceList.stream()
            .map(ServiceInstance::getMetadata)
            .filter(metadata -> metadata.get(METADATA_KEY) == null
                || String.valueOf(true).equalsIgnoreCase(metadata.get(METADATA_KEY)))
            .collect(Collectors.toList());

        if (enabledList.size() == instanceList.size()) {
            shouldFilter = false;
        }

        return shouldFilter;
    }

}