Search in sources :

Example 21 with PipeRunException

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

the class PostboxRetrieverPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (!(input instanceof String)) {
        throw new PipeRunException(this, "String expected, got a [" + input.getClass().getName() + "]");
    }
    Map threadContext = null;
    try {
        threadContext = getListener().openThread();
        Object rawMessage = getListener().retrieveRawMessage((String) input, threadContext);
        if (rawMessage == null)
            return new PipeRunResult(findForward("emptyPostbox"), getResultOnEmptyPostbox());
        String result = getListener().getStringFromRawMessage(rawMessage, threadContext);
        return new PipeRunResult(getForward(), result);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "caught exception", e);
    } finally {
        try {
            getListener().closeThread(threadContext);
        } catch (ListenerException le) {
            log.error(getLogPrefix(session) + "got error closing listener");
        }
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ListenerException(nl.nn.adapterframework.core.ListenerException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ListenerException(nl.nn.adapterframework.core.ListenerException)

Example 22 with PipeRunException

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

the class CompareStringPipe method doPipe.

@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    ParameterValueList pvl = null;
    if (getParameterList() != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
    }
    String operand1 = getParameterValue(pvl, OPERAND1);
    if (operand1 == null) {
        if (StringUtils.isNotEmpty(getSessionKey1())) {
            operand1 = (String) session.get(getSessionKey1());
        }
        if (operand1 == null) {
            operand1 = (String) input;
        }
    }
    String operand2 = getParameterValue(pvl, OPERAND2);
    if (operand2 == null) {
        if (StringUtils.isNotEmpty(getSessionKey2())) {
            operand2 = (String) session.get(getSessionKey2());
        }
        if (operand2 == null) {
            operand2 = (String) input;
        }
    }
    if (isXml()) {
        try {
            operand1 = XmlUtils.canonicalize(operand1);
            operand2 = XmlUtils.canonicalize(operand2);
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + " Exception on pretty printing input", e);
        }
    }
    String ip = getParameterValue(pvl, IGNOREPATTERNS);
    if (ip != null) {
        try {
            Node n = XmlUtils.buildNode(ip);
            if (n.getNodeName().equals("ignores")) {
                NodeList nList = n.getChildNodes();
                for (int i = 0; i <= nList.getLength() - 1; i++) {
                    Node cn = nList.item(i);
                    if (cn.getNodeName().equals("ignore")) {
                        NodeList cnList = cn.getChildNodes();
                        String after = null;
                        String before = null;
                        for (int j = 0; j <= cnList.getLength() - 1; j++) {
                            Node ccn = cnList.item(j);
                            if (ccn.getNodeName().equals("after")) {
                                after = ccn.getFirstChild().getNodeValue();
                            } else {
                                if (ccn.getNodeName().equals("before")) {
                                    before = ccn.getFirstChild().getNodeValue();
                                }
                            }
                        }
                        operand1 = ignoreBetween(operand1, after, before);
                        operand2 = ignoreBetween(operand2, after, before);
                    }
                }
            }
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + " Exception on ignoring parts of input", e);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("operand1 [" + operand1 + "]");
        log.debug("operand2 [" + operand2 + "]");
    }
    int comparison = operand1.compareTo(operand2);
    if (comparison == 0)
        return new PipeRunResult(findForward(EQUALSFORWARD), input);
    else if (comparison < 0)
        return new PipeRunResult(findForward(LESSTHANFORWARD), input);
    else
        return new PipeRunResult(findForward(GREATERTHANFORWARD), input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) Node(org.w3c.dom.Node) NodeList(org.w3c.dom.NodeList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 23 with PipeRunException

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

the class CompressPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    try {
        Object result;
        InputStream in;
        OutputStream out;
        boolean zipMultipleFiles = false;
        if (messageIsContent) {
            if (input instanceof byte[]) {
                in = new ByteArrayInputStream((byte[]) input);
            } else {
                in = new ByteArrayInputStream(input.toString().getBytes());
            }
        } else {
            if (compress && StringUtils.contains((String) input, ";")) {
                zipMultipleFiles = true;
                in = null;
            } else {
                in = new FileInputStream((String) input);
            }
        }
        if (resultIsContent) {
            out = new ByteArrayOutputStream();
            result = out;
        } else {
            String outFilename = null;
            if (messageIsContent) {
                outFilename = FileUtils.getFilename(getParameterList(), session, (File) null, filenamePattern);
            } else {
                outFilename = FileUtils.getFilename(getParameterList(), session, new File((String) input), filenamePattern);
            }
            File outFile = new File(outputDirectory, outFilename);
            result = outFile.getAbsolutePath();
            out = new FileOutputStream(outFile);
        }
        if (zipMultipleFiles) {
            ZipOutputStream zipper = new ZipOutputStream(out);
            StringTokenizer st = new StringTokenizer((String) input, ";");
            while (st.hasMoreElements()) {
                String fn = st.nextToken();
                String zipEntryName = getZipEntryName(fn, session);
                zipper.putNextEntry(new ZipEntry(zipEntryName));
                in = new FileInputStream(fn);
                try {
                    int readLength = 0;
                    byte[] block = new byte[4096];
                    while ((readLength = in.read(block)) > 0) {
                        zipper.write(block, 0, readLength);
                    }
                } finally {
                    in.close();
                    zipper.closeEntry();
                }
            }
            zipper.close();
            out = zipper;
        } else {
            if (compress) {
                if ("gz".equals(fileFormat) || fileFormat == null && resultIsContent) {
                    out = new GZIPOutputStream(out);
                } else {
                    ZipOutputStream zipper = new ZipOutputStream(out);
                    String zipEntryName = getZipEntryName(input, session);
                    zipper.putNextEntry(new ZipEntry(zipEntryName));
                    out = zipper;
                }
            } else {
                if ("gz".equals(fileFormat) || fileFormat == null && messageIsContent) {
                    in = new GZIPInputStream(in);
                } else {
                    ZipInputStream zipper = new ZipInputStream(in);
                    String zipEntryName = getZipEntryName(input, session);
                    if (zipEntryName.equals("")) {
                        // Use first entry found
                        zipper.getNextEntry();
                    } else {
                        // Position the stream at the specified entry
                        ZipEntry zipEntry = zipper.getNextEntry();
                        while (zipEntry != null && !zipEntry.getName().equals(zipEntryName)) {
                            zipEntry = zipper.getNextEntry();
                        }
                    }
                    in = zipper;
                }
            }
            try {
                int readLength = 0;
                byte[] block = new byte[4096];
                while ((readLength = in.read(block)) > 0) {
                    out.write(block, 0, readLength);
                }
            } finally {
                out.close();
                in.close();
            }
        }
        return new PipeRunResult(getForward(), getResultMsg(result));
    } catch (Exception e) {
        PipeForward exceptionForward = findForward(EXCEPTIONFORWARD);
        if (exceptionForward != null) {
            log.warn(getLogPrefix(session) + "exception occured, forwarded to [" + exceptionForward.getPath() + "]", e);
            String originalMessage;
            if (input instanceof String) {
                originalMessage = (String) input;
            } else {
                originalMessage = "Object of type " + input.getClass().getName();
            }
            String resultmsg = new ErrorMessageFormatter().format(getLogPrefix(session), e, this, originalMessage, session.getMessageId(), 0);
            return new PipeRunResult(exceptionForward, resultmsg);
        }
        throw new PipeRunException(this, "Unexpected exception during compression", e);
    }
}
Also used : GZIPInputStream(java.util.zip.GZIPInputStream) ZipInputStream(java.util.zip.ZipInputStream) FileInputStream(java.io.FileInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) FileOutputStream(java.io.FileOutputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipEntry(java.util.zip.ZipEntry) ByteArrayOutputStream(java.io.ByteArrayOutputStream) PipeForward(nl.nn.adapterframework.core.PipeForward) FileInputStream(java.io.FileInputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) GZIPInputStream(java.util.zip.GZIPInputStream) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) StringTokenizer(java.util.StringTokenizer) ZipInputStream(java.util.zip.ZipInputStream) ErrorMessageFormatter(nl.nn.adapterframework.errormessageformatters.ErrorMessageFormatter) ByteArrayInputStream(java.io.ByteArrayInputStream) GZIPOutputStream(java.util.zip.GZIPOutputStream) ZipOutputStream(java.util.zip.ZipOutputStream) FileOutputStream(java.io.FileOutputStream) PipeRunException(nl.nn.adapterframework.core.PipeRunException) File(java.io.File)

Example 24 with PipeRunException

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

the class DelayPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    try {
        log.info(getLogPrefix(session) + "starts waiting for " + getDelayTime() + " ms.");
        Thread.sleep(getDelayTime());
    } catch (InterruptedException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "delay interrupted", e);
    }
    log.info(getLogPrefix(session) + "ends waiting for " + getDelayTime() + " ms.");
    return new PipeRunResult(getForward(), input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException)

Example 25 with PipeRunException

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

the class BytesOutputPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    Object result = null;
    Variant in = new Variant(input);
    try {
        XMLReader parser = XMLReaderFactory.createXMLReader();
        FieldsContentHandler fieldsContentHandler = new FieldsContentHandler();
        parser.setContentHandler(fieldsContentHandler);
        parser.parse(in.asXmlInputSource());
        result = fieldsContentHandler.getResult();
    } catch (SAXException e) {
        throw new PipeRunException(this, "SAXException", e);
    } catch (IOException e) {
        throw new PipeRunException(this, "IOException", e);
    }
    return new PipeRunResult(getForward(), result);
}
Also used : Variant(nl.nn.adapterframework.util.Variant) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) XMLReader(org.xml.sax.XMLReader) SAXException(org.xml.sax.SAXException)

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