Search in sources :

Example 21 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class WsdlGeneratorPipe method createValidator.

private EsbSoapValidator createValidator(File xsdFile, String namespace, String root, int rootPosition, int cmhVersion, PipeLine pipeLine) throws ConfigurationException {
    if (xsdFile != null) {
        EsbSoapValidator esbSoapValidator = new EsbSoapValidator();
        esbSoapValidator.setWarn(false);
        esbSoapValidator.setCmhVersion(cmhVersion);
        Resource xsdResource = Resource.getResource(xsdFile.getPath());
        if (StringUtils.isEmpty(namespace)) {
            String xsdTargetNamespace = null;
            try {
                TransformerPool tp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource("*/@targetNamespace", OutputType.TEXT));
                xsdTargetNamespace = tp.transform(xsdResource.asSource());
                if (StringUtils.isNotEmpty(xsdTargetNamespace)) {
                    log.debug("found target namespace [" + xsdTargetNamespace + "] in xsd file [" + xsdFile.getName() + "]");
                } else {
                    // default namespace to prevent
                    // "(IllegalArgumentException) The schema attribute isn't supported"
                    xsdTargetNamespace = "urn:wsdlGenerator";
                    log.warn("could not find target namespace in xsd file [" + xsdFile.getName() + "], assuming namespace [" + xsdTargetNamespace + "]");
                }
            } catch (Exception e) {
                throw new ConfigurationException(e);
            }
            if (StringUtils.isEmpty(xsdTargetNamespace)) {
                esbSoapValidator.setSchema(xsdFile.getName());
            } else {
                esbSoapValidator.setSchemaLocation(xsdTargetNamespace + "\t" + xsdFile.getName());
                esbSoapValidator.setAddNamespaceToSchema(true);
            }
        } else {
            esbSoapValidator.setSchemaLocation(namespace + "\t" + xsdFile.getName());
            esbSoapValidator.setAddNamespaceToSchema(true);
        }
        if (StringUtils.isEmpty(root)) {
            String xsdRoot = null;
            try {
                String rootXPath = "*/*[local-name()='element'][" + rootPosition + "]/@name";
                TransformerPool tp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(rootXPath, OutputType.TEXT));
                xsdRoot = tp.transform(xsdResource.asSource());
                if (StringUtils.isNotEmpty(xsdRoot)) {
                    log.debug("found root element [" + xsdRoot + "] in xsd file [" + xsdFile.getName() + "]");
                    esbSoapValidator.setSoapBody(xsdRoot);
                }
            } catch (Exception e) {
                throw new ConfigurationException(e);
            }
        } else {
            esbSoapValidator.setSoapBody(root);
        }
        esbSoapValidator.setForwardFailureToSuccess(true);
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        esbSoapValidator.registerForward(pf);
        esbSoapValidator.setPipeLine(pipeLine);
        esbSoapValidator.configure();
        return esbSoapValidator;
    }
    return null;
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Resource(nl.nn.adapterframework.core.Resource) PipeForward(nl.nn.adapterframework.core.PipeForward) TransformerPool(nl.nn.adapterframework.util.TransformerPool) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 22 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class ClassLoaderXmlEntityResolver method resolveEntity.

@Override
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
    if (log.isDebugEnabled())
        log.debug("resolveEntity publicId [" + resourceIdentifier.getPublicId() + "] baseSystemId [" + resourceIdentifier.getBaseSystemId() + "] expandedSystemId [" + resourceIdentifier.getExpandedSystemId() + "] literalSystemId [" + resourceIdentifier.getLiteralSystemId() + "] namespace [" + resourceIdentifier.getNamespace() + "]");
    if (resourceIdentifier.getBaseSystemId() == null && resourceIdentifier.getExpandedSystemId() == null && resourceIdentifier.getLiteralSystemId() == null && resourceIdentifier.getNamespace() == null && resourceIdentifier.getPublicId() == null) {
        // return null.
        return null;
    }
    String base = resourceIdentifier.getBaseSystemId();
    String href = resourceIdentifier.getLiteralSystemId();
    if (href == null) {
        // Ignore import with namespace but without schemaLocation
        return null;
    }
    Resource resource;
    try {
        resource = resolveToResource(href, base);
    } catch (TransformerException e) {
        throw new XNIException(e);
    }
    return resource.asXMLInputSource();
}
Also used : Resource(nl.nn.adapterframework.core.Resource) TransformerException(javax.xml.transform.TransformerException) XNIException(org.apache.xerces.xni.XNIException)

Example 23 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class FlowDiagramTest method testAdapter2DotXslWithoutFirstPipe.

@Test
public void testAdapter2DotXslWithoutFirstPipe() throws Exception {
    Resource resource = Resource.getResource("xml/xsl/adapter2dot.xsl");
    TransformerPool transformerPool = TransformerPool.getInstance(resource, 2);
    String adapter = TestFileUtils.getTestFile("/FlowDiagram/pipelineWithoutFirstPipe.xml");
    String dot = TestFileUtils.getTestFile("/FlowDiagram/dot.txt");
    String result = transformerPool.transform(adapter, null);
    assertEquals(dot, result);
}
Also used : Resource(nl.nn.adapterframework.core.Resource) Test(org.junit.Test)

Example 24 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class FlowDiagramTest method testAdapter2DotXslExitInMiddle.

@Test
public void testAdapter2DotXslExitInMiddle() throws Exception {
    Resource resource = Resource.getResource("xml/xsl/adapter2dot.xsl");
    TransformerPool transformerPool = TransformerPool.getInstance(resource, 2);
    String adapter = TestFileUtils.getTestFile("/FlowDiagram/pipelineExitInTheMiddle.xml");
    String dot = TestFileUtils.getTestFile("/FlowDiagram/dot.txt");
    String result = transformerPool.transform(adapter, null);
    assertEquals(dot, result);
}
Also used : Resource(nl.nn.adapterframework.core.Resource) Test(org.junit.Test)

Example 25 with Resource

use of nl.nn.adapterframework.core.Resource in project iaf by ibissource.

the class XmlUtilsTest method testIdentityTransformWithDefaultEntityResolver.

@Test
public void testIdentityTransformWithDefaultEntityResolver() throws Exception {
    // External EntityResolving is still possible with the XMLEntityResolver
    Resource resource = Resource.getResource(new TestScopeProvider(), "XmlUtils/EntityResolution/in-file-entity-c-temp.xml");
    SAXException thrown = assertThrows(SAXException.class, () -> {
        XmlUtils.parseXml(resource, new XmlWriter());
    });
    String errorMessage = "Cannot get resource for publicId [null] with systemId [file:///c:/temp/test.xml] in scope [URLResource ";
    assertTrue("SaxParseException should start with [Cannot get resource ...] but is [" + thrown.getMessage() + "]", thrown.getMessage().startsWith(errorMessage));
}
Also used : TestScopeProvider(nl.nn.adapterframework.testutil.TestScopeProvider) Resource(nl.nn.adapterframework.core.Resource) XmlWriter(nl.nn.adapterframework.xml.XmlWriter) SAXException(org.xml.sax.SAXException) Test(org.junit.Test)

Aggregations

Resource (nl.nn.adapterframework.core.Resource)27 Test (org.junit.Test)12 IOException (java.io.IOException)10 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)7 XmlWriter (nl.nn.adapterframework.xml.XmlWriter)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 SAXException (org.xml.sax.SAXException)6 TransformerException (javax.xml.transform.TransformerException)4 TransformerPool (nl.nn.adapterframework.util.TransformerPool)4 URL (java.net.URL)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ValidatorHandler (javax.xml.validation.ValidatorHandler)2 ConfigurationDigester (nl.nn.adapterframework.configuration.ConfigurationDigester)2 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)2 Digester (org.apache.commons.digester3.Digester)2 QueueInfo (com.tibco.tibjms.admin.QueueInfo)1 TibjmsAdmin (com.tibco.tibjms.admin.TibjmsAdmin)1 TibjmsAdminException (com.tibco.tibjms.admin.TibjmsAdminException)1 File (java.io.File)1