Search in sources :

Example 66 with PipeRunResult

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

the class Adios2XmlPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    Variant v = new Variant(input);
    String result;
    if (DIRECTION_BACKWARD.equalsIgnoreCase(getDirection())) {
        result = makeAdios(v.asXmlInputSource(), session);
    } else {
        String inputstring = v.asString();
        String firstToken = new StringTokenizer(inputstring).nextToken();
        if (firstToken.startsWith("<")) {
            log.info(getLogPrefix(session) + "input is already XML, no conversion performed");
            return new PipeRunResult(noConversionForward, inputstring);
        }
        result = makeXml(v.asString(), session);
    }
    return new PipeRunResult(getForward(), result);
}
Also used : Variant(nl.nn.adapterframework.util.Variant) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) StringTokenizer(java.util.StringTokenizer)

Example 67 with PipeRunResult

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

the class ScanTibcoSolutionPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    StringWriter stringWriter = new StringWriter();
    XMLStreamWriter xmlStreamWriter;
    try {
        xmlStreamWriter = XmlUtils.OUTPUT_FACTORY.createXMLStreamWriter(stringWriter);
        xmlStreamWriter.writeStartDocument();
        xmlStreamWriter.writeStartElement("root");
        xmlStreamWriter.writeAttribute("url", getUrl());
        // xmlStreamWriter.writeAttribute("level",
        // String.valueOf(getLevel()));
        process(xmlStreamWriter, getUrl(), getLevel());
        xmlStreamWriter.writeEndDocument();
        xmlStreamWriter.flush();
        xmlStreamWriter.close();
    } catch (XMLStreamException e) {
        throw new PipeRunException(this, "XMLStreamException", e);
    } catch (DomBuilderException e) {
        throw new PipeRunException(this, "DomBuilderException", e);
    } catch (XPathExpressionException e) {
        throw new PipeRunException(this, "XPathExpressionException", e);
    }
    return new PipeRunResult(getForward(), stringWriter.getBuffer().toString());
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) StringWriter(java.io.StringWriter) XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) XPathExpressionException(javax.xml.xpath.XPathExpressionException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException)

Example 68 with PipeRunResult

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

the class RestListener method transformToXml.

public String transformToXml(String message) throws PipeRunException {
    JsonPipe pipe = new JsonPipe();
    PipeRunResult pipeResult = pipe.doPipe(message, new PipeLineSessionBase());
    return (String) pipeResult.getResult();
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) JsonPipe(nl.nn.adapterframework.pipes.JsonPipe) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 69 with PipeRunResult

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

the class RestListener method transformToJson.

public String transformToJson(String message) throws PipeRunException {
    JsonPipe pipe = new JsonPipe();
    pipe.setDirection("xml2json");
    PipeRunResult pipeResult = pipe.doPipe(message, new PipeLineSessionBase());
    return (String) pipeResult.getResult();
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) JsonPipe(nl.nn.adapterframework.pipes.JsonPipe) PipeLineSessionBase(nl.nn.adapterframework.core.PipeLineSessionBase)

Example 70 with PipeRunResult

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

the class ZipWriterPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (ACTION_CLOSE.equals(getAction())) {
        closeZipWriterHandle(session, true);
        return new PipeRunResult(getForward(), input);
    }
    String msg = null;
    if (input instanceof String) {
        msg = (String) input;
    }
    ParameterResolutionContext prc = new ParameterResolutionContext(msg, session);
    ParameterValueList pvl;
    try {
        pvl = prc.getValues(getParameterList());
    } catch (ParameterException e1) {
        throw new PipeRunException(this, getLogPrefix(session) + "cannot determine filename", e1);
    }
    ZipWriter sessionData = getZipWriter(session);
    if (ACTION_OPEN.equals(getAction())) {
        if (sessionData != null) {
            throw new PipeRunException(this, getLogPrefix(session) + "zipWriterHandle in session key [" + getZipWriterHandle() + "] is already open");
        }
        sessionData = createZipWriter(session, pvl, input);
        return new PipeRunResult(getForward(), input);
    }
    // from here on action must be 'write' or 'stream'
    if (sessionData == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "zipWriterHandle in session key [" + getZipWriterHandle() + "] is not open");
    }
    String filename = (String) pvl.getParameterValue(PARAMETER_FILENAME).getValue();
    if (StringUtils.isEmpty(filename)) {
        throw new PipeRunException(this, getLogPrefix(session) + "filename cannot be empty");
    }
    try {
        if (ACTION_STREAM.equals(getAction())) {
            sessionData.openEntry(filename);
            PipeRunResult prr = new PipeRunResult(getForward(), sessionData.getZipoutput());
            return prr;
        }
        if (ACTION_WRITE.equals(getAction())) {
            try {
                if (isCompleteFileHeader()) {
                    sessionData.writeEntryWithCompletedHeader(filename, input, isCloseInputstreamOnExit(), getCharset());
                } else {
                    sessionData.writeEntry(filename, input, isCloseInputstreamOnExit(), getCharset());
                }
            } catch (IOException e) {
                throw new PipeRunException(this, getLogPrefix(session) + "cannot add data to zipentry for [" + filename + "]", e);
            }
            return new PipeRunResult(getForward(), input);
        }
        throw new PipeRunException(this, getLogPrefix(session) + "illegal action [" + getAction() + "]");
    } catch (CompressionException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "cannot add zipentry for [" + filename + "]", e);
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException) IOException(java.io.IOException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Aggregations

PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)89 PipeRunException (nl.nn.adapterframework.core.PipeRunException)65 PipeForward (nl.nn.adapterframework.core.PipeForward)23 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)22 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)21 IOException (java.io.IOException)17 ParameterException (nl.nn.adapterframework.core.ParameterException)14 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)11 Test (org.junit.Test)11 File (java.io.File)10 Map (java.util.Map)10 ParameterList (nl.nn.adapterframework.parameters.ParameterList)8 InputStream (java.io.InputStream)7 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)7 Parameter (nl.nn.adapterframework.parameters.Parameter)6 FileInputStream (java.io.FileInputStream)4 StringReader (java.io.StringReader)4 Iterator (java.util.Iterator)4 StringTokenizer (java.util.StringTokenizer)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)4