class AbstractMethodValidator implements MethodValidator {

    @Override
    public MessageError validate(HttpServletRequest request, MessageError messageError) {
        Map<String, String> headers = Collections.list(request.getHeaderNames())
                                          .stream()
                                          .collect(Collectors.toMap(h -> h, request::getHeader));

        // This is implemented for handling the headers in case insensitive mode.
        TreeMap<String, String> caseInsensitiveHeaders = new TreeMap<>(String.CASE_INSENSITIVE_ORDER);
        caseInsensitiveHeaders.putAll(headers);

        MessageError resultingMessageError = messageError;

        Map<String, List<String>> queryParameters = extractQueryParameters(request);
        Map<String, String> pathParameters = extractPathParameters(request);

        for (PathParameterValidator pathParameterValidator : validatorWrapper.getPathParameterValidators()) {
            resultingMessageError = pathParameterValidator.validate(pathParameters, resultingMessageError);
        }

        for (QueryParameterValidator queryParameterValidator : validatorWrapper.getQueryParameterValidators()) {
            resultingMessageError = queryParameterValidator.validate(queryParameters, resultingMessageError);
        }

        for (HeaderValidator headerValidator : validatorWrapper.getHeaderValidators()) {
            resultingMessageError = headerValidator.validate(caseInsensitiveHeaders, resultingMessageError);
        }

        for (BodyValidator bodyValidator : validatorWrapper.getBodyValidators()) {
            resultingMessageError = bodyValidator.validate(request, resultingMessageError);
        }

        return resultingMessageError;
    }

}