Search in sources :

Example 1 with JsonConverter

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);
    }
}
Also used : JsonSyntaxException(com.google.gson.JsonSyntaxException) PrimitiveJsonConverter(io.vertigo.vega.plugins.webservice.handler.converter.PrimitiveJsonConverter) VFileJsonConverter(io.vertigo.vega.plugins.webservice.handler.converter.VFileJsonConverter) JsonConverter(io.vertigo.vega.plugins.webservice.handler.converter.JsonConverter) DtListJsonConverter(io.vertigo.vega.plugins.webservice.handler.converter.DtListJsonConverter) DtObjectJsonConverter(io.vertigo.vega.plugins.webservice.handler.converter.DtObjectJsonConverter) ImplicitJsonConverter(io.vertigo.vega.plugins.webservice.handler.converter.ImplicitJsonConverter) DefaultJsonConverter(io.vertigo.vega.plugins.webservice.handler.converter.DefaultJsonConverter) DtListDeltaJsonConverter(io.vertigo.vega.plugins.webservice.handler.converter.DtListDeltaJsonConverter) PathJsonReader(io.vertigo.vega.plugins.webservice.handler.reader.PathJsonReader) QueryJsonReader(io.vertigo.vega.plugins.webservice.handler.reader.QueryJsonReader) RequestJsonReader(io.vertigo.vega.plugins.webservice.handler.reader.RequestJsonReader) HeaderJsonReader(io.vertigo.vega.plugins.webservice.handler.reader.HeaderJsonReader) BodyJsonReader(io.vertigo.vega.plugins.webservice.handler.reader.BodyJsonReader) JsonReader(io.vertigo.vega.plugins.webservice.handler.reader.JsonReader) InnerBodyJsonReader(io.vertigo.vega.plugins.webservice.handler.reader.InnerBodyJsonReader)

Aggregations

JsonSyntaxException (com.google.gson.JsonSyntaxException)1 DefaultJsonConverter (io.vertigo.vega.plugins.webservice.handler.converter.DefaultJsonConverter)1 DtListDeltaJsonConverter (io.vertigo.vega.plugins.webservice.handler.converter.DtListDeltaJsonConverter)1 DtListJsonConverter (io.vertigo.vega.plugins.webservice.handler.converter.DtListJsonConverter)1 DtObjectJsonConverter (io.vertigo.vega.plugins.webservice.handler.converter.DtObjectJsonConverter)1 ImplicitJsonConverter (io.vertigo.vega.plugins.webservice.handler.converter.ImplicitJsonConverter)1 JsonConverter (io.vertigo.vega.plugins.webservice.handler.converter.JsonConverter)1 PrimitiveJsonConverter (io.vertigo.vega.plugins.webservice.handler.converter.PrimitiveJsonConverter)1 VFileJsonConverter (io.vertigo.vega.plugins.webservice.handler.converter.VFileJsonConverter)1 BodyJsonReader (io.vertigo.vega.plugins.webservice.handler.reader.BodyJsonReader)1 HeaderJsonReader (io.vertigo.vega.plugins.webservice.handler.reader.HeaderJsonReader)1 InnerBodyJsonReader (io.vertigo.vega.plugins.webservice.handler.reader.InnerBodyJsonReader)1 JsonReader (io.vertigo.vega.plugins.webservice.handler.reader.JsonReader)1 PathJsonReader (io.vertigo.vega.plugins.webservice.handler.reader.PathJsonReader)1 QueryJsonReader (io.vertigo.vega.plugins.webservice.handler.reader.QueryJsonReader)1 RequestJsonReader (io.vertigo.vega.plugins.webservice.handler.reader.RequestJsonReader)1