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