use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.
the class XmlValidator method getSchemas.
public List<Schema> getSchemas(boolean checkRootValidations) throws ConfigurationException {
Set<XSD> xsds = getXsds();
if (StringUtils.isEmpty(getNoNamespaceSchemaLocation())) {
xsds = SchemaUtils.getXsdsRecursive(xsds);
if (checkRootValidations) {
checkInputRootValidations(xsds);
checkOutputRootValidations(xsds);
}
try {
Map<String, Set<XSD>> xsdsGroupedByNamespace = SchemaUtils.getXsdsGroupedByNamespace(xsds, false);
xsds = SchemaUtils.mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes(classLoader, xsdsGroupedByNamespace, null);
} catch (Exception e) {
throw new ConfigurationException(getLogPrefix(null) + "could not merge schema's", e);
}
} else {
// Support redefine for noNamespaceSchemaLocation for backwards
// compatibility. It's deprecated in the latest specification:
// http://www.w3.org/TR/xmlschema11-1/#modify-schema
// It's difficult to support redefine in
// mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes so
// we only use getXsdsRecursive here for root validation. Xerces
// will need to resolve the imports, includes an redefines itself.
// See comment in method XercesXmlValidator.stringToXMLInputSource()
// too. The latest specification also specifies override:
// http://www.w3.org/TR/xmlschema11-1/#override-schema
// But this functionality doesn't seem to be (properly) supported by
// Xerces (yet). WSDL generation was the main reason to introduce
// mergeXsdsGroupedByNamespaceToSchemasWithoutIncludes, in case of
// noNamespaceSchemaLocation the WSDL generator doesn't use
// XmlValidator.getXsds(). See comment in Wsdl.getXsds() too.
Set<XSD> xsds_temp = SchemaUtils.getXsdsRecursive(xsds, false);
if (checkRootValidations) {
checkInputRootValidations(xsds_temp);
checkOutputRootValidations(xsds_temp);
}
}
List<Schema> schemas = new ArrayList<Schema>();
SchemaUtils.sortByDependencies(xsds, schemas);
return schemas;
}
use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.
the class XmlValidator method checkRootValidation.
private void checkRootValidation(List<String> path, Set<XSD> xsds) throws ConfigurationException {
boolean found = false;
String validElements = path.get(path.size() - 1);
List<String> validElementsAsList = Arrays.asList(validElements.split(","));
for (String validElement : validElementsAsList) {
if (StringUtils.isNotEmpty(validElement)) {
List<String> allRootTags = new ArrayList<String>();
for (XSD xsd : xsds) {
for (String rootTag : xsd.getRootTags()) {
allRootTags.add(rootTag);
if (validElement.equals(rootTag)) {
found = true;
}
}
}
if (!found) {
ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
String msg = getLogPrefix(null) + "Element '" + validElement + "' not in list of available root elements " + allRootTags;
configWarnings.add(log, msg);
}
}
}
}
use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.
the class XmlValidator method getXsds.
public Set<XSD> getXsds() throws ConfigurationException {
Set<XSD> xsds = new HashSet<XSD>();
if (StringUtils.isNotEmpty(getNoNamespaceSchemaLocation())) {
XSD xsd = new XSD();
xsd.setClassLoader(classLoader);
xsd.setNoNamespaceSchemaLocation(getNoNamespaceSchemaLocation());
xsd.setResource(getNoNamespaceSchemaLocation());
xsd.init();
xsds.add(xsd);
} else {
String[] split = schemaLocation.trim().split("\\s+");
if (split.length % 2 != 0)
throw new ConfigurationException("The schema must exist from an even number of strings, but it is " + schemaLocation);
for (int i = 0; i < split.length; i += 2) {
XSD xsd = new XSD();
xsd.setClassLoader(classLoader);
xsd.setNamespace(split[i]);
xsd.setResource(split[i + 1]);
xsd.setAddNamespaceToSchema(isAddNamespaceToSchema());
xsd.setImportedSchemaLocationsToIgnore(getImportedSchemaLocationsToIgnore());
xsd.setUseBaseImportedSchemaLocationsToIgnore(isUseBaseImportedSchemaLocationsToIgnore());
xsd.setImportedNamespacesToIgnore(getImportedNamespacesToIgnore());
xsd.init();
xsds.add(xsd);
}
}
return xsds;
}
use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.
the class Wsdl method getRootElement.
protected QName getRootElement(Set<XSD> xsds, String root, String namespace) {
String firstRoot = null;
if (root.trim().length() > 0) {
String[] roots = root.trim().split(",", -1);
firstRoot = roots[0].trim();
for (XSD xsd : xsds) {
for (String rootTag : xsd.getRootTags()) {
if (firstRoot.equals(rootTag)) {
if (StringUtils.isEmpty(namespace) || namespace.equals(xsd.getNamespace())) {
String prefix = prefixByXsd.get(xsd);
return new QName(namespaceByPrefix.get(prefix), firstRoot, prefix);
}
}
}
}
if (StringUtils.isEmpty(namespace)) {
warn("Root element '" + firstRoot + "' not found in XSD's");
} else {
warn("Root element '" + firstRoot + "' with namespace '" + namespace + "' not found in XSD's");
}
}
return null;
}
use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.
the class Wsdl method init.
public void init() throws IOException, XMLStreamException, ConfigurationException {
inputXsds = new HashSet<XSD>();
outputXsds = new HashSet<XSD>();
xsds = new HashSet<XSD>();
rootXsds = new HashSet<XSD>();
Set<XSD> inputRootXsds = new HashSet<XSD>();
inputRootXsds.addAll(getXsds(inputValidator));
rootXsds.addAll(inputRootXsds);
inputXsds.addAll(SchemaUtils.getXsdsRecursive(inputRootXsds));
xsds.addAll(inputXsds);
if (outputValidator != null) {
Set<XSD> outputRootXsds = new HashSet<XSD>();
outputRootXsds.addAll(getXsds(outputValidator));
rootXsds.addAll(outputRootXsds);
outputXsds.addAll(SchemaUtils.getXsdsRecursive(outputRootXsds));
xsds.addAll(outputXsds);
} else {
if (isMixedValidator) {
outputXsds.addAll(inputXsds);
}
}
prefixByXsd = new LinkedHashMap<XSD, String>();
namespaceByPrefix = new LinkedHashMap<String, String>();
int prefixCount = 1;
xsdsGroupedByNamespace = SchemaUtils.getXsdsGroupedByNamespace(xsds, true);
for (String namespace : xsdsGroupedByNamespace.keySet()) {
// (see http://www.w3.org/TR/xml-names/#ns-decl).
if (!"http://www.w3.org/XML/1998/namespace".equals(namespace)) {
for (XSD xsd : xsdsGroupedByNamespace.get(namespace)) {
prefixByXsd.put(xsd, "ns" + prefixCount);
}
namespaceByPrefix.put("ns" + prefixCount, namespace);
prefixCount++;
}
}
for (XSD xsd : xsds) {
if (StringUtils.isEmpty(xsd.getTargetNamespace()) && !xsd.isAddNamespaceToSchema()) {
warn("XSD '" + xsd + "' doesn't have a targetNamespace and addNamespaceToSchema is false");
}
}
inputRoot = getRoot(inputValidator);
inputHeaderElement = getHeaderElement(inputValidator, inputXsds);
inputHeaderIsOptional = isHeaderOptional(inputValidator);
inputBodyElement = getBodyElement(inputValidator, inputXsds, "inputValidator");
if (outputValidator != null) {
outputRoot = getRoot(outputValidator);
outputHeaderElement = getHeaderElement(outputValidator, outputXsds);
outputHeaderIsOptional = isHeaderOptional(outputValidator);
outputBodyElement = getBodyElement(outputValidator, outputXsds, "outputValidator");
} else {
if (isMixedValidator) {
outputRoot = getRoot(inputValidator, true);
outputHeaderElement = inputHeaderElement;
outputHeaderIsOptional = inputHeaderIsOptional;
outputBodyElement = getBodyElement(inputValidator, outputXsds, "outputValidator", true);
}
}
for (IListener listener : WsdlUtils.getListeners(pipeLine.getAdapter())) {
if (listener instanceof WebServiceListener) {
httpActive = true;
} else if (listener instanceof JmsListener) {
jmsActive = true;
} else if (listener instanceof JavaListener) {
JavaListener jl = (JavaListener) listener;
if (jl.isHttpWsdl())
httpActive = true;
}
}
}
Aggregations