Search in sources :

Example 1 with Xml2Json

use of nl.nn.adapterframework.align.Xml2Json in project iaf by ibissource.

the class Json2XmlValidator method alignXml2Json.

protected PipeRunResult alignXml2Json(String messageToValidate, IPipeLineSession session, boolean responseMode) throws XmlValidatorException, PipeRunException, ConfigurationException {
    ValidationContext context = validator.createValidationContext(session, getRootValidations(responseMode), getInvalidRootNamespaces());
    XMLReader parser = validator.getValidatingParser(session, context);
    XmlAligner aligner = new XmlAligner((PSVIProvider) parser);
    Xml2Json xml2json = new Xml2Json(aligner, isCompactJsonArrays(), !isJsonWithRootElements());
    parser.setContentHandler(aligner);
    aligner.setContentHandler(xml2json);
    aligner.setErrorHandler(context.getErrorHandler());
    String resultEvent = validator.validate(messageToValidate, session, getLogPrefix(session), parser, xml2json, context);
    String out = xml2json.toString();
    PipeForward forward = determineForward(resultEvent, session, responseMode);
    PipeRunResult result = new PipeRunResult(forward, out);
    return result;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) XmlAligner(nl.nn.adapterframework.align.XmlAligner) Xml2Json(nl.nn.adapterframework.align.Xml2Json) PipeForward(nl.nn.adapterframework.core.PipeForward) XMLReader(org.xml.sax.XMLReader) ValidationContext(nl.nn.adapterframework.validation.ValidationContext)

Example 2 with Xml2Json

use of nl.nn.adapterframework.align.Xml2Json in project iaf by ibissource.

the class Json2XmlValidator method alignJson.

protected PipeRunResult alignJson(String messageToValidate, IPipeLineSession session, boolean responseMode) throws PipeRunException, XmlValidatorException {
    ValidationContext context;
    ValidatorHandler validatorHandler;
    try {
        context = validator.createValidationContext(session, getRootValidations(responseMode), getInvalidRootNamespaces());
        validatorHandler = validator.getValidatorHandler(session, context);
    } catch (ConfigurationException e) {
        throw new PipeRunException(this, "Cannot create ValidationContext", e);
    }
    String resultEvent;
    String out = null;
    try {
        Json2Xml aligner = new Json2Xml(validatorHandler, context.getXsModels(), isCompactJsonArrays(), getMessageRoot(responseMode), isStrictJsonArraySyntax());
        if (StringUtils.isNotEmpty(getTargetNamespace())) {
            aligner.setTargetNamespace(getTargetNamespace());
        }
        aligner.setDeepSearch(isDeepSearch());
        aligner.setErrorHandler(context.getErrorHandler());
        aligner.setFailOnWildcards(isFailOnWildcards());
        ParameterList parameterList = getParameterList();
        if (parameterList != null) {
            ParameterResolutionContext prc = new ParameterResolutionContext(messageToValidate, session, isNamespaceAware(), false);
            Map<String, Object> parametervalues = null;
            parametervalues = prc.getValueMap(parameterList);
            aligner.setOverrideValues(parametervalues);
        }
        JsonStructure jsonStructure = Json.createReader(new StringReader(messageToValidate)).read();
        if (getOutputFormat(session, responseMode).equalsIgnoreCase(FORMAT_JSON)) {
            Xml2Json xml2json = new Xml2Json(aligner, isCompactJsonArrays(), !isJsonWithRootElements());
            aligner.setContentHandler(xml2json);
            aligner.startParse(jsonStructure);
            out = xml2json.toString();
        } else {
            Source source = aligner.asSource(jsonStructure);
            out = XmlUtils.source2String(source, isProduceNamespaceLessXml());
        }
    } catch (Exception e) {
        resultEvent = validator.finalizeValidation(context, session, e);
    }
    resultEvent = validator.finalizeValidation(context, session, null);
    PipeForward forward = determineForward(resultEvent, session, responseMode);
    PipeRunResult result = new PipeRunResult(forward, out);
    return result;
}
Also used : ValidatorHandler(javax.xml.validation.ValidatorHandler) PipeForward(nl.nn.adapterframework.core.PipeForward) Source(javax.xml.transform.Source) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XmlValidatorException(nl.nn.adapterframework.validation.XmlValidatorException) ValidationContext(nl.nn.adapterframework.validation.ValidationContext) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StringReader(java.io.StringReader) ParameterList(nl.nn.adapterframework.parameters.ParameterList) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Xml2Json(nl.nn.adapterframework.align.Xml2Json) Json2Xml(nl.nn.adapterframework.align.Json2Xml) JsonStructure(javax.json.JsonStructure)

Aggregations

Xml2Json (nl.nn.adapterframework.align.Xml2Json)2 PipeForward (nl.nn.adapterframework.core.PipeForward)2 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)2 ValidationContext (nl.nn.adapterframework.validation.ValidationContext)2 StringReader (java.io.StringReader)1 JsonStructure (javax.json.JsonStructure)1 Source (javax.xml.transform.Source)1 ValidatorHandler (javax.xml.validation.ValidatorHandler)1 Json2Xml (nl.nn.adapterframework.align.Json2Xml)1 XmlAligner (nl.nn.adapterframework.align.XmlAligner)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 ParameterList (nl.nn.adapterframework.parameters.ParameterList)1 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)1 XmlValidatorException (nl.nn.adapterframework.validation.XmlValidatorException)1 XMLReader (org.xml.sax.XMLReader)1