Search in sources :

Example 11 with PipeLineSessionBase

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

the class SoapValidatorTest method validate12_invalidversion.

@Test(expected = PipeRunException.class)
public void validate12_invalidversion() throws ConfigurationException, IOException, PipeRunException {
    SoapValidator xml = getSoapValidator();
    xml.setSoapVersion("1.2");
    xml.doPipe(getTestXml("/SoapValidator/valid_soap.xml"), new PipeLineSessionBase());
}
Also used : PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase) Test(org.junit.Test)

Example 12 with PipeLineSessionBase

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

the class AbstractXmlValidatorTest method validationTest.

protected void validationTest(String namespace, String systemId, String inputfile, boolean addNamespaceToSchema, boolean expectedValid) throws IllegalAccessException, InstantiationException, XmlValidatorException, IOException, PipeRunException, ConfigurationException {
    AbstractXmlValidator instance = implementation.newInstance();
    instance.setSchemasProvider(new SchemasProviderImpl(namespace, systemId));
    instance.setIgnoreUnknownNamespaces(false);
    instance.setAddNamespaceToSchema(addNamespaceToSchema);
    instance.configure("Setup");
    String result = instance.validate(getTestXml(inputfile), new PipeLineSessionBase(), "test", null, null, false);
    if (expectedValid) {
        Assert.assertEquals("valid XML", result);
    } else {
        Assert.assertEquals("Invalid XML: does not comply to XSD", result);
    }
}
Also used : PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 13 with PipeLineSessionBase

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

the class AbstractXmlValidatorTestBase method validate.

@Override
public String validate(String rootNamespace, String schemaLocation, boolean addNamespaceToSchema, boolean ignoreUnknownNamespaces, String inputfile, String[] expectedFailureReasons) throws ConfigurationException, InstantiationException, IllegalAccessException, XmlValidatorException, PipeRunException, IOException {
    AbstractXmlValidator instance = implementation.newInstance();
    instance.setSchemasProvider(getSchemasProvider(schemaLocation, addNamespaceToSchema));
    instance.setIgnoreUnknownNamespaces(ignoreUnknownNamespaces);
    // instance.registerForward("success");
    instance.setThrowException(true);
    instance.setFullSchemaChecking(true);
    String testXml = inputfile != null ? getTestXml(inputfile + ".xml") : null;
    PipeLineSessionBase session = new PipeLineSessionBase();
    try {
        instance.configure("init");
        String result = instance.validate(testXml, session, "test", null, null, false);
        evaluateResult(result, session, null, expectedFailureReasons);
        return result;
    } catch (Exception e) {
        evaluateResult(null, session, e, expectedFailureReasons);
        return "Invalid XML";
    }
}
Also used : PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 14 with PipeLineSessionBase

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

the class Json2XmlValidatorTest method validate.

@Override
public String validate(String rootNamespace, String schemaLocation, boolean addNamespaceToSchema, boolean ignoreUnknownNamespaces, String inputFile, String[] expectedFailureReasons) throws IOException, ConfigurationException, PipeRunException {
    init();
    PipeLineSessionBase session = new PipeLineSessionBase();
    // instance.setSchemasProvider(getSchemasProvider(schemaLocation, addNamespaceToSchema));
    instance.setSchemaLocation(schemaLocation);
    instance.setAddNamespaceToSchema(addNamespaceToSchema);
    instance.setIgnoreUnknownNamespaces(ignoreUnknownNamespaces);
    // instance.registerForward("success");
    instance.setThrowException(true);
    instance.setFullSchemaChecking(true);
    instance.setTargetNamespace(rootNamespace);
    instance.registerForward(new PipeForward("failure", null));
    instance.registerForward(new PipeForward("parserError", null));
    instance.configure(null);
    validator.setSchemasProvider(getSchemasProvider(schemaLocation, addNamespaceToSchema));
    validator.setIgnoreUnknownNamespaces(ignoreUnknownNamespaces);
    validator.configure("setup");
    String testXml = inputFile != null ? getTestXml(inputFile + ".xml") : null;
    System.out.println("testXml [" + inputFile + ".xml] contents [" + testXml + "]");
    String xml2json = (String) jsonPipe.doPipe(testXml, session).getResult();
    System.out.println("testXml [" + inputFile + ".xml] to json [" + xml2json + "]");
    String testJson = inputFile != null ? getTestXml(inputFile + ".json") : null;
    System.out.println("testJson [" + testJson + "]");
    try {
        PipeRunResult prr = instance.doPipe(testJson, session);
        String result = (String) prr.getResult();
        System.out.println("result [" + ToStringBuilder.reflectionToString(prr) + "]");
        String event;
        if (prr.getPipeForward().getName().equals("success")) {
            event = "valid XML";
        } else {
            if (prr.getPipeForward().getName().equals("failure")) {
                event = "Invalid XML";
            } else {
                event = prr.getPipeForward().getName();
            }
        }
        evaluateResult(event, session, null, expectedFailureReasons);
        try {
            String validationResult = validator.validate(result, session, "check result", null, null, false);
            evaluateResult(validationResult, session, null, expectedFailureReasons);
            return result;
        } catch (Exception e) {
            fail("result XML must be valid");
        }
        return result;
    } catch (PipeRunException pre) {
        evaluateResult("Invalid XML", session, pre, expectedFailureReasons);
    }
    return null;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 15 with PipeLineSessionBase

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

the class HttpListenerServlet method invoke.

public void invoke(String message, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
    ISecurityHandler securityHandler = new HttpSecurityHandler(request);
    IPipeLineSession messageContext = new PipeLineSessionBase();
    messageContext.put(IPipeLineSession.securityHandlerKey, securityHandler);
    messageContext.put("httpListenerServletRequest", request);
    messageContext.put("httpListenerServletResponse", response);
    String service = request.getParameter(SERVICE_ID_PARAM);
    Enumeration paramnames = request.getParameterNames();
    while (paramnames.hasMoreElements()) {
        String paramname = (String) paramnames.nextElement();
        String paramvalue = request.getParameter(paramname);
        if (log.isDebugEnabled()) {
            log.debug("HttpListenerServlet setting parameter [" + paramname + "] to [" + paramvalue + "]");
        }
        messageContext.put(paramname, paramvalue);
    }
    try {
        log.debug("HttpListenerServlet calling service [" + service + "]");
        String result = sd.dispatchRequest(service, null, message, messageContext);
        response.getWriter().print(result);
    } catch (ListenerException e) {
        log.warn("HttpListenerServlet caught exception, will rethrow as ServletException", e);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    }
}
Also used : ISecurityHandler(nl.nn.adapterframework.core.ISecurityHandler) ListenerException(nl.nn.adapterframework.core.ListenerException) Enumeration(java.util.Enumeration) IPipeLineSession(nl.nn.adapterframework.core.IPipeLineSession) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

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