use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class ValidatorEntityExpansionTest method parseAndRenderString.
@Override
public String parseAndRenderString(String xsd, String xmlIn) throws Exception {
// AbstractXmlValidator instance = implementation.newInstance();
// instance.setSchemasProvider(new SchemasProviderImpl(SCHEMA_NAMESPACE, xsd));
// instance.setIgnoreUnknownNamespaces(false);
// instance.setAddNamespaceToSchema(false);
// instance.configure("Setup");
// String result=instance.validate(xmlIn, new PipeLineSessionBase(), "test");
// System.out.println("Validation Result:"+result);
// return instance.get
// return result;
AbstractXmlValidator instance = implementation.newInstance();
System.out.println("Created instance [" + instance.getClass().getName() + "]");
instance.setSchemasProvider(new SchemasProviderImpl(SCHEMA_NAMESPACE, xsd));
instance.setThrowException(true);
instance.setFullSchemaChecking(true);
instance.configure("init");
PipeLineSessionBase session = new PipeLineSessionBase();
ValidationContext context = instance.createValidationContext(session, null, null);
XMLReader reader = instance.getValidatingParser(session, context, false);
StringReader sr = new StringReader(xmlIn);
InputSource is = new InputSource(sr);
final StringBuffer sb = new StringBuffer();
ContentHandler ch = new DefaultHandler() {
boolean elementOpen;
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
if (elementOpen) {
sb.append(">");
elementOpen = false;
}
sb.append(ch, start, length);
}
@Override
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException {
sb.append("<" + localName);
sb.append(" xmlns=\"").append(uri).append("\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
for (int i = 0; i < atts.getLength(); i++) {
sb.append(' ').append(atts.getLocalName(i)).append("=\"").append(atts.getValue(i)).append('"');
}
elementOpen = true;
}
@Override
public void endElement(String uri, String localName, String qName) throws SAXException {
if (elementOpen) {
sb.append("/>");
elementOpen = false;
} else {
sb.append("</" + localName + ">");
}
}
@Override
public void ignorableWhitespace(char[] ch, int start, int length) throws SAXException {
// ignore
}
};
// String testString;
// try {
// testString = XmlUtils.identityTransform((String) xmlIn);
// } catch (DomBuilderException e) {
// throw new XmlValidatorException("caught DomBuilderException", e);
// }
// System.out.println("TestStr:"+testString);
reader.setContentHandler(ch);
reader.parse(is);
instance.finalizeValidation(context, session, null);
XmlValidatorErrorHandler errorHandler = context.getErrorHandler();
if (errorHandler.hasErrorOccured()) {
throw new SAXException(errorHandler.getReasons());
}
return sb.toString();
}
use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class ShowConfigurationStatusTest method initXMLUnit.
@Before
public void initXMLUnit() throws IOException {
XMLUnit.setIgnoreWhitespace(true);
XMLUnit.setIgnoreDiffBetweenTextAndCDATA(true);
session = new PipeLineSessionBase();
session.put("method", "GET");
}
use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class SoapValidatorTest method validate12_explicitversion.
@Test
public void validate12_explicitversion() throws ConfigurationException, IOException, PipeRunException {
SoapValidator xml = getSoapValidator(true, "1.2");
xml.doPipe(getTestXml("/SoapValidator/valid_soap_1.2.xml"), new PipeLineSessionBase());
}
use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class SoapValidatorTest method validate12.
@Test
public void validate12() throws ConfigurationException, IOException, PipeRunException {
SoapValidator xml = getSoapValidator(true);
System.out.println("1 " + new Date());
xml.doPipe(getTestXml("/SoapValidator/valid_soap.xml"), new PipeLineSessionBase());
System.out.println("2" + new Date());
xml.doPipe(getTestXml("/SoapValidator/valid_soap.xml"), new PipeLineSessionBase());
System.out.println("3" + new Date());
}
use of nl.nn.adapterframework.core.PipeLineSessionBase in project iaf by ibissource.
the class SoapValidatorTest method validate12_invalid_body.
@Test(expected = PipeRunException.class)
public void validate12_invalid_body() throws ConfigurationException, IOException, PipeRunException {
SoapValidator xml = getSoapValidator();
xml.setSoapVersion("1.1");
xml.doPipe(getTestXml("/SoapValidator/invalid_soap_body.xml"), new PipeLineSessionBase());
}
Aggregations