Skip to content

Commit

Permalink
Merge pull request #267 from jrfinc/fix/issue-266
Browse files Browse the repository at this point in the history
Fixes issue #266
  • Loading branch information
ar authored Oct 21, 2022
2 parents a468489 + 833687e commit fd42beb
Showing 1 changed file with 22 additions and 17 deletions.
39 changes: 22 additions & 17 deletions modules/qrest/src/main/java/org/jpos/qrest/ValidateParams.java
Original file line number Diff line number Diff line change
Expand Up @@ -191,31 +191,35 @@ private boolean checkMandatoryPathParams (Context ctx) {

private boolean checkMandatoryQueryParams (Context ctx) {
Map<String,Object> queryParams = ctx.get(Constants.QUERYPARAMS);
boolean validParams = true;
for (Map.Entry<String,Pattern> 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<String,Object> queryParams = ctx.get(Constants.QUERYPARAMS);
boolean validParams = true;
for (Map.Entry<String,Pattern> 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<String,JsonSchema> entry : mandatoryJson.entrySet()) {
String value = ctx.getString(entry.getKey());
ProcessingReport report;
Expand All @@ -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<String,JsonSchema> entry : optionalJson.entrySet()) {
String value = ctx.getString(entry.getKey());
ProcessingReport report;
Expand All @@ -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;
}
}

0 comments on commit fd42beb

Please sign in to comment.