}
if (resourceType != null && !"".equals(resourceType)) {
String resourcePath = request.getRequestPathInfo().getResourcePath();
ValidationModel vm = validationService.getValidationModel(resourceType, resourcePath);
if (vm != null) {
ValidationResult vr = validationService.validate(requestParameters, vm);
if (vr.isValid()) {
RequestDispatcherOptions options = new RequestDispatcherOptions();
options.setReplaceSelectors(" ");
request.getRequestDispatcher(request.getResource(), options).forward(request, response);
} else {
response.setContentType("application/json");
JSONObject json = new JSONObject();
try {
json.put("success", false);
JSONObject messages = new JSONObject();
for (Map.Entry<String, List<String>> entry : vr.getFailureMessages().entrySet()) {
String key = entry.getKey();
JSONArray errors = new JSONArray();
for (String message : entry.getValue()) {
errors.put(message);
}