Search in sources :

Example 16 with ParameterResolutionContext

use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.

the class TimeoutGuardPipe method doPipe.

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 on extracting parameters", e);
        }
    }
    int timeout_work;
    String timeout_work_str = getParameterValue(pvl, "timeout");
    if (timeout_work_str == null) {
        timeout_work = getTimeout();
    } else {
        timeout_work = Integer.valueOf(timeout_work_str);
    }
    DoPipe doPipe = new DoPipe(input, session, Thread.currentThread().getName(), NDC.peek());
    ExecutorService service = Executors.newSingleThreadExecutor();
    Future future = service.submit(doPipe);
    String result = null;
    try {
        log.debug(getLogPrefix(session) + "setting timeout of [" + timeout_work + "] s");
        result = (String) future.get(timeout_work, TimeUnit.SECONDS);
    } catch (Exception e) {
        String msg;
        if (e instanceof TimeoutException) {
            String errorMsg = getLogPrefix(session) + "exceeds timeout of [" + timeout_work + "] s, interupting";
            future.cancel(true);
            msg = e.getClass().getName() + ": " + errorMsg;
        } else {
            msg = e.getClass().getName();
        }
        if (isThrowException()) {
            throw new PipeRunException(this, msg, e);
        } else {
            String msgString = msg + ": " + e.getMessage();
            log.error(msgString, e);
            String msgCdataString = "<![CDATA[" + msgString + "]]>";
            result = "<error>" + msgCdataString + "</error>";
        }
    } finally {
        service.shutdown();
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeRunException(nl.nn.adapterframework.core.PipeRunException) TimeoutException(java.util.concurrent.TimeoutException) ParameterException(nl.nn.adapterframework.core.ParameterException) TimeoutException(java.util.concurrent.TimeoutException)

Example 17 with ParameterResolutionContext

use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.

the class EtagHandlerPipe method doPipe.

@Override
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());
    }
    String uriPatternSessionKey = null;
    ParameterValueList pvl = null;
    ParameterList parameterList = getParameterList();
    if (parameterList != null) {
        ParameterResolutionContext prc = new ParameterResolutionContext((String) input, session);
        try {
            pvl = prc.getValues(getParameterList());
            if (pvl != null) {
                for (int i = 0; i < parameterList.size(); i++) {
                    Parameter parameter = parameterList.getParameter(i);
                    if ("uriPattern".equalsIgnoreCase(parameter.getName()))
                        uriPatternSessionKey = (String) parameter.getValue(pvl, prc);
                }
            }
        } catch (ParameterException e) {
            throw new PipeRunException(this, getLogPrefix(session) + "exception extracting parameters", e);
        }
    }
    // hash over data genereren, uit cache lezen en teruggeven, in cache updaten, verwijderen uit cache, cache naar disk wegschrijven, cache legen
    String cacheKey = null;
    if (uriPatternSessionKey != null && !uriPatternSessionKey.isEmpty())
        cacheKey = getRestPath() + "_" + uriPatternSessionKey.toLowerCase();
    else
        cacheKey = getRestPath() + "_" + getUriPattern();
    if (cache != null && cache.containsKey(cacheKey)) {
        Object returnCode = false;
        if (getAction().equalsIgnoreCase("generate")) {
            cache.put(cacheKey, RestListenerUtils.formatEtag(getRestPath(), getUriPattern(), input.hashCode()));
            returnCode = true;
        } else if (getAction().equalsIgnoreCase("get")) {
            returnCode = cache.get(cacheKey);
        } else if (getAction().equalsIgnoreCase("set")) {
            cache.put(cacheKey, input.toString());
            returnCode = true;
        } else if (getAction().equalsIgnoreCase("delete")) {
            returnCode = cache.remove(cacheKey);
        } else if (getAction().equalsIgnoreCase("flush")) {
            if (cache instanceof ApiEhcache) {
                ((ApiEhcache) cache).flush();
                returnCode = true;
            }
        } else if (getAction().equalsIgnoreCase("clear")) {
            cache.clear();
            returnCode = true;
        } else {
            throw new PipeRunException(this, getLogPrefix(session) + "action not found [" + getAction() + "]");
        }
        if (log.isDebugEnabled())
            log.debug("found eTag cacheKey [" + cacheKey + "] with action [" + getAction() + "]");
        return new PipeRunResult(getForward(), returnCode);
    } else {
        PipeForward pipeForward = findForward("exception");
        String msg;
        if (cache == null)
            msg = "failed to locate cache";
        else
            msg = "failed to locate eTag [" + cacheKey + "] in cache";
        if (pipeForward == null) {
            throw new PipeRunException(this, getLogPrefix(session) + msg);
        }
        return new PipeRunResult(pipeForward, "");
    }
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) ApiEhcache(nl.nn.adapterframework.http.rest.ApiEhcache) PipeForward(nl.nn.adapterframework.core.PipeForward)

Example 18 with ParameterResolutionContext

use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.

the class DirectWrapperPipe method doPipeWithTimeoutGuarded.

public String doPipeWithTimeoutGuarded(Object input, IPipeLineSession session) throws PipeRunException {
    String result;
    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 destination = getParameterValue(pvl, DESTINATION);
    String cmhVersion = getParameterValue(pvl, CMHVERSION);
    String addOutputNamespace = getParameterValue(pvl, ADDOUTPUTNAMESPACE);
    EsbSoapWrapperPipe eswPipe = new EsbSoapWrapperPipe();
    if (addOutputNamespace != null) {
        if ("on".equalsIgnoreCase(addOutputNamespace)) {
            eswPipe.setAddOutputNamespace(true);
        }
    }
    if (destination != null) {
        Parameter p = new Parameter();
        p.setName(DESTINATION);
        p.setValue(destination);
        eswPipe.addParameter(p);
    }
    if (cmhVersion != null) {
        if (StringUtils.isNumeric(cmhVersion)) {
            eswPipe.setCmhVersion(Integer.parseInt(cmhVersion));
        }
    }
    PipeForward pf = new PipeForward();
    pf.setName("success");
    eswPipe.registerForward(pf);
    try {
        eswPipe.configure();
        PipeRunResult prr = eswPipe.doPipe(input, session);
        result = (String) prr.getResult();
    } catch (Exception e) {
        throw new PipeRunException(this, getLogPrefix(session) + "Exception on wrapping input", e);
    }
    return result;
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ParameterValueList(nl.nn.adapterframework.parameters.ParameterValueList) PipeRunException(nl.nn.adapterframework.core.PipeRunException) Parameter(nl.nn.adapterframework.parameters.Parameter) ParameterException(nl.nn.adapterframework.core.ParameterException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 19 with ParameterResolutionContext

use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.

the class StreamTransformerPipe method doPipe.

/**
 * Open a reader for the file named according the input messsage and transform it.
 * Move the input file to a done directory when transformation is finished
 * and return the names of the generated files.
 *
 * @see nl.nn.adapterframework.core.IPipe#doPipe(java.lang.Object, nl.nn.adapterframework.core.IPipeLineSession)
 */
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String streamId = getStreamId(input, session);
    BufferedReader reader = getReader(streamId, input, session);
    if (reader == null) {
        throw new PipeRunException(this, "could not obtain reader for [" + streamId + "]");
    }
    Object transformationResult = null;
    ParameterResolutionContext prc = new ParameterResolutionContext("", session);
    try {
        transformationResult = transform(streamId, reader, session, prc);
    } finally {
        if (isCloseInputstreamOnExit()) {
            try {
                reader.close();
            } catch (IOException e) {
                log.warn(getLogPrefix(session) + "Exception closing reader", e);
            }
        }
    }
    return new PipeRunResult(getForward(), transformationResult);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) BufferedReader(java.io.BufferedReader) PipeRunException(nl.nn.adapterframework.core.PipeRunException) IOException(java.io.IOException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext)

Example 20 with ParameterResolutionContext

use of nl.nn.adapterframework.parameters.ParameterResolutionContext in project iaf by ibissource.

the class SoapWrapperPipe method doPipe.

@Override
public PipeRunResult doPipe(Object input, IPipeLineSession session) throws PipeRunException {
    String result;
    try {
        if ("wrap".equalsIgnoreCase(getDirection())) {
            String payload = input.toString();
            if (rootTp != null) {
                payload = rootTp.transform(payload, null, true);
            }
            if (outputNamespaceTp != null) {
                payload = outputNamespaceTp.transform(payload, null, true);
            }
            ParameterResolutionContext prc = null;
            Map parameterValues = null;
            if (getParameterList() != null && (soapHeaderTp != null || soapBodyTp != null)) {
                prc = new ParameterResolutionContext(payload, session);
                parameterValues = prc.getValueMap(getParameterList());
            }
            String soapHeader = null;
            if (soapHeaderTp != null) {
                soapHeader = soapHeaderTp.transform(prc.getInputSource(), parameterValues);
            } else {
                if (StringUtils.isNotEmpty(getSoapHeaderSessionKey())) {
                    soapHeader = (String) session.get(getSoapHeaderSessionKey());
                }
            }
            if (soapBodyTp != null) {
                payload = soapBodyTp.transform(prc.getInputSource(), parameterValues);
            }
            result = wrapMessage(payload, soapHeader);
        } else {
            result = unwrapMessage(input.toString());
            if (StringUtils.isEmpty(result)) {
                throw new PipeRunException(this, getLogPrefix(session) + "SOAP Body is empty or message is not a SOAP Message");
            }
            if (!isIgnoreSoapFault() && soapWrapper.getFaultCount(input.toString()) > 0) {
                throw new PipeRunException(this, getLogPrefix(session) + "SOAP Body contains SOAP Fault");
            }
            if (StringUtils.isNotEmpty(getSoapHeaderSessionKey())) {
                String soapHeader = soapWrapper.getHeader(input.toString());
                session.put(getSoapHeaderSessionKey(), soapHeader);
            }
            if (removeOutputNamespacesTp != null) {
                result = removeOutputNamespacesTp.transform(result, null, true);
            }
            if (removeUnusedOutputNamespacesTp != null) {
                result = removeUnusedOutputNamespacesTp.transform(result, null, true);
            }
            if (rootTp != null) {
                result = rootTp.transform(result, null, true);
            }
        }
    } catch (Exception t) {
        throw new PipeRunException(this, getLogPrefix(session) + " Unexpected exception during (un)wrapping ", t);
    }
    return new PipeRunResult(getForward(), result);
}
Also used : PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Map(java.util.Map) PipeRunException(nl.nn.adapterframework.core.PipeRunException) PipeStartException(nl.nn.adapterframework.core.PipeStartException) TransformerException(javax.xml.transform.TransformerException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) SOAPException(javax.xml.soap.SOAPException) DomBuilderException(nl.nn.adapterframework.util.DomBuilderException) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException)

Aggregations

ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)47 PipeRunException (nl.nn.adapterframework.core.PipeRunException)32 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)21 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)20 ParameterException (nl.nn.adapterframework.core.ParameterException)18 IOException (java.io.IOException)17 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)16 Parameter (nl.nn.adapterframework.parameters.Parameter)15 Map (java.util.Map)10 SenderException (nl.nn.adapterframework.core.SenderException)10 ParameterList (nl.nn.adapterframework.parameters.ParameterList)10 FixedQuerySender (nl.nn.adapterframework.jdbc.FixedQuerySender)8 PipeForward (nl.nn.adapterframework.core.PipeForward)7 HashMap (java.util.HashMap)6 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)5 PipeLineSessionBase (nl.nn.adapterframework.core.PipeLineSessionBase)4 DomBuilderException (nl.nn.adapterframework.util.DomBuilderException)4 URL (java.net.URL)3 ISender (nl.nn.adapterframework.core.ISender)3 PipeStartException (nl.nn.adapterframework.core.PipeStartException)3