Search in sources :

Example 1 with Variant

use of nl.nn.adapterframework.util.Variant in project iaf by ibissource.

the class CoolGenWrapperPipe method doPipe.

/**
 * Transform the input (optionally), check the conformance to the schema (optionally),
 * call the required proxy, transform the output (optionally)
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    Writer proxyResult;
    String proxypreProc = null;
    Variant inputVar;
    String wrapperResult = "";
    CoolGenXMLProxy proxy;
    ActionListener actionListener = new ActionListener() {

        /**
         * @see java.awt.event.ActionListener#actionPerformed(ActionEvent)
         */
        public String errorMessage;

        public void actionPerformed(ActionEvent e) {
            errorMessage = e.toString();
        }

        public String toString() {
            return errorMessage;
        }
    };
    Source in;
    try {
        log.info(getLogPrefix(session) + "instantiating proxy [" + proxyClassName + "] as a temporary fix for broken comm-bridge connections");
        proxy = createProxy(proxyClassName);
    } catch (ConfigurationException ce) {
        String msg = getLogPrefix(session) + "cannot recreate proxy after exception";
        log.error(msg, ce);
        throw new PipeRunException(this, msg, ce);
    }
    proxy.addExceptionListener(actionListener);
    try {
        inputVar = new Variant(input);
        in = inputVar.asXmlSource();
        if (preProcTransformer != null) {
            proxypreProc = XmlUtils.transformXml(preProcTransformer, in);
            log.debug(getLogPrefix(session) + "] preprocessing transformed message into [" + proxypreProc + "]");
        } else
            proxypreProc = inputVar.asString();
        if (proxyInputFixTransformer != null)
            proxypreProc = XmlUtils.transformXml(proxyInputFixTransformer, proxypreProc);
        proxyResult = new StringWriter(10 * 1024);
        try {
            proxy.clear();
        } catch (PropertyVetoException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "cannot clear CoolGen proxy", e);
        }
        try {
            proxy.executeXML(new StringReader(proxypreProc), proxyResult);
            proxy.removeExceptionListener(actionListener);
            String err = actionListener.toString();
            if (err != null) {
                // if an error occurs, recreate the proxy and throw an exception
                log.debug(getLogPrefix(session) + "got error, recreating proxy with class [" + proxyClassName + "]");
                try {
                    proxy = createProxy(proxyClassName);
                } catch (ConfigurationException e) {
                    throw new PipeRunException(this, getLogPrefix(session) + "cannot recreate proxy [" + proxyClassName + "]", e);
                }
                throw new PipeRunException(this, getLogPrefix(session) + "error excuting proxy [" + proxyClassName + "]:" + err);
            }
        } catch (XmlProxyException xpe) {
            try {
                proxy = createProxy(proxyClassName);
            } catch (ConfigurationException ce) {
                log.error(getLogPrefix(session) + "cannot recreate proxy", xpe);
            }
            throw new PipeRunException(this, getLogPrefix(session) + "error excecuting proxy", xpe);
        }
        if (postProcTransformer != null) {
            log.debug(getLogPrefix(session) + " CoolGen proxy returned: [" + proxyResult.toString() + "]");
            wrapperResult = XmlUtils.transformXml(postProcTransformer, proxyResult.toString());
        } else
            wrapperResult = proxyResult.toString();
    } catch (DomBuilderException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "DomBuilderException excecuting proxy", e);
    } catch (IOException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "IOException excecuting proxy", e);
    } catch (TransformerException e) {
        throw new PipeRunException(this, getLogPrefix(session) + "TransformerException excecuting proxy", e);
    }
    return new PipeRunResult(getForward(), wrapperResult);
}
Also used : CoolGenXMLProxy(nl.nn.coolgen.proxy.CoolGenXMLProxy) ActionEvent(java.awt.event.ActionEvent) IOException(java.io.IOException) Source(javax.xml.transform.Source) Variant(nl.nn.adapterframework.util.Variant) PropertyVetoException(java.beans.PropertyVetoException) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) XmlProxyException(nl.nn.coolgen.proxy.XmlProxyException) ActionListener(java.awt.event.ActionListener) StringWriter(java.io.StringWriter) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StringReader(java.io.StringReader) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) StringWriter(java.io.StringWriter) Writer(java.io.Writer) TransformerException(javax.xml.transform.TransformerException)

Example 2 with Variant

use of nl.nn.adapterframework.util.Variant 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)

Example 3 with Variant

use of nl.nn.adapterframework.util.Variant 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 4 with Variant

use of nl.nn.adapterframework.util.Variant in project iaf by ibissource.

the class AbstractXmlValidator method getInputSource.

protected InputSource getInputSource(Object input) throws XmlValidatorException {
    Variant in = new Variant(input);
    final InputSource is;
    if (isValidateFile()) {
        try {
            is = new InputSource(new InputStreamReader(new FileInputStream(in.asString()), getCharset()));
        } catch (FileNotFoundException e) {
            throw new XmlValidatorException("could not find file [" + in.asString() + "]", e);
        } catch (UnsupportedEncodingException e) {
            throw new XmlValidatorException("could not use charset [" + getCharset() + "]", e);
        }
    } else {
        is = in.asXmlInputSource();
    }
    return is;
}
Also used : Variant(nl.nn.adapterframework.util.Variant) InputSource(org.xml.sax.InputSource) InputStreamReader(java.io.InputStreamReader) FileNotFoundException(java.io.FileNotFoundException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) FileInputStream(java.io.FileInputStream)

Example 5 with Variant

use of nl.nn.adapterframework.util.Variant 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)

Aggregations

Variant (nl.nn.adapterframework.util.Variant)5 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)4 PipeRunException (nl.nn.adapterframework.core.PipeRunException)3 IOException (java.io.IOException)2 StringReader (java.io.StringReader)2 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)2 InputSource (org.xml.sax.InputSource)2 XMLReader (org.xml.sax.XMLReader)2 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyVetoException (java.beans.PropertyVetoException)1 FileInputStream (java.io.FileInputStream)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStreamReader (java.io.InputStreamReader)1 StringWriter (java.io.StringWriter)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Writer (java.io.Writer)1 StringTokenizer (java.util.StringTokenizer)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 Source (javax.xml.transform.Source)1