Search in sources :

Example 6 with ParameterList

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

the class CompareStringPipe method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    if (null == findForward(LESSTHANFORWARD))
        throw new ConfigurationException(getLogPrefix(null) + "forward [" + LESSTHANFORWARD + "] is not defined");
    if (null == findForward(GREATERTHANFORWARD))
        throw new ConfigurationException(getLogPrefix(null) + "forward [" + GREATERTHANFORWARD + "] is not defined");
    if (null == findForward(EQUALSFORWARD))
        throw new ConfigurationException(getLogPrefix(null) + "forward [" + EQUALSFORWARD + "] is not defined");
    if (StringUtils.isEmpty(sessionKey1) && StringUtils.isEmpty(sessionKey2)) {
        boolean operand1Exists = false;
        boolean operand2Exists = false;
        ParameterList parameterList = getParameterList();
        for (int i = 0; i < parameterList.size(); i++) {
            Parameter parameter = parameterList.getParameter(i);
            if (parameter.getName().equalsIgnoreCase(OPERAND1)) {
                operand1Exists = true;
            } else {
                if (parameter.getName().equalsIgnoreCase(OPERAND2)) {
                    operand2Exists = true;
                }
            }
        }
        if (!operand1Exists && !operand2Exists) {
            throw new ConfigurationException(getLogPrefix(null) + "has neither parameter [" + OPERAND1 + "] nor parameter [" + OPERAND2 + "] specified");
        }
    }
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter)

Example 7 with ParameterList

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

the class AbstractPipe method configure.

/**
 * <code>configure()</code> is called after the {@link nl.nn.adapterframework.core.PipeLine Pipeline} is registered
 * at the {@link nl.nn.adapterframework.core.Adapter Adapter}. Purpose of this method is to reduce
 * creating connections to databases etc. in the {@link #doPipe(Object) doPipe()} method.
 * As much as possible class-instantiating should take place in the
 * <code>configure()</code> method, to improve performance.
 */
@Override
public void configure() throws ConfigurationException {
    ParameterList params = getParameterList();
    if (params != null) {
        try {
            params.configure();
        } catch (ConfigurationException e) {
            throw new ConfigurationException(getLogPrefix(null) + "while configuring parameters", e);
        }
    }
    if (!StringUtils.isEmpty(getElementToMove()) && !StringUtils.isEmpty(getElementToMoveChain())) {
        throw new ConfigurationException(getLogPrefix(null) + "cannot have both an elementToMove and an elementToMoveChain specified");
    }
    if (pipeForwards.isEmpty()) {
        ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
        String msg = getLogPrefix(null) + "has no forwards defined.";
        configWarnings.add(log, msg);
    } else {
        for (Iterator<String> it = pipeForwards.keySet().iterator(); it.hasNext(); ) {
            String forwardName = it.next();
            PipeForward forward = pipeForwards.get(forwardName);
            if (forward != null) {
                String path = forward.getPath();
                if (path != null) {
                    PipeLineExit plExit = pipeline.getPipeLineExits().get(path);
                    if (plExit == null) {
                        if (pipeline.getPipe(path) == null) {
                            ConfigurationWarnings configWarnings = ConfigurationWarnings.getInstance();
                            String msg = getLogPrefix(null) + "has a forward of which the pipe to execute [" + path + "] is not defined.";
                            configWarnings.add(log, msg);
                        }
                    }
                }
            }
        }
    }
    if (getLocker() != null) {
        getLocker().configure();
    }
    eventHandler = MonitorManager.getEventHandler();
}
Also used : ConfigurationWarnings(nl.nn.adapterframework.configuration.ConfigurationWarnings) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) PipeForward(nl.nn.adapterframework.core.PipeForward) PipeLineExit(nl.nn.adapterframework.core.PipeLineExit)

Example 8 with ParameterList

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

the class Json2XmlValidator method alignJson.

protected PipeRunResult alignJson(String messageToValidate, IPipeLineSession session, boolean responseMode) throws PipeRunException, XmlValidatorException {
    ValidationContext context;
    ValidatorHandler validatorHandler;
    try {
        context = validator.createValidationContext(session, getRootValidations(responseMode), getInvalidRootNamespaces());
        validatorHandler = validator.getValidatorHandler(session, context);
    } catch (ConfigurationException e) {
        throw new PipeRunException(this, "Cannot create ValidationContext", e);
    }
    String resultEvent;
    String out = null;
    try {
        Json2Xml aligner = new Json2Xml(validatorHandler, context.getXsModels(), isCompactJsonArrays(), getMessageRoot(responseMode), isStrictJsonArraySyntax());
        if (StringUtils.isNotEmpty(getTargetNamespace())) {
            aligner.setTargetNamespace(getTargetNamespace());
        }
        aligner.setDeepSearch(isDeepSearch());
        aligner.setErrorHandler(context.getErrorHandler());
        aligner.setFailOnWildcards(isFailOnWildcards());
        ParameterList parameterList = getParameterList();
        if (parameterList != null) {
            ParameterResolutionContext prc = new ParameterResolutionContext(messageToValidate, session, isNamespaceAware(), false);
            Map<String, Object> parametervalues = null;
            parametervalues = prc.getValueMap(parameterList);
            aligner.setOverrideValues(parametervalues);
        }
        JsonStructure jsonStructure = Json.createReader(new StringReader(messageToValidate)).read();
        if (getOutputFormat(session, responseMode).equalsIgnoreCase(FORMAT_JSON)) {
            Xml2Json xml2json = new Xml2Json(aligner, isCompactJsonArrays(), !isJsonWithRootElements());
            aligner.setContentHandler(xml2json);
            aligner.startParse(jsonStructure);
            out = xml2json.toString();
        } else {
            Source source = aligner.asSource(jsonStructure);
            out = XmlUtils.source2String(source, isProduceNamespaceLessXml());
        }
    } catch (Exception e) {
        resultEvent = validator.finalizeValidation(context, session, e);
    }
    resultEvent = validator.finalizeValidation(context, session, null);
    PipeForward forward = determineForward(resultEvent, session, responseMode);
    PipeRunResult result = new PipeRunResult(forward, out);
    return result;
}
Also used : ValidatorHandler(javax.xml.validation.ValidatorHandler) PipeForward(nl.nn.adapterframework.core.PipeForward) Source(javax.xml.transform.Source) PipeRunException(nl.nn.adapterframework.core.PipeRunException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) XmlValidatorException(nl.nn.adapterframework.validation.XmlValidatorException) ValidationContext(nl.nn.adapterframework.validation.ValidationContext) PipeRunResult(nl.nn.adapterframework.core.PipeRunResult) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) PipeRunException(nl.nn.adapterframework.core.PipeRunException) StringReader(java.io.StringReader) ParameterList(nl.nn.adapterframework.parameters.ParameterList) ParameterResolutionContext(nl.nn.adapterframework.parameters.ParameterResolutionContext) Xml2Json(nl.nn.adapterframework.align.Xml2Json) Json2Xml(nl.nn.adapterframework.align.Json2Xml) JsonStructure(javax.json.JsonStructure)

Example 9 with ParameterList

use of nl.nn.adapterframework.parameters.ParameterList 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 10 with ParameterList

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

the class EtagHandlerPipe method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    String action = getAction();
    if (action == null) {
        throw new ConfigurationException(getLogPrefix(null) + "action must be set");
    }
    if (!actions.contains(action)) {
        throw new ConfigurationException(getLogPrefix(null) + "illegal value for action [" + action + "], must be one of " + actions.toString());
    }
    boolean hasUriPatternParameter = false;
    ParameterList parameterList = getParameterList();
    for (int i = 0; i < parameterList.size(); i++) {
        Parameter parameter = parameterList.getParameter(i);
        if ("uriPattern".equalsIgnoreCase(parameter.getName()))
            hasUriPatternParameter = true;
    }
    if (getUriPattern() == null && !hasUriPatternParameter) {
        throw new ConfigurationException(getLogPrefix(null) + "no uriPattern found!");
    }
    cache = ApiCacheManager.getInstance();
}
Also used : ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) Parameter(nl.nn.adapterframework.parameters.Parameter)

Aggregations

ParameterList (nl.nn.adapterframework.parameters.ParameterList)24 ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)14 Parameter (nl.nn.adapterframework.parameters.Parameter)13 ParameterResolutionContext (nl.nn.adapterframework.parameters.ParameterResolutionContext)10 PipeRunException (nl.nn.adapterframework.core.PipeRunException)8 PipeRunResult (nl.nn.adapterframework.core.PipeRunResult)8 ParameterException (nl.nn.adapterframework.core.ParameterException)7 IOException (java.io.IOException)6 PipeForward (nl.nn.adapterframework.core.PipeForward)6 Map (java.util.Map)4 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)3 ParameterValueList (nl.nn.adapterframework.parameters.ParameterValueList)3 InputStream (java.io.InputStream)2 ArrayList (java.util.ArrayList)2 List (java.util.List)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 SenderException (nl.nn.adapterframework.core.SenderException)2 TimeOutException (nl.nn.adapterframework.core.TimeOutException)2 File (java.io.File)1 OutputStream (java.io.OutputStream)1