Search in sources :

Example 1 with XSD

use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.

the class ClassLoaderWSDLLocator method getXsds.

@Override
public Set<XSD> getXsds() throws ConfigurationException {
    Set<XSD> xsds = new HashSet<XSD>();
    if (getSoapVersion() == null || "1.1".equals(getSoapVersion()) || "any".equals(getSoapVersion())) {
        XSD xsd = new XSD();
        xsd.setClassLoader(classLoader);
        xsd.setNamespace(SoapValidator.SoapVersion.VERSION_1_1.namespace);
        xsd.setResource(SoapValidator.SoapVersion.VERSION_1_1.location);
        xsd.init();
        xsds.add(xsd);
    }
    if ("1.2".equals(getSoapVersion()) || "any".equals(getSoapVersion())) {
        XSD xsd = new XSD();
        xsd.setClassLoader(classLoader);
        xsd.setNamespace(SoapValidator.SoapVersion.VERSION_1_2.namespace);
        xsd.setResource(SoapValidator.SoapVersion.VERSION_1_2.location);
        xsd.init();
        xsds.add(xsd);
    }
    if (StringUtils.isNotEmpty(getSchemaLocationToAdd())) {
        StringTokenizer st = new StringTokenizer(getSchemaLocationToAdd(), ", \t\r\n\f");
        while (st.hasMoreTokens()) {
            XSD xsd = new XSD();
            xsd.setClassLoader(classLoader);
            xsd.setNamespace(st.nextToken());
            if (st.hasMoreTokens()) {
                xsd.setResource(st.nextToken());
            }
            xsd.init();
            xsds.add(xsd);
        }
    }
    List<Schema> schemas = new ArrayList<Schema>();
    List types = definition.getTypes().getExtensibilityElements();
    for (Iterator i = types.iterator(); i.hasNext(); ) {
        ExtensibilityElement type = (ExtensibilityElement) i.next();
        QName qn = type.getElementType();
        if (SchemaUtils.WSDL_SCHEMA.equals(qn)) {
            final Schema schema = (Schema) type;
            addNamespaces(schema, definition.getNamespaces());
            schemas.add(schema);
        }
    }
    List<Schema> filteredSchemas;
    Map<Schema, String> filteredReferences = null;
    Map<Schema, String> filteredNamespaces = null;
    if (StringUtils.isEmpty(schemaLocation)) {
        filteredSchemas = schemas;
    } else {
        filteredSchemas = new ArrayList<Schema>();
        filteredReferences = new HashMap<Schema, String>();
        filteredNamespaces = new HashMap<Schema, String>();
        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) {
            if (!split[i + 1].startsWith(RESOURCE_INTERNAL_REFERENCE_PREFIX)) {
                throw new ConfigurationException("Schema reference " + split[i + 1] + " should start with '" + RESOURCE_INTERNAL_REFERENCE_PREFIX + "'");
            }
            try {
                int j = Integer.parseInt(split[i + 1].substring(RESOURCE_INTERNAL_REFERENCE_PREFIX.length())) - 1;
                filteredSchemas.add(schemas.get(j));
                filteredReferences.put(schemas.get(j), RESOURCE_INTERNAL_REFERENCE_PREFIX + (j + 1));
                filteredNamespaces.put(schemas.get(j), split[i]);
            } catch (Exception e) {
                throw new ConfigurationException("Schema reference " + split[i + 1] + " not valid or not found");
            }
        }
    }
    for (Schema schema : filteredSchemas) {
        XSD xsd = new XSD();
        xsd.setClassLoader(classLoader);
        xsd.setWsdlSchema(definition, schema);
        xsd.setResource(getWsdl());
        if (StringUtils.isNotEmpty(schemaLocation)) {
            xsd.setResourceInternalReference(filteredReferences.get(schema));
            xsd.setNamespace(filteredNamespaces.get(schema));
        } else {
            xsd.setResourceInternalReference(RESOURCE_INTERNAL_REFERENCE_PREFIX + (filteredSchemas.indexOf(schema) + 1));
        }
        xsd.setAddNamespaceToSchema(isAddNamespaceToSchema());
        xsd.setImportedSchemaLocationsToIgnore(getImportedSchemaLocationsToIgnore());
        xsd.setUseBaseImportedSchemaLocationsToIgnore(isUseBaseImportedSchemaLocationsToIgnore());
        xsd.setImportedNamespacesToIgnore(getImportedNamespacesToIgnore());
        xsd.init();
        xsds.add(xsd);
    }
    return xsds;
}
Also used : QName(nl.nn.javax.xml.namespace.QName) Schema(nl.nn.javax.wsdl.extensions.schema.Schema) XSD(nl.nn.adapterframework.validation.XSD) ArrayList(java.util.ArrayList) ExtensibilityElement(nl.nn.javax.wsdl.extensions.ExtensibilityElement) WSDLException(nl.nn.javax.wsdl.WSDLException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) StringTokenizer(java.util.StringTokenizer) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) NodeList(org.w3c.dom.NodeList) List(java.util.List) HashSet(java.util.HashSet)

Example 2 with XSD

use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.

the class XmlValidator method getSchemas.

@Override
public List<Schema> getSchemas(IPipeLineSession session) throws PipeRunException {
    List<Schema> xsds = new ArrayList<Schema>();
    String schemaLocation = getSchemasId(session);
    if (schemaSessionKey != null) {
        final URL url = ClassUtils.getResourceURL(classLoader, schemaLocation);
        if (url == null) {
            throw new PipeRunException(this, getLogPrefix(session) + "could not find schema at [" + schemaLocation + "]");
        }
        XSD xsd = new XSD();
        xsd.setClassLoader(classLoader);
        xsd.setNoNamespaceSchemaLocation(schemaLocation);
        try {
            xsd.init();
        } catch (ConfigurationException e) {
            throw new PipeRunException(this, "Could not init xsd", e);
        }
        xsds.add(xsd);
        return xsds;
    }
    return null;
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Schema(nl.nn.adapterframework.validation.Schema) ArrayList(java.util.ArrayList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) XSD(nl.nn.adapterframework.validation.XSD) URL(java.net.URL)

Example 3 with XSD

use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.

the class XSDTest method xsdName.

@Test
public void xsdName() throws URISyntaxException, XMLStreamException, IOException, ConfigurationException {
    XSD xsd = new XSD();
    xsd.setResource("XSDTest/v1 test.xsd");
    xsd.setNamespace("http://test");
    xsd.init();
    assertEquals("XSDTest/v1 test.xsd", xsd.getResourceTarget());
}
Also used : XSD(nl.nn.adapterframework.validation.XSD) Test(org.junit.Test)

Example 4 with XSD

use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.

the class Wsdl method zip.

/**
 * Generates a zip file (and writes it to the given outputstream), containing the WSDL and all referenced XSD's.
 * @see #wsdl(java.io.OutputStream, String)
 */
public void zip(OutputStream stream, String servletName) throws IOException, ConfigurationException, XMLStreamException, NamingException {
    ZipOutputStream out = new ZipOutputStream(stream);
    // First an entry for the WSDL itself:
    ZipEntry wsdlEntry = new ZipEntry(getFilename() + ".wsdl");
    out.putNextEntry(wsdlEntry);
    wsdl(out, servletName);
    out.closeEntry();
    // And then all XSD's
    Set<String> entries = new HashSet<String>();
    for (XSD xsd : xsds) {
        String zipName = xsd.getResourceTarget();
        if (entries.add(zipName)) {
            ZipEntry xsdEntry = new ZipEntry(zipName);
            out.putNextEntry(xsdEntry);
            XMLStreamWriter writer = WsdlUtils.getWriter(out, false);
            SchemaUtils.xsdToXmlStreamWriter(xsd, writer);
            out.closeEntry();
        } else {
            warn("Duplicate xsds in " + this + " " + xsd + " " + xsds);
        }
    }
    out.close();
}
Also used : ZipOutputStream(java.util.zip.ZipOutputStream) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) ZipEntry(java.util.zip.ZipEntry) XSD(nl.nn.adapterframework.validation.XSD) HashSet(java.util.HashSet)

Example 5 with XSD

use of nl.nn.adapterframework.validation.XSD in project iaf by ibissource.

the class Wsdl method getXsds.

public Set<XSD> getXsds(IXmlValidator xmlValidator) throws IOException, XMLStreamException, ConfigurationException {
    Set<XSD> xsds = new HashSet<XSD>();
    String inputSchema = xmlValidator.getSchema();
    if (inputSchema != null) {
        // In case of a WebServiceListener using soap=true it might be
        // valid to use the schema attribute (in which case the schema
        // doesn't have a namespace) as the WebServiceListener will
        // remove the soap envelop and body element before it is
        // validated. In this case we use the serviceNamespaceURI from
        // the WebServiceListener as the namespace for the schema.
        XSD xsd = new XSD();
        xsd.setClassLoader(pipeLine.getAdapter().getConfiguration().getClassLoader());
        xsd.setNamespace(webServiceListenerNamespace);
        xsd.setResource(inputSchema);
        xsd.setAddNamespaceToSchema(true);
        xsd.init();
        xsds.add(xsd);
    } else {
        xsds = xmlValidator.getXsds();
        Set<XSD> remove = new HashSet<XSD>();
        for (XSD xsd : xsds) {
            if (excludeXsds.contains(xsd.getNamespace())) {
                remove.add(xsd);
            }
        }
        xsds.removeAll(remove);
    }
    return xsds;
}
Also used : XSD(nl.nn.adapterframework.validation.XSD) 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