Search in sources :

Example 6 with XSD

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;
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Schema(nl.nn.adapterframework.validation.Schema) XSD(nl.nn.adapterframework.validation.XSD) ArrayList(java.util.ArrayList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XmlValidatorException(nl.nn.adapterframework.validation.XmlValidatorException)

Example 7 with XSD

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);
            }
        }
    }
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) ArrayList(java.util.ArrayList) XSD(nl.nn.adapterframework.validation.XSD)

Example 8 with XSD

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;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XSD(nl.nn.adapterframework.validation.XSD) HashSet(java.util.HashSet)

Example 9 with XSD

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;
}
Also used : QName(javax.xml.namespace.QName) XSD(nl.nn.adapterframework.validation.XSD)

Example 10 with XSD

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;
        }
    }
}
Also used : JmsListener(nl.nn.adapterframework.jms.JmsListener) JavaListener(nl.nn.adapterframework.receivers.JavaListener) IListener(nl.nn.adapterframework.core.IListener) XSD(nl.nn.adapterframework.validation.XSD) WebServiceListener(nl.nn.adapterframework.http.WebServiceListener) HashSet(java.util.HashSet)

Aggregations

XSD (nl.nn.adapterframework.validation.XSD)12 HashSet (java.util.HashSet)6 ArrayList (java.util.ArrayList)4 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 Test (org.junit.Test)3 XMLStreamWriter (javax.xml.stream.XMLStreamWriter)2 PipeRunException (nl.nn.adapterframework.core.PipeRunException)2 Schema (nl.nn.adapterframework.validation.Schema)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 IOException (java.io.IOException)1 URL (java.net.URL)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Set (java.util.Set)1 StringTokenizer (java.util.StringTokenizer)1 ZipEntry (java.util.zip.ZipEntry)1 ZipOutputStream (java.util.zip.ZipOutputStream)1 QName (javax.xml.namespace.QName)1