Search in sources :

Example 11 with PipeRunException

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

the class WsdlGeneratorPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String result = null;
    IAdapter adapter;
    if ("input".equals(getFrom())) {
        adapter = ((Adapter) getAdapter()).getConfiguration().getIbisManager().getRegisteredAdapter((String) input);
        if (adapter == null) {
            throw new PipeRunException(this, "Could not find adapter: " + input);
        }
    } else {
        adapter = getPipeLine().getAdapter();
    }
    try {
        Wsdl wsdl = new Wsdl(((Adapter) adapter).getPipeLine());
        wsdl.setDocumentation("Generated at " + AppConstants.getInstance().getResolvedProperty("otap.stage") + "-" + AppConstants.getInstance().getResolvedProperty("otap.side") + " on " + DateUtils.getIsoTimeStamp() + ".");
        wsdl.init();
        ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
        wsdl.wsdl(outputStream, null);
        result = outputStream.toString("UTF-8");
    } catch (Exception e) {
        throw new PipeRunException(this, "Could not generate WSDL for adapter '" + adapter.getName() + "'", e);
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IAdapter(nl.nn.adapterframework.core.IAdapter) Wsdl(nl.nn.adapterframework.soap.Wsdl) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 12 with PipeRunException

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

the class XQueryPipe method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    if (input == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "got null input");
    }
    if (!(input instanceof String)) {
        throw new PipeRunException(this, getLogPrefix(session) + "got an invalid type as input, expected String, got " + input.getClass().getName());
    }
    try {
        String stringResult = (String) input;
        // We already specifically use Saxon in this pipe, hence set xslt2
        // to true to make XmlUtils use the Saxon
        // DocumentBuilderFactoryImpl.
        ParameterResolutionContext prc = new ParameterResolutionContext(stringResult, session, isNamespaceAware(), true);
        Map parametervalues = null;
        if (getParameterList() != null) {
            parametervalues = prc.getValueMap(getParameterList());
        }
        preparedExpression.bindDocument(XQConstants.CONTEXT_ITEM, stringResult, null, null);
        Iterator iterator = getParameterList().iterator();
        while (iterator.hasNext()) {
            Parameter parameter = (Parameter) iterator.next();
            preparedExpression.bindObject(new QName(parameter.getName()), parametervalues.get(parameter.getName()), null);
        }
        XQResultSequence resultSequence = preparedExpression.executeQuery();
        stringResult = resultSequence.getSequenceAsString(null);
        return new PipeRunResult(getForward(), stringResult);
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + " Exception on running xquery", e);
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) QName(javax.xml.namespace.QName) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Iterator(java.util.Iterator) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) MalformedURLException(java.net.MalformedURLException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XQException(javax.xml.xquery.XQException) XQResultSequence(javax.xml.xquery.XQResultSequence)

Example 13 with PipeRunException

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

the class XmlIf method doPipe.

public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    PipeForward pipeForward = null;
    String sInput;
    if (StringUtils.isEmpty(getSessionKey())) {
        if (input == null) {
            sInput = "";
        } else {
            sInput = input.toString();
        }
    } else {
        log.debug(getLogPrefix(session) + "taking input from sessionKey [" + getSessionKey() + "]");
        sInput = (String) session.get(getSessionKey());
    }
    if (tp != null) {
        try {
            forward = tp.transform(sInput, null, isNamespaceAware());
        } catch (Exception e) {
            throw new PipeRunException(this, getLogPrefix(session) + "cannot evaluate expression", e);
        }
    } else {
        if (StringUtils.isEmpty(expressionValue)) {
            if (StringUtils.isEmpty(sInput)) {
                forward = elseForwardName;
            } else {
                forward = thenForwardName;
            }
        } else {
            if (sInput.equals(expressionValue)) {
                forward = thenForwardName;
            } else {
                forward = elseForwardName;
            }
        }
    }
    log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
    pipeForward = findForward(forward);
    if (pipeForward == null) {
        throw new PipeRunException(this, getLogPrefix(null) + "cannot find forward or pipe named [" + forward + "]");
    }
    log.debug(getLogPrefix(session) + "resolved forward [" + forward + "] to path [" + pipeForward.getPath() + "]");
    return new PipeRunResult(pipeForward, input);
}
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) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Example 14 with PipeRunException

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

the class XmlSwitch method doPipe.

/**
 * This is where the action takes place, the switching is done. Pipes may only throw a PipeRunException,
 * to be handled by the caller of this object.<br/>
 * As WebLogic has the problem that when an non-well formed XML stream is given to
 * weblogic.xerces the transformer gets corrupt, on an exception the configuration is done again, so that the
 * transformer is re-initialized.
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String forward = "";
    String sInput = (String) input;
    PipeForward pipeForward = null;
    if (StringUtils.isNotEmpty(getSessionKey())) {
        sInput = (String) session.get(sessionKey);
    }
    if (transformerPool != null) {
        ParameterList parameterList = null;
        ParameterResolutionContext prc = new ParameterResolutionContext(sInput, session, isNamespaceAware());
        ;
        try {
            Map parametervalues = null;
            if (getParameterList() != null) {
                parameterList = getParameterList();
                parametervalues = prc.getValueMap(parameterList);
            }
            forward = transformerPool.transform(prc.getInputSource(), parametervalues);
        } catch (Throwable e) {
            throw new PipeRunException(this, getLogPrefix(session) + "got exception on transformation", e);
        }
    } else {
        forward = sInput;
    }
    log.debug(getLogPrefix(session) + "determined forward [" + forward + "]");
    if (StringUtils.isEmpty(forward) && getEmptyForwardName() != null) {
        throwEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
        pipeForward = findForward(getEmptyForwardName());
    } else {
        if (findForward(forward) != null) {
            throwEvent(XML_SWITCH_FORWARD_FOUND_MONITOR_EVENT);
            pipeForward = findForward(forward);
        } else {
            log.info(getLogPrefix(session) + "determined forward [" + forward + "], which is not defined. Will use [" + getNotFoundForwardName() + "] instead");
            throwEvent(XML_SWITCH_FORWARD_NOT_FOUND_MONITOR_EVENT);
            pipeForward = findForward(getNotFoundForwardName());
        }
    }
    if (pipeForward == null) {
        throw new PipeRunException(this, getLogPrefix(session) + "cannot find forward or pipe named [" + forward + "]");
    }
    return new PipeRunResult(pipeForward, input);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) PipeForward(nl.nn.adapterframework.core.PipeForward) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map)

Example 15 with PipeRunException

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

the class XmlValidator method getMessageToValidate.

@Deprecated
private String getMessageToValidate(Object input, IPipeLineSession session) throws PipeRunException {
    String inputStr = input.toString();
    if (XmlUtils.isWellFormed(inputStr, "Envelope")) {
        String inputRootNs;
        try {
            inputRootNs = transformerPoolGetRootNamespace.transform(inputStr, null);
        } catch (Exception e) {
            throw new PipeRunException(this, "cannot extract root namespace", e);
        }
        if (inputRootNs.equals(getSoapNamespace())) {
            log.debug(getLogPrefix(session) + "message to validate is a SOAP message");
            boolean extractSoapBody = true;
            if (StringUtils.isNotEmpty(getSchemaLocation())) {
                StringTokenizer st = new StringTokenizer(getSchemaLocation(), ", \t\r\n\f");
                while (st.hasMoreTokens() && extractSoapBody) {
                    if (st.nextToken().equals(getSoapNamespace())) {
                        extractSoapBody = false;
                    }
                }
            }
            if (extractSoapBody) {
                log.debug(getLogPrefix(session) + "extract SOAP body for validation");
                try {
                    inputStr = transformerPoolExtractSoapBody.transform(inputStr, null, true);
                } catch (Exception e) {
                    throw new PipeRunException(this, "cannot extract SOAP body", e);
                }
                try {
                    inputRootNs = transformerPoolGetRootNamespace.transform(inputStr, null);
                } catch (Exception e) {
                    throw new PipeRunException(this, "cannot extract root namespace", e);
                }
                if (StringUtils.isNotEmpty(inputRootNs) && StringUtils.isEmpty(getSchemaLocation())) {
                    log.debug(getLogPrefix(session) + "remove namespaces from extracted SOAP body");
                    try {
                        inputStr = transformerPoolRemoveNamespaces.transform(inputStr, null);
                    } catch (Exception e) {
                        throw new PipeRunException(this, "cannot remove namespaces", e);
                    }
                }
            }
        }
    }
    return inputStr;
}
Also used : StringTokenizer(java.util.StringTokenizer) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XmlValidatorException(nl.nn.adapterframework.validation.XmlValidatorException)

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