Search in sources :

Example 6 with PipeLineSessionBase

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();
}
Also used : InputSource(org.xml.sax.InputSource) Attributes(org.xml.sax.Attributes) ContentHandler(org.xml.sax.ContentHandler) DefaultHandler(org.xml.sax.helpers.DefaultHandler) SAXException(org.xml.sax.SAXException) StringReader(java.io.StringReader) XMLReader(org.xml.sax.XMLReader) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 7 with PipeLineSessionBase

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");
}
Also used : PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase) Before(org.junit.Before)

Example 8 with PipeLineSessionBase

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());
}
Also used : PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase) Test(org.junit.Test)

Example 9 with 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());
}
Also used : Date(java.util.Date) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase) Test(org.junit.Test)

Example 10 with PipeLineSessionBase

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());
}
Also used : PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase) Test(org.junit.Test)

Aggregations

PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)38 Test (org.junit.Test)14 IPipeLineSession (nl.nn.adapterframework.core.IPipeLineSession)12 IOException (java.io.IOException)8 AbstractXmlValidator (nl.nn.adapterframework.validation.AbstractXmlValidator)8 JavaxXmlValidator (nl.nn.adapterframework.validation.JavaxXmlValidator)8 XercesXmlValidator (nl.nn.adapterframework.validation.XercesXmlValidator)8 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)6 Iterator (java.util.Iterator)5 Map (java.util.Map)5 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)5 HashMap (java.util.HashMap)4 ListenerException (nl.nn.adapterframework.core.ListenerException)4 PipeForward (nl.nn.adapterframework.core.PipeForward)4 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)4 ArrayList (java.util.ArrayList)3 Date (java.util.Date)3 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 SenderException (nl.nn.adapterframework.core.SenderException)3 ParseException (java.text.ParseException)2