Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes issue #266 #267

Merged
merged 1 commit into from
Oct 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
}