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;
}
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;
}
Aggregations