Search in sources :

Example 1 with XmlProxyException

use of nl.nn.coolgen.proxy.XmlProxyException 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)

Aggregations

ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 PropertyVetoException (java.beans.PropertyVetoException)1 IOException (java.io.IOException)1 StringReader (java.io.StringReader)1 StringWriter (java.io.StringWriter)1 Writer (java.io.Writer)1 Source (javax.xml.transform.Source)1 TransformerException (javax.xml.transform.TransformerException)1 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)1 PipeRunException (nl.nn.adapterframework.core.PipeRunException)1 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)1 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)1 Variant (nl.nn.adapterframework.util.Variant)1 CoolGenXMLProxy (nl.nn.coolgen.proxy.CoolGenXMLProxy)1 XmlProxyException (nl.nn.coolgen.proxy.XmlProxyException)1