Search in sources :

Example 86 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class XslErrorMessageFormatter method format.

@Override
public Message format(String errorMessage, Throwable t, INamedObject location, Message originalMessage, String messageId, long receivedTime) {
    Message result = super.format(errorMessage, t, location, originalMessage, messageId, receivedTime);
    if (StringUtils.isNotEmpty(getStyleSheet()) || StringUtils.isNotEmpty(getXpathExpression())) {
        try {
            Transformer errorTransformer;
            if (StringUtils.isNotEmpty(getStyleSheet())) {
                URL url = ClassUtils.getResourceURL(this, styleSheet);
                errorTransformer = XmlUtils.createTransformer(url);
            } else {
                String xpath = getXpathExpression();
                // if (StringUtils.isEmpty(xpath)) {
                // xpath="/errorMessage/@message";
                // }
                errorTransformer = XmlUtils.createTransformer(XmlUtils.createXPathEvaluatorSource(xpath));
            }
            ParameterList params = getParameterList();
            if (params != null) {
                try {
                    params.configure();
                } catch (ConfigurationException e) {
                    log.error("exception while configuring parameters", e);
                }
                Map<String, Object> parametervalues = null;
                try {
                    parametervalues = params.getValues(new Message(errorMessage), new PipeLineSession()).getValueMap();
                } catch (ParameterException e) {
                    log.error("got exception extracting parameters", e);
                }
                XmlUtils.setTransformerParameters(errorTransformer, parametervalues);
            }
            result = new Message(XmlUtils.transformXml(errorTransformer, result.asSource()));
        } catch (IOException e) {
            log.error(" cannot retrieve [" + styleSheet + "]", e);
        } catch (javax.xml.transform.TransformerConfigurationException te) {
            log.error("got error creating transformer from file [" + styleSheet + "]", te);
        } catch (Exception tfe) {
            log.error("could not transform [" + result + "] using stylesheet [" + styleSheet + "]", tfe);
        }
    } else {
        log.warn("no stylesheet defined for XslErrorMessageFormatter");
    }
    return result;
}
Also used : Transformer(javax.xml.transform.Transformer) Message(nl.nn.adapterframework.stream.Message) PipeLineSession(nl.nn.adapterframework.core.PipeLineSession) IOException(java.io.IOException) URL(java.net.URL) IOException(java.io.IOException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterException(nl.nn.adapterframework.core.ParameterException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ParameterList(nl.nn.adapterframework.parameters.ParameterList) INamedObject(nl.nn.adapterframework.core.INamedObject) ParameterException(nl.nn.adapterframework.core.ParameterException)

Example 87 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class MessageSendingPipe method configure.

/**
 * Checks whether a sender is defined for this pipe.
 */
@Override
public void configure() throws ConfigurationException {
    super.configure();
    msgLog = LogUtil.getMsgLogger(getAdapter(), this);
    if (StringUtils.isNotEmpty(getStubFilename())) {
        URL stubUrl;
        try {
            stubUrl = ClassUtils.getResourceURL(this, getStubFilename());
        } catch (Throwable e) {
            throw new ConfigurationException("got exception finding resource for stubfile [" + getStubFilename() + "]", e);
        }
        if (stubUrl == null) {
            throw new ConfigurationException("could not find resource for stubfile [" + getStubFilename() + "]");
        }
        try {
            returnString = Misc.resourceToString(stubUrl, Misc.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new ConfigurationException("got exception loading stubfile [" + getStubFilename() + "] from resource [" + stubUrl.toExternalForm() + "]", e);
        }
    } else {
        propagateName();
        if (getSender() == null) {
            throw new ConfigurationException("no sender defined ");
        }
        // because sender might not have been set when addPipe() is called.
        if (getParameterList() != null && getSender() instanceof ISenderWithParameters) {
            for (Parameter p : getParameterList()) {
                if (!p.getName().equals(STUBFILENAME)) {
                    ((ISenderWithParameters) getSender()).addParameter(p);
                }
            }
        }
        try {
            // In order to be able to suppress 'xxxSender may cause potential SQL injections!' config warnings
            if (sender instanceof DirectQuerySender) {
                ((DirectQuerySender) getSender()).configure(getAdapter());
            } else {
                getSender().configure();
            }
        } catch (ConfigurationException e) {
            throw new ConfigurationException("while configuring sender", e);
        }
        if (getSender() instanceof HasPhysicalDestination) {
            log.info(getLogPrefix(null) + "has sender on " + ((HasPhysicalDestination) getSender()).getPhysicalDestinationName());
        }
        if (getListener() != null) {
            if (getSender().isSynchronous()) {
                throw new ConfigurationException("cannot have listener with synchronous sender");
            }
            try {
                getListener().configure();
            } catch (ConfigurationException e) {
                throw new ConfigurationException("while configuring listener", e);
            }
            if (getListener() instanceof HasPhysicalDestination) {
                log.info(getLogPrefix(null) + "has listener on " + ((HasPhysicalDestination) getListener()).getPhysicalDestinationName());
            }
        }
        if (!(getHideMethod().equalsIgnoreCase("all")) && (!(getHideMethod().equalsIgnoreCase("firstHalf")))) {
            throw new ConfigurationException("invalid value for hideMethod [" + getHideMethod() + "], must be 'all' or 'firstHalf'");
        }
        if (isCheckXmlWellFormed() || StringUtils.isNotEmpty(getCheckRootTag())) {
            if (findForward(ILLEGAL_RESULT_FORWARD) == null)
                throw new ConfigurationException("has no forward with name [illegalResult]");
        }
        if (!ConfigurationUtils.isConfigurationStubbed(getConfigurationClassLoader())) {
            if (StringUtils.isNotEmpty(getTimeOutOnResult())) {
                throw new ConfigurationException("timeOutOnResult only allowed in stub mode");
            }
            if (StringUtils.isNotEmpty(getExceptionOnResult())) {
                throw new ConfigurationException("exceptionOnResult only allowed in stub mode");
            }
        }
        if (getMaxRetries() > 0) {
            if (getRetryMinInterval() < MIN_RETRY_INTERVAL) {
                ConfigurationWarnings.add(this, log, "retryMinInterval [" + getRetryMinInterval() + "] should be greater than or equal to [" + MIN_RETRY_INTERVAL + "], assuming the lower limit");
                setRetryMinInterval(MIN_RETRY_INTERVAL);
            }
            if (getRetryMaxInterval() > MAX_RETRY_INTERVAL) {
                ConfigurationWarnings.add(this, log, "retryMaxInterval [" + getRetryMaxInterval() + "] should be less than or equal to [" + MAX_RETRY_INTERVAL + "], assuming the upper limit");
                setRetryMaxInterval(MAX_RETRY_INTERVAL);
            }
            if (getRetryMaxInterval() < getRetryMinInterval()) {
                ConfigurationWarnings.add(this, log, "retryMaxInterval [" + getRetryMaxInterval() + "] should be greater than or equal to [" + getRetryMinInterval() + "], assuming the lower limit");
                setRetryMaxInterval(getRetryMinInterval());
            }
        }
    }
    ITransactionalStorage messageLog = getMessageLog();
    if (messageLog == null) {
        if (StringUtils.isEmpty(getStubFilename()) && !getSender().isSynchronous() && getListener() == null && !(getSender() instanceof nl.nn.adapterframework.senders.IbisLocalSender)) {
            // sender is asynchronous and not a local sender, but has no messageLog
            boolean suppressIntegrityCheckWarning = ConfigurationWarnings.isSuppressed(SuppressKeys.INTEGRITY_CHECK_SUPPRESS_KEY, getAdapter());
            if (!suppressIntegrityCheckWarning) {
                boolean legacyCheckMessageLog = AppConstants.getInstance(getConfigurationClassLoader()).getBoolean("messageLog.check", true);
                if (!legacyCheckMessageLog) {
                    ConfigurationWarnings.add(this, log, "Suppressing integrityCheck warnings by setting property 'messageLog.check=false' has been replaced by by setting property 'warnings.suppress.integrityCheck=true'");
                    suppressIntegrityCheckWarning = true;
                }
            }
            if (!suppressIntegrityCheckWarning) {
                ConfigurationWarnings.add(this, log, "asynchronous sender [" + getSender().getName() + "] without sibling listener has no messageLog. " + "Service Managers will not be able to perform an integrity check (matching messages received by the adapter to messages sent by this pipe). " + "This warning can be suppressed globally by setting property 'warnings.suppress.integrityCheck=true', " + "or for this adapter only by setting property 'warnings.suppress.integrityCheck." + getAdapter().getName() + "=true'");
            }
        }
    } else {
        if (StringUtils.isNotEmpty(getHideRegex()) && StringUtils.isEmpty(messageLog.getHideRegex())) {
            messageLog.setHideRegex(getHideRegex());
            messageLog.setHideMethod(getHideMethod());
        }
        messageLog.configure();
        if (messageLog instanceof HasPhysicalDestination) {
            String msg = getLogPrefix(null) + "has messageLog in " + ((HasPhysicalDestination) messageLog).getPhysicalDestinationName();
            log.info(msg);
            if (getAdapter() != null)
                getAdapter().getMessageKeeper().add(msg);
        }
        if (StringUtils.isNotEmpty(getAuditTrailXPath())) {
            auditTrailTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getAuditTrailNamespaceDefs(), getAuditTrailXPath(), null, OutputType.TEXT, false, null);
        }
        if (StringUtils.isNotEmpty(getCorrelationIDXPath()) || StringUtils.isNotEmpty(getCorrelationIDStyleSheet())) {
            correlationIDTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getCorrelationIDNamespaceDefs(), getCorrelationIDXPath(), getCorrelationIDStyleSheet(), OutputType.TEXT, false, null);
        }
        if (StringUtils.isNotEmpty(getLabelXPath()) || StringUtils.isNotEmpty(getLabelStyleSheet())) {
            labelTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getLabelNamespaceDefs(), getLabelXPath(), getLabelStyleSheet(), OutputType.TEXT, false, null);
        }
    }
    if (StringUtils.isNotEmpty(getRetryXPath())) {
        retryTp = TransformerPool.configureTransformer(getLogPrefix(null), this, getRetryNamespaceDefs(), getRetryXPath(), null, OutputType.TEXT, false, null);
    }
    IValidator inputValidator = getInputValidator();
    IValidator outputValidator = getOutputValidator();
    if (inputValidator != null && outputValidator == null && inputValidator instanceof IDualModeValidator) {
        outputValidator = ((IDualModeValidator) inputValidator).getResponseValidator();
        setOutputValidator(outputValidator);
    }
    if (inputValidator != null) {
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        inputValidator.registerForward(pf);
        configure(inputValidator);
    }
    if (outputValidator != null) {
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        outputValidator.registerForward(pf);
        configure(outputValidator);
    }
    if (getInputWrapper() != null) {
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        getInputWrapper().registerForward(pf);
        if (getInputWrapper() instanceof EsbSoapWrapperPipe) {
            EsbSoapWrapperPipe eswPipe = (EsbSoapWrapperPipe) getInputWrapper();
            ISender sender = getSender();
            eswPipe.retrievePhysicalDestinationFromSender(sender);
        }
        configure(getInputWrapper());
    }
    if (getOutputWrapper() != null) {
        PipeForward pf = new PipeForward();
        pf.setName(PipeForward.SUCCESS_FORWARD_NAME);
        getOutputWrapper().registerForward(pf);
        configure(getOutputWrapper());
    }
    registerEvent(PIPE_TIMEOUT_MONITOR_EVENT);
    registerEvent(PIPE_CLEAR_TIMEOUT_MONITOR_EVENT);
    registerEvent(PIPE_EXCEPTION_MONITOR_EVENT);
}
Also used : EsbSoapWrapperPipe(nl.nn.adapterframework.extensions.esb.EsbSoapWrapperPipe) ISenderWithParameters(nl.nn.adapterframework.core.ISenderWithParameters) IDualModeValidator(nl.nn.adapterframework.core.IDualModeValidator) DirectQuerySender(nl.nn.adapterframework.jdbc.DirectQuerySender) PipeForward(nl.nn.adapterframework.core.PipeForward) URL(java.net.URL) ITransactionalStorage(nl.nn.adapterframework.core.ITransactionalStorage) IValidator(nl.nn.adapterframework.core.IValidator) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) ISender(nl.nn.adapterframework.core.ISender) Parameter(nl.nn.adapterframework.parameters.Parameter) HasPhysicalDestination(nl.nn.adapterframework.core.HasPhysicalDestination)

Example 88 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class PGPPipe method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    if (action == null)
        throw new ConfigurationException("Action can not be null!");
    if (Security.getProvider(BouncyCastleProvider.PROVIDER_NAME) != null)
        Security.removeProvider(BouncyCastleProvider.PROVIDER_NAME);
    Security.addProvider(new BouncyCastleProvider());
    switch(action.toLowerCase()) {
        case "encrypt":
            pgpAction = new Encrypt(publicKeys, recipients);
            break;
        case "decrypt":
            pgpAction = new Decrypt(secretKey, secretPassword);
            break;
        case "sign":
            if (verificationAddresses == null || verificationAddresses.length == 0)
                throw new ConfigurationException("During signing action, senders has to be set.");
            pgpAction = new Sign(publicKeys, secretKey, secretPassword, recipients, verificationAddresses[0]);
            break;
        case "verify":
            pgpAction = new Verify(publicKeys, secretKey, secretPassword, verificationAddresses);
            break;
        default:
            throw new ConfigurationException("Unknown action. Action has to be set to one of [Encrypt, Decrypt, Sign, Verify]");
    }
    pgpAction.configure();
}
Also used : Decrypt(nl.nn.adapterframework.pgp.Decrypt) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) Sign(nl.nn.adapterframework.pgp.Sign) Verify(nl.nn.adapterframework.pgp.Verify) Encrypt(nl.nn.adapterframework.pgp.Encrypt) BouncyCastleProvider(org.bouncycastle.jce.provider.BouncyCastleProvider)

Example 89 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class FixedResultPipe method configure.

/**
 * checks for correct configuration, and translates the filename to
 * a file, to check existence.
 * If a filename or filenameSessionKey was specified, the contents of the file is put in the
 * <code>returnString</code>, so that the <code>returnString</code>
 * may always be returned.
 * @throws ConfigurationException
 */
@Override
public void configure() throws ConfigurationException {
    super.configure();
    appConstants = AppConstants.getInstance(getConfigurationClassLoader());
    if (StringUtils.isNotEmpty(getFilename()) && !isLookupAtRuntime()) {
        URL resource = null;
        try {
            resource = ClassUtils.getResourceURL(this, getFilename());
        } catch (Throwable e) {
            throw new ConfigurationException("got exception searching for [" + getFilename() + "]", e);
        }
        if (resource == null) {
            throw new ConfigurationException("cannot find resource [" + getFilename() + "]");
        }
        try {
            returnString = Misc.resourceToString(resource, Misc.LINE_SEPARATOR);
        } catch (Throwable e) {
            throw new ConfigurationException("got exception loading [" + getFilename() + "]", e);
        }
    }
    if ((StringUtils.isEmpty(getFilename())) && (StringUtils.isEmpty(getFilenameSessionKey())) && returnString == null) {
        // allow an empty returnString to be specified
        throw new ConfigurationException("has neither filename nor filenameSessionKey nor returnString specified");
    }
    if (StringUtils.isNotEmpty(replaceFrom)) {
        returnString = replace(returnString, replaceFrom, replaceTo);
    }
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) URL(java.net.URL)

Example 90 with ConfigurationException

use of nl.nn.adapterframework.configuration.ConfigurationException in project iaf by ibissource.

the class IteratingPipe method configure.

@Override
public void configure() throws ConfigurationException {
    super.configure();
    msgTransformerPool = TransformerPool.configureTransformer(getLogPrefix(null), this, getNamespaceDefs(), getXpathExpression(), getStyleSheetName(), getOutputType(), !isOmitXmlDeclaration(), getParameterList(), false);
    if (msgTransformerPool != null) {
        preprocessingStatisticsKeeper = new StatisticsKeeper("-> message preprocessing");
    }
    try {
        if (StringUtils.isNotEmpty(getStopConditionXPathExpression())) {
            stopConditionTp = TransformerPool.getInstance(XmlUtils.createXPathEvaluatorSource(null, getStopConditionXPathExpression(), OutputType.XML, false));
            stopConditionStatisticsKeeper = new StatisticsKeeper("-> stop condition determination");
        }
    } catch (TransformerConfigurationException e) {
        throw new ConfigurationException("Cannot compile stylesheet from stopConditionXPathExpression [" + getStopConditionXPathExpression() + "]", e);
    }
    if (getMaxChildThreads() > 0) {
        childThreadSemaphore = new Semaphore(getMaxChildThreads());
    }
    stopForwardConfigured = getForwards() != null && (getForwards().get(StopReason.MAX_ITEMS_REACHED.getForwardName()) != null || getForwards().get(StopReason.STOP_CONDITION_MET.getForwardName()) != null);
}
Also used : TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) ConfigurationException(nl.nn.adapterframework.configuration.ConfigurationException) StatisticsKeeper(nl.nn.adapterframework.statistics.StatisticsKeeper) Semaphore(nl.nn.adapterframework.util.Semaphore)

Aggregations

ConfigurationException (nl.nn.adapterframework.configuration.ConfigurationException)187 IOException (java.io.IOException)52 PipeRunException (nl.nn.adapterframework.core.PipeRunException)25 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)24 Parameter (nl.nn.adapterframework.parameters.Parameter)20 ArrayList (java.util.ArrayList)19 URL (java.net.URL)17 ParameterList (nl.nn.adapterframework.parameters.ParameterList)16 SAXException (org.xml.sax.SAXException)14 TransformerException (javax.xml.transform.TransformerException)12 Test (org.junit.Test)12 CredentialFactory (nl.nn.adapterframework.util.CredentialFactory)11 HashMap (java.util.HashMap)10 File (java.io.File)9 StringTokenizer (java.util.StringTokenizer)8 Connection (java.sql.Connection)7 Map (java.util.Map)7 ListenerException (nl.nn.adapterframework.core.ListenerException)7 ParameterException (nl.nn.adapterframework.core.ParameterException)7 JdbcException (nl.nn.adapterframework.jdbc.JdbcException)7