use of io.vertigo.vega.plugins.webservice.handler.converter.JsonConverter in project vertigo by KleeGroup.
the class JsonConverterWebServiceHandlerPlugin method readParameterValue.
private void readParameterValue(final Request request, final WebServiceCallContext routeContext, final WebServiceParam webServiceParam) {
try {
boolean found = false;
JsonReader jsonReaderToApply = null;
JsonConverter jsonConverterToApply = null;
for (final JsonReader jsonReader : jsonReaders.get(webServiceParam.getParamType())) {
jsonReaderToApply = jsonReader;
for (final JsonConverter jsonConverter : jsonConverters.get(jsonReader.getSupportedOutput())) {
if (jsonConverter.canHandle(webServiceParam.getType())) {
jsonConverterToApply = jsonConverter;
found = true;
break;
}
}
if (found) {
break;
}
}
// -----
Assertion.checkNotNull(jsonReaderToApply, "Can't parse param {0} of service {1} {2} no compatible JsonReader found for {3}", webServiceParam.getFullName(), routeContext.getWebServiceDefinition().getVerb(), routeContext.getWebServiceDefinition().getPath(), webServiceParam.getParamType());
Assertion.checkNotNull(jsonConverterToApply, "Can't parse param {0} of service {1} {2} no compatible JsonConverter found for {3} {4}", webServiceParam.getFullName(), routeContext.getWebServiceDefinition().getVerb(), routeContext.getWebServiceDefinition().getPath(), webServiceParam.getParamType(), webServiceParam.getType());
// -----
final Object converterSource = jsonReaderToApply.extractData(request, webServiceParam, routeContext);
if (converterSource != null) {
// On ne convertit pas les null
jsonConverterToApply.populateWebServiceCallContext(converterSource, webServiceParam, routeContext);
} else if (webServiceParam.isOptional()) {
routeContext.setParamValue(webServiceParam, null);
}
Assertion.checkNotNull(routeContext.getParamValue(webServiceParam), "RestParam not found : {0}", webServiceParam);
} catch (final JsonSyntaxException e) {
throw new JsonSyntaxException("Error parsing param " + webServiceParam.getFullName() + " on service " + routeContext.getWebServiceDefinition().getVerb() + " " + routeContext.getWebServiceDefinition().getPath(), e);
}
}
Aggregations