Search in sources :

Example 41 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException 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 42 with PipeRunException

use of nl.nn.adapterframework.core.PipeRunException 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 43 with PipeRunException

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

the class LabelFormat method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    try {
        String result;
        if (getDirection().equalsIgnoreCase(DIRECTION_XML2LABEL)) {
            Variant v = new Variant(input);
            DocumentBuilder documentBuilder = XmlUtils.getDocumentBuilderFactory().newDocumentBuilder();
            Document document = documentBuilder.parse(new InputSource(new StringReader(v.asString())));
            result = XmlToLabelFormat.doTransformation(document).toString();
            return new PipeRunResult(getForward(), result);
        } else {
            Variant v = new Variant(input);
            XMLReader reader = XMLReaderFactory.createXMLReader("nl.nn.adapterframework.extensions.rekenbox.CalcboxOutputReader");
            CalcboxContentHandler handler = new CalcboxContentHandler(v.asString());
            reader.setContentHandler(handler);
            return new PipeRunResult(getForward(), handler.getStringResult());
        }
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "cannot transform", e);
    }
}
Also used : Variant(nl.nn.adapterframework.util.Variant) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) InputSource(org.xml.sax.InputSource) DocumentBuilder(javax.xml.parsers.DocumentBuilder) StringReader(java.io.StringReader) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Document(org.w3c.dom.Document) XMLReader(org.xml.sax.XMLReader) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 44 with PipeRunException

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

the class RekenBoxCaller method doPipe.

/**
 * positie 1 t/m 8 bepalen de naam van de executable, of tot aan de ':' (wat het eerst komt)
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (!(input instanceof String))
        throw new PipeRunException(this, getLogPrefix(session) + "expected java.lang.String, got [" + input.getClass().getName() + "], value [" + input + "]");
    String sInput = (String) input;
    // log.debug("Pipe ["+name+"] got input ["+sInput+"]");
    String rekenboxName = getRekenBoxName();
    if (StringUtils.isEmpty(rekenboxName)) {
        rekenboxName = sInput;
        if (rekenboxName.length() >= 8)
            rekenboxName = rekenboxName.substring(0, 8);
        // find end or position of first colon.
        rekenboxName = (rekenboxName + ":").substring(0, (rekenboxName + ":").indexOf(":")).trim();
    }
    if (rekenboxName.equals("")) {
        throw new PipeRunException(this, getLogPrefix(session) + "cannot determine rekenboxName from [" + sInput + "]");
    }
    int i = rekenboxName.length();
    int n = sInput.length();
    while (i < n && " :;".indexOf(sInput.charAt(i)) >= 0) {
        i++;
    }
    String rekenboxInput = sInput.substring(i);
    String exeName = runPath + rekenboxName + "." + executableExtension;
    if (!(new File(exeName).exists())) {
        throw new PipeRunException(this, getLogPrefix(session) + "executable file [" + exeName + "] does not exist; requestmessage: [" + sInput + "]");
    }
    if (getRekenboxSessionKey() != null) {
        session.put(getRekenboxSessionKey(), rekenboxName);
    }
    String baseFileName = getBaseFileName();
    String inputFileName = inputOutputDirectory + baseFileName + ".INV";
    String outputFileName = inputOutputDirectory + baseFileName + ".UIT";
    String callAndArgs;
    String callType = getCommandLineType();
    if ((callType == null) || (callType.equals("switches"))) {
        callAndArgs = exeName + " /I" + inputFileName + " /U" + outputFileName + " /P" + templateDir;
    } else if (callType.equals("straight")) {
        callAndArgs = exeName + " " + inputFileName + " " + outputFileName + " " + templateDir;
    } else if (callType.equals("redirected")) {
        callAndArgs = exeName + " " + inputFileName + " " + templateDir;
    } else
        throw new PipeRunException(this, getLogPrefix(session) + "unknown commandLineType: " + callType);
    try {
        // put input in a file
        Misc.stringToFile(rekenboxInput, inputFileName);
        // precreating outputfile is necessary for L76HB000
        log.debug(getLogPrefix(session) + " precreating outputfile [" + outputFileName + "]");
        new File(outputFileName).createNewFile();
        log.debug(getLogPrefix(session) + " will issue command [" + callAndArgs + "]");
        // execute
        Runtime rt = Runtime.getRuntime();
        Process child = rt.exec(callAndArgs);
        String result;
        if (callType.equals("redirected")) {
            result = Misc.streamToString(child.getInputStream(), "\n", true);
        } else {
            child.waitFor();
            // read output
            result = Misc.fileToString(outputFileName, "\n", true);
        }
        log.debug(getLogPrefix(session) + " completed call. Process exit code is: " + child.exitValue());
        // log.debug("Pipe ["+name+"] retrieved result ["+result+"]");
        return new PipeRunResult(getForward(), result);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "got Exception executing rekenbox", e);
    } finally {
        // cleanup
        if (isCleanup()) {
            new File(inputFileName).delete();
            new File(outputFileName).delete();
        }
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) File(java.io.File) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 45 with PipeRunException

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

the class WsdlGeneratorPipe method doPipe.

@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    InputStream inputStream = (InputStream) session.get("file");
    if (inputStream == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null value from session under key [" + getSessionKey() + "]");
    }
    File tempDir;
    String fileName;
    try {
        tempDir = FileUtils.createTempDir(null, "WEB-INF" + File.separator + "classes");
        fileName = (String) session.get("fileName");
        if (FileUtils.extensionEqualsIgnoreCase(fileName, "zip")) {
            FileUtils.unzipStream(inputStream, tempDir);
        } else {
            File file = new File(tempDir, fileName);
            Misc.streamToFile(inputStream, file);
            file.deleteOnExit();
        }
    } catch (IOException e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on uploading and unzipping/writing file", e);
    }
    File propertiesFile = new File(tempDir, getPropertiesFileName());
    PipeLine pipeLine;
    ClassLoader originalClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        DirectoryClassLoader directoryClassLoader = new DirectoryClassLoader(tempDir.getPath());
        Thread.currentThread().setContextClassLoader(directoryClassLoader);
        if (propertiesFile.exists()) {
            pipeLine = createPipeLineFromPropertiesFile(propertiesFile);
        } else {
            File xsdFile = FileUtils.getFirstFile(tempDir);
            pipeLine = createPipeLineFromXsdFile(xsdFile);
        }
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
    } finally {
        if (originalClassLoader != null) {
            Thread.currentThread().setContextClassLoader(originalClassLoader);
        }
    }
    Object result = null;
    OutputStream zipOut = null;
    OutputStream fullWsdlOut = null;
    try {
        Adapter adapter = new Adapter();
        adapter.setConfiguration(new Configuration(null));
        String fileBaseName = FileUtils.getBaseName(fileName).replaceAll(" ", "_");
        adapter.setName(fileBaseName);
        GenericReceiver genericReceiver = new GenericReceiver();
        EsbJmsListener esbJmsListener = new EsbJmsListener();
        esbJmsListener.setQueueConnectionFactoryName("jms/qcf_" + fileBaseName);
        esbJmsListener.setDestinationName("jms/dest_" + fileBaseName);
        genericReceiver.setListener(esbJmsListener);
        adapter.registerReceiver(genericReceiver);
        pipeLine.setAdapter(adapter);
        Wsdl wsdl = null;
        wsdl = new Wsdl(pipeLine);
        wsdl.setIndent(true);
        wsdl.setDocumentation(getWsdlDocumentation(wsdl.getFilename()));
        wsdl.init();
        File wsdlDir = FileUtils.createTempDir(tempDir);
        // zip (with includes)
        File zipOutFile = new File(wsdlDir, wsdl.getFilename() + ".zip");
        zipOutFile.deleteOnExit();
        zipOut = new FileOutputStream(zipOutFile);
        wsdl.setUseIncludes(true);
        wsdl.zip(zipOut, null);
        // full wsdl (without includes)
        File fullWsdlOutFile = new File(wsdlDir, wsdl.getFilename() + ".wsdl");
        fullWsdlOutFile.deleteOnExit();
        fullWsdlOut = new FileOutputStream(fullWsdlOutFile);
        wsdl.setUseIncludes(false);
        wsdl.wsdl(fullWsdlOut, null);
        Dir2Xml dx = new Dir2Xml();
        dx.setPath(wsdlDir.getPath());
        result = dx.getDirList();
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on generating wsdl", e);
    } finally {
        try {
            if (zipOut != null) {
                zipOut.close();
            }
            if (fullWsdlOut != null) {
                fullWsdlOut.close();
            }
        } catch (IOException e1) {
            log.warn("exception closing outputstream", e1);
        }
    }
    return new PipeRunResult(getForward(), result);
}
Also used : Dir2Xml(nl.nn.adapterframework.util.Dir2Xml) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) Configuration(nl.nn.adapterframework.configuration.Configuration) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) Adapter(nl.nn.adapterframework.core.Adapter) IOException(java.io.IOException) Wsdl(nl.nn.adapterframework.soap.Wsdl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) GenericReceiver(nl.nn.adapterframework.receivers.GenericReceiver) FileOutputStream(java.io.FileOutputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) DirectoryClassLoader(nl.nn.adapterframework.configuration.classloaders.DirectoryClassLoader) PipeLine(nl.nn.adapterframework.core.PipeLine) File(java.io.File)

Aggregations

PipeRunException (nl.nn.adapterframework.core.PipeRunException)101 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)65 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)40 IOException (java.io.IOException)34 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)32 PipeForward (nl.nn.adapterframework.core.PipeForward)20 ParameterException (nl.nn.adapterframework.core.ParameterException)16 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)13 Parameter (nl.nn.adapterframework.parameters.Parameter)12 InputStream (java.io.InputStream)10 File (java.io.File)9 Map (java.util.Map)9 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)6 PipeStartException (nl.nn.adapterframework.core.PipeStartException)6 ArrayList (java.util.ArrayList)5 ZipInputStream (java.util.zip.ZipInputStream)5 IAdapter (nl.nn.adapterframework.core.IAdapter)5