From 833687ef1c7da3d11343b2eed98d6610037c432f Mon Sep 17 00:00:00 2001 From: Josefina Revilla Date: Thu, 20 Oct 2022 15:39:11 -0300 Subject: [PATCH] Fixes issue #266 --- .../java/org/jpos/qrest/ValidateParams.java | 39 +++++++++++-------- 1 file changed, 22 insertions(+), 17 deletions(-) diff --git a/modules/qrest/src/main/java/org/jpos/qrest/ValidateParams.java b/modules/qrest/src/main/java/org/jpos/qrest/ValidateParams.java index 47eb288860..fc6b48c707 100644 --- a/modules/qrest/src/main/java/org/jpos/qrest/ValidateParams.java +++ b/modules/qrest/src/main/java/org/jpos/qrest/ValidateParams.java @@ -191,31 +191,35 @@ private boolean checkMandatoryPathParams (Context ctx) { private boolean checkMandatoryQueryParams (Context ctx) { Map queryParams = ctx.get(Constants.QUERYPARAMS); + boolean validParams = true; for (Map.Entry entry : mandatoryQueryParams.entrySet()) { Object v = queryParams.get(entry.getKey()); String value = v != null ? v.toString() : null; if (value == null) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), "Mandatory param " + entry.getKey().toLowerCase() + " not present"); - return false; + validParams = false; + } else { + validParams = validParams && validParam(ctx, entry, value); } - return validParam(ctx, entry, value); } - return true; + return validParams; } private boolean checkOptionalQueryParams (Context ctx) { Map queryParams = ctx.get(Constants.QUERYPARAMS); + boolean validParams = true; for (Map.Entry entry : optionalQueryParams.entrySet()) { String value = (String) queryParams.get(entry.getKey()); if (value != null) { - return validParam(ctx, entry, value); + validParams = validParams && validParam(ctx, entry, value); } } - return true; + return validParams; } private boolean checkMandatoryJson (Context ctx) { ctx.log ("Mandatory JSON: " + mandatoryJson); + boolean validParams = true; for (Map.Entry entry : mandatoryJson.entrySet()) { String value = ctx.getString(entry.getKey()); ProcessingReport report; @@ -225,20 +229,21 @@ private boolean checkMandatoryJson (Context ctx) { JsonSchema schema = entry.getValue(); JsonNode node = JsonLoader.fromString(value); report = schema.validate(node); + if (!report.isSuccess()) { + ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), report.toString()); + validParams = false; + } } catch(Exception ex) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), ex.toString()); - return false; - } - if (!report.isSuccess()) { - ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), report.toString()); - return false; + validParams = false; } } } - return true; + return validParams; } private boolean checkOptionalJson (Context ctx) { + boolean validParams = true; for (Map.Entry entry : optionalJson.entrySet()) { String value = ctx.getString(entry.getKey()); ProcessingReport report; @@ -247,16 +252,16 @@ private boolean checkOptionalJson (Context ctx) { JsonSchema schema = entry.getValue(); JsonNode node = JsonLoader.fromString(value); report = schema.validate(node); + if (!report.isSuccess()) { + ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), report.toString()); + validParams = false; + } } catch(Exception ex) { ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), ex.toString()); - return false; - } - if (!report.isSuccess()) { - ctx.getResult().fail(ResultCode.BAD_REQUEST, Caller.info(), report.toString()); - return false; + validParams = false; } } } - return true; + return validParams; } }